Articles for category: Data Structures and Algorithms

Largest Number Formed from an Array

Problem Statement Given an array of N positive integers, arrange these integers in such a manner that when we join the elements, it is maximum among all possible permutations of the array elements. (Basically: Find the Largest Number Formed From an Array) Example Input: arr = [3, 30, 40, 9] Output: [9, 40, 3, 30] ...

Expression Tree

This article mainly explains Expression trees. Expression trees are binary trees where the internal nodes denote operators (“+”, “-“, “/”, “*”,”^”) whereas the leaf nodes denote operands. These expression trees are used to implement or represent various kinds of expressions like infix, postfix, and prefix expressions. What is the Expression Tree? Expression trees are the binary trees that are used to ...

Lowest Common Ancestor of a Binary Tree

Problem Statement Given a binary tree, and two values v1 and v2, find the lowest common ancestor of nodes with their values as v1 and v2. Where the lowest common ancestor of two nodes (Node1 and Node2) is the deepest node of which Node1 and Node2 are descendants. Note that here we consider that a node is the descendant of itself also. Examples Example 1 – Input ...

Kaprekar Number

Problem Statement A number is said to be a kaprekar number if the square of the number is divided into two parts in such a way that the sum of divided parts equals the original number where none of the parts is having a value of 0. We have given a number to find out whether the number ...

Leaky bucket algorithm

Problem Statement Consider a host A connected to a network. Host A produces bursty traffic (explained below) in the form of variable-length packets that must be transmitted to the receiver through a network. Suppose Host A sends : This traffic nature is called bursty traffic, coming from a source into the network. Bursty traffic is ...

Fractional Knapsack Problem

The Knapsack problem is a class of optimization problems in which we have to find the maximal answer among all the various possibilities given in the question. There are three types of knapsack problems $i.e.$ 0-1 Knapsack, Fractional Knapsack, and Unbounded Knapsack. In this article, we will be seeing the fractional knapsack Problem in detail. ...

Quadratic Probing

Problem Statement Given a hash function, Quadratic probing is used to find the correct index of the element in the hash table. To eliminate the Primary clustering problem in Linear probing, Quadratic probing in data structure uses a Quadratic polynomial hash function to resolve the collisions in the hash table. Example Let there a table ...

Binomial Heap

The heap is a tree-based structure that is a complete binary tree. The binomial tree is of orders 0 and 1. A binomial heap is a specific implementation of a heap. It is a collection of small binomial heaps that are linked to each other and follow the heap property. There should be at least ...

Intersection of Two Linked Lists

Implement a program to detect the intersection point of two linked lists, where one list accidentally merges with the other, forming an inverted Y-shaped structure. For example, the following two linked lists have common nodes starting from c1. Thus, c1 is the intersection point of two linked lists. Approach 1: Using Two Nested Loops Utilize ...

Implement Queue Using stack

Problem Statement The problem statement here is to implement queue using stack.Queue is a linear data structure which follows First In First Out (FIFO) principle. This means that the element which is inserted first will be the one that will be removed first. Stack is also a linear data structure which follows Last In First ...