Articles for category: Data Structures and Algorithms

Boundary Traversal of Binary Tree

Problem Statement A binary tree will be given in the problem and we need to find the boundary traversal of that binary tree.Boundary traversal of a binary tree means traversing the binary tree along the boundary. The boundary includes the left boundary, right boundary and leaf nodes. Therefore in the boundary traversal of binary trees ...

Next Greater Element

Problem Statement We are given an array of integers, and we need to find the next greater element of every array elements. So, we need to find and print the next greater element of every array element. Note: Refer to the Example and Example Explanation sections for more details and the Approach section to understand how to find the next greater ...

Find the Middle Element in Linked List

Problem Statement You are given the head of a linked list, write a program to Find middle element in linked list. When there are even number of nodes in linked list, then there would be two middle nodes, return the second middle node. Example Input-1 Output-1 Explanation Here, 3 is the middle node of the ...

Application of Queue in Data Structure

A Queue is an abstract linear data structure serving as a collection of elements that are inserted (enqueue operation) and removed (dequeue operation) according to the First in First Out (FIFO) approach. Takeaways Introduction to Queue A queue is a linear sequence of items arranged in an ordered fashion. It is based on the FIFO (First In First Out) i.e.i.e. item can only be inserted at ...

Divide and Conquer Algorithm

Divide and Conquer is a fundamental algorithmic technique in computer science, where a problem is divided into smaller, more manageable sub-problems, solved individually, and then combined to form the final solution. Divide and conquer algorithm approach not only simplifies complex problems but also enhances computational efficiency. How Does the Divide and Conquer Algorithm Work? The divide ...

Geometric Progression

Geometric Progression (GP) is a sequence where each term results from multiplying the previous one by a constant, known as the Common Ratio. Consider folding a paper multiple times: while it’s folded 4-5 times, determining its final stack height illustrates GP principles. This progression concept offers insights into patterns formed by consistent multiplicative growth. Notation ...

Introduction to Logarithms

Overview In this article, we are going to learn about Logarithms in programming. Before getting started with the topic, let us get a short overview of what is Logarithms. Logarithms: In mathematics, the inverse of an exponential function is called the logarithmic function. In simple terms, the logarithm is the exponent or power of any ...

Merge Sort for Linked Lists

Problem Statement Given a singly linked list, use the merge sort algorithm to sort the list in the ascending order of their node’s values. Example Input Output Example Explanation The nodes in the input are not arranged in any particular order, while they are arranged in ascending order of their value in the output. Constraints ...