# Parentheses matching problem.

Given a set of parentheses (a string expression), we aim to validate those parentheses. Let us see this with some examples. We can solve this problem using stack data structure. Here we have taken three sets of braces which are ‘{}’, ‘()’ and ‘[]’. Algorithm Check if stack not empty and current bracket character isRead More »

# Queue using two stacks

A Queue is a FIFO (First In First Out) data structure. In this article, we aim to implement a Queue using two stack data structures. To implement Queue generally, we have some simple data structure that can hold data. In general, Queue supports insertion (enqueue) and deletion (dequeue) operations, which we can do with constantRead More »

# Stack data structure with push, pop, and min operations in O(1) complexity

A stack is a LIFO(Last In First Out) data structure. Like all other data structures, it supports two basic operations like push(insert), pop(delete), with constant complexity (i.e., O(1)). In contrast, usually, the stack doesn’t have a min (minimum) as a default operation. To have this min operation, we need to have an auxiliary stack (whichRead More »

# Spiral order binary tree traversal

Spiral order traversal is a type of level order traversal where each alternate level traverses from right to left. This traversal is as shown in the picture below. In the tree as shown here, the level one traverses from right to left and processes {10, 8, 4, 50, 24, 5, 12, 18}. As observed levelRead More »

# Largest rectangular area in a histogram

A Histogram is a picture that contains multiple rectangular bars of different sizes based on a value that it represents. First of all let’s create a histogram by taking an example array. Picture represents histogram for input {4, 3, 2, 1}. Here rectangular bars represent larger from 4 to smaller to 1. Let’s jump intoRead More »

# Stack data structure

Stack is the most popular and historical data structure. A list of items arranged one on top of others. Stack data structure popularly used to maintain program memory stack. It follows the last-in-first-out order. Let’s consider a stack of discs as shown in the below picture. As shown in this diagram, only the top nodeRead More »