Category: data structure

Print All Leaf Nodes of a Binary Tree

Print All Leaf Nodes of a Binary Tree

“Print All Leaf Nodes of a Binary Tree” is a basic problem of tree data structure. Here, we are given a binary tree and our task is to print all leaf nodes of given binary tree from left to right. Leaf Nodes: Leaf Nodes are those nodes/vertices of a tree,...

Binary Tree Traversal

Binary Tree Traversal

Binary Tree Traversal is a process of visiting every node of the tree and print the node value. Unlike linear data structure like arrays and linked lists which can be traversed only in linear manner. Trees can be traversed in multiple manner. Majorly, the trees can be traversed in following...

Introduction to Tree Data Structure

Tree Data Structure is a non-linear or hierarchical data structure. In terms of graph, tree data structure can be defined as a special type of graph data structure with no circuits in it. Basic Terminologies of Tree Data Structure: Root Node: Root Node is a first node in a tree...

Check whether an Array is subset of another Array

Check whether an Array is subset of another Array

“Check whether an Array is subset of another Array” is a basic problem which can be solved using multiple methods like brute-force, sorting, binary search and hashing. Here, in this problem, we are given two arrays; arr1 and arr2 and our task is to write a program to check whether...

blank

Stock Span Problem

“Stock Span Problem” is a classic problem of stack data structure, asked in technical interviews of many product-based companies. Here, we are given a price of a single stock for ‘N’ consecutive days and our task is to find the stock span for each day. Stock Span is defined as number...

blank

Sort a Stack Using Temporary Stack

“Sort a Stack Using Temporary Stack” is again one of the favorite technical interview problems based on stack data structure. Here, in this problem, we are given a stack and our task is to sort the elements of given stack using help of another temporary stack. The top of the...

Next Greater Frequency Element

Next Greater Frequency Element

“Next Greater Frequency Element” is a standard problem of stack data structure. Here, in this problem, we are given an array and our task is to write a program to find the next (right side) greater frequency element of every element. If for any particular element next greater frequency element...

blank

Print Bracket Number

“Print Bracket Number” is a stack based basic problem asked in technical round of product- based company. Here, in this problem, we are given a expression string of balanced brackets and our task is to print the bracket number when the expression is being parsed. Example: Expression: (())() Bracket Number:...

blank

Implement Two Stacks in a Single Array

“Implement Two Stacks in a Single Array” is a popular technical interview problem based on stack data structure. Here, we are given an array of size ‘n’ and our task is to implement two stacks in a single array. We need to ensure that the space in an array is...