Data Structure

Binary Tree Traversals

There are three types of binary tree traversals In - Order Traversal Pre - Order Traversal Post - Order Traversal In - Order Traversal ( leftChild - root - rightChild ) In In-Order traversal, the root node is visited between left child and right child. In this traversal, the left [...]

2017-09-16T13:28:48+05:30Categories: Data Structure|Tags: |

Circular Queue

Circular Queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the first position to make a circle. Implementation of Circular Queue To implement a circular queue data structure using array, we [...]

2017-03-10T00:16:35+05:30Categories: Data Structure|

Largest rectangle in a histogram

Problem: Given an array of bar-heights in a histogram, find the rectangle with largest area. Solution: Assuming, all elements in the array are positive non-zero elements, a quick solution is to look for the minimum element hmin in the array. Then numElements * hmin can be one of the possible [...]

2017-03-01T11:54:22+05:30Categories: Data Structure|Tags: |

Stock span problem

We are given a list of prices of a stock for N number of days. We need to find stock span for each day. Span is defined as number of consecutive days before the given day where the price of stock was less than or equal to price at given day. For [...]

2018-09-28T11:57:54+05:30Categories: Data Structure|Tags: |

Expression (Postfix, Prefix, Infix) conversion

Arithmetic expression evaluation In expression (A + B) * C, the addition of A and B to be done first before the multiplication. Infix requires the parentheses to force the performance of the addition before the multiplication. However, when A + B was written in prefix, the addition operator was [...]

2019-04-13T19:42:32+05:30Categories: Data Structure|Tags: |

Detect loop in linked list

Floyd's algorithm for cycle detection is the fastest method to detect loop in linked list. Traverse linked list using two pointers. Move one pointer by one and other pointer by two. If these pointers meet at some node then there is a loop. If pointers do not meet then linked [...]

2017-02-08T22:16:05+05:30Categories: Data Structure|Tags: |

Space complexity in Data structure

Space complexity is a measure of the amount of working storage an algorithm needs. That means how much memory, in the worst case, is needed at any point in the algorithm. As with time complexity, we're mostly concerned with how the space needs grow, in big-Oh terms, as the size [...]

2017-02-08T18:53:26+05:30Categories: Data Structure|Tags: |
Go to Top