Tag: datastructures


Introduction to Arrays

An array is a collection of items stored at contiguous memory locations. The array is used to store multiple data …

Reverse elements of an array

Write a program to input elements in an array and find reverse of an array. So in this post, we …

Program to find middle element of a Linked List

Given a linked list, write a program to find middle element of a linked list. e.g.- for linked list 1 …

Program to reverse a linked list

Given a linked list, write a program to reverse elements of a linked list. e.g.- for linked list 1 - …

Balanced brackets problem

Balanced brackets problem is one of the famous problems based on the stack and it has been asked in many …

Height of a binary tree

Height of a tree is the total number of nodes on the path from the root node to the deepest …

Nearest greater to right

Write a program to find the nearest greater element or next greater to the right of each element in an …

Stack using array

In this tutorial, we will implement a stack using array by using the fixed array and dynamic array method with …

Stack using linked list

In this tutorial, we will implement a stack using linked list with their time and space complexity.

Nearest greater to left

Write a program to find the nearest greater element or next greater to the left of each element in an …

Stock span problem

Stock span problem is a financial problem mostly asked in interviews and its optimized solution can be obtained using stack. …

Nearest smaller to right

Write a program to find the nearest smaller element or next smaller element to the right of each element in …

Nearest smaller to left

Write a program to find the nearest smaller element to the left of each element in an array.

Maximum area histogram

Write a program to find the maximum area under histogram or largest rectangle in a histogram. It's optimized solution can …

Introduction to Linked list

In this introduction part of the linked list, we will learn about the basics of a Linked List, like its …

Linked List

A Linked List or Singly Linked List is a linear data structure which collectively represents a sequence of data. In …

Doubly Linked List

A Doubly Linked List is a linear data structure which collectively represents a sequence of data in which each node …

Pair with given sum in an array

In this problem, we have to find a pair of number in an unsorted array which adds up to the …

Introduction to Trees

A tree is a non-linear data structures in which each node can point to a number of nodes. A tree …

Introduction to Binary Tree

A binary tree is a non-linear and hierarchical data structure which has zero children, one child or two children. An …

Binary tree traversals

Binary tree traversals can be done by Depth-first traversal and Breadth-first traversals or Level order traversal. Preorder traversal, Inorder traversal …

Reverse level order traversal

Program to print reverse level order traversal of a binary tree i.e., print data in a binary tree from bottom …

Second largest element in an array

Given an array write a program to find the second largest element in an array by using the efficient possible …

Maximum in Binary tree

Find the maximum element in a Binary tree using recursion or iterative solution. For example, a binary tree contains the …

Left rotation of an array

Given an array write a program to rotate the array of size "n" to left/anticlockwise direction by "k" elements and …

Search a node in Binary tree

Search a node in a Binary tree using recursion or iterative solution. For example, a binary tree contains the following …

Size of a binary tree

Find the size of a Binary tree using recursion or iterative solution. For example, a binary tree contains the following …

Deepest node in a binary tree

The rightmost node among the leaf nodes is known as the deepest node in a binary tree. Find the deepest …

Number of leaf nodes in a binary tree

Those nodes in the tree which don't have any child are known as leaf nodes i.e., A node is a …

Number of full nodes in a binary tree

Those nodes in the tree which have both the children are known as full nodes i.e., A node is a …

Number of half nodes in a binary tree

Those nodes in the tree which have only one child are known as half nodes i.e., A node is a …

Compare structure of two binary trees

Write a program to compare the structure of two binary trees without data and if they are identical then return …

Compare structure and data of two binary trees

Write a program to compare the structure data of two binary trees and if they are identical then return true …

Maximum level sum in a binary tree

Write a program to find the maximum level sum in a binary tree even if nodes may have negative values …

Diameter of a Binary tree

The diameter of a tree is the number of nodes on the longest path between two leaves in the tree. …

All root-to-leaf paths of a Binary tree

Write a program to find all root to leaf paths of a Binary tree. A tree has different paths from …

Introduction to Binary Search Tree

A Binary Search Tree is a non-linear data structure in which all the left subtree keys should be less than …

Search a node in Binary search tree

In this tutorial, we are going to learn that how to search a node in a Binary search tree using …

Search the node with minimum value in a Binary search tree

Search the node with minimum value in a binary search tree. To search a node with a minimum value in …