Heaps are mainly used for implementing priority queue. We have discussed below heaps in previous posts. Binary Heap Binomial Heap In terms of Time Complexity, Fibonacci Heap beats both Binary and Binomial Heaps. Below are amortized time complexities of Fibonacci Heap. 1) Find Min: Θ(1) [Same as both Binary and Binomial] 2) Delete Min: O(Log… Read More »
We strongly recommend to refer below posts as a prerequisite of this. K Dimensional Tree | Set 1 (Search and Insert) K Dimensional Tree | Set 2 (Find Minimum) In this post delete is discussed. The operation is to delete a given point from K D Tree. Like Binary Search Tree Delete, we recursively traverse… Read More »
We strongly recommend to refer below post as a prerequisite of this. K Dimensional Tree | Set 1 (Search and Insert) In this post find minimum is discussed. The operation is to find minimum in the given dimension. This is especially needed in delete operation. For example, consider below KD Tree, if given dimension is… Read More »
Segment tree is introduced in previous post with an example of range sum problem. We have used the same “Sum of given Range” problem to explain Lazy propagation
Given two Binary Search Trees, find common nodes in them. In other words, find intersection of two BSTs. Example: We strongly recommend you to minimize your browser and try this yourself first. Method 1 (Simple Solution) A simple way is to one by once search every node of first tree in second tree. Time complexity… Read More »
A typical Priority Queue requires following operations to be efficient. Get Top Priority Element (Get minimum or maximum) Insert an element Remove top priority element Decrease Key A Binary Heap supports above operations with following time complexities: O(1) O(Logn) O(Logn) O(Logn) A Self Balancing Binary Search Tree like AVL Tree, Red-Black Tree, etc can also… Read More »
Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. Example: Input: Root of below tree
Expression tree is a binary tree in which each internal node corresponds to operator and each leaf node corresponds to operand so for example expression tree for 3 + ((5+9)*2) would be:
In this article, first count of possible BST (Binary Search Trees)s is discussed, then construction of all possible BSTs. How many structurally unique BSTs for keys from 1..N?
Given a Binary Search Tree (BST) and a positive integer k, find the k’th smallest element in the Binary Search Tree.
Given a Binary Search Tree (BST) of integer values and a range [low, high], return count of nodes where all the nodes under that node (or subtree rooted with that node) lie in the given range.
Given a Binary Search Tree (BST) and a range, count number of nodes that lie in the given range.
Design a data structure to do reservations of future jobs on a single machine under following constraints. 1) Every job requires exactly k time units of the machine. 2) The machine can do only one job at a time.
In a Binary Search Tree (BST), all keys in left subtree of a key must be smaller and all keys in right subtree must be greater. So a Binary Search Tree by definition has distinct keys.
What is Handshaking Lemma? Handshaking lemma is about undirected graph. In every finite undirected graph number of vertices with odd degree is always even.
Hash Table supports following operations in Θ(1) time.
Given A binary Tree, how do you remove all the half nodes (which has only one child)? Note leaves should not be touched as they have both children as NULL.
Given a Binary Search Tree (BST) and a positive integer k, find the k’th largest element in the Binary Search Tree.
A vertex cover of an undirected graph is a subset of its vertices such that for every edge (u, v) of the graph, either ‘u’ or ‘v’ is in vertex cover.
A complete binary tree is a binary tree whose all levels except the last level are completely filled and all the leaves in the last level are all to the left side.