Data structure interview questions with code in JAVA
-
Coin change problem 💰 (Number of ways sum can be achieved): You are given unlimited supply of coins of some denominations. Find the number of ways you can achieve in finding a sum value using these coins.
-
Coin change problem (Minimum number of coins): You are given unlimited supply of coins of some denominations. Find the number of ways you can achieve in finding a sum value using these coins.
-
Sieve of Eratosthenes (Find the prime numbers): Given a number n, print all primes smaller than or equal to n.
-
Longest Common Subsequence: Given two sequences, find the length of the longest subsequence present in both of them.
-
Next greater element (Using stacks): Find the next greater element in an array. If not found for an element show null.
-
Minimum element in array: Find the minimum element in an array.
-
Leader in array: Find all the leaders in the array.
-
KMP Algorithm: Knuth-Morris-Pratt string searching algorithm searches for occurrences of a word W within a main text string S.
- Binary to Doubly linked list: Construction of doubly linked list from a binary tree.
-
Binary search tree: construct: Construction of binary search tree from integer array.
-
Pre-Order Traversal of BST: (Recursive): Pre-order traversal of Binary Tree recursively.
-
Pre-Order Traversal of BST: (Non-Recursive): Pre-order traversal of Binary Tree non-recursively using stacks.
-
In-Order Traversal of BST: (Recursive): In-order traversal of Binary Tree recursively.
-
In-Order Traversal of BST: (Non-Recursive): In-order traversal of Binary Tree non-recursively using stacks.
-
Post-Order Traversal of BST: (Recursive): Post-order traversal of Binary Tree recursively.
-
Post-Order Traversal of BST: (Non-Recursive): Post-order traversal of Binary Tree non-recursively using stacks.
-
Diameter of Binary Tree: Diameter of tree is the length of the longest path between any two nodes in a tree. The path may or may not pass through root.
-
Deepest node in Binary Tree: Given a binary tree, find the deepest node in it.
-
Boundary Traversal of Binary tree: Given a complete binary tree, traverse it such that all the boundary nodes are visited in Anti-Clockwise order starting from the root.
-
Height of Binary Tree: Find the Maximum Depth or Height of a Tree.
-
Level order traversing: Level order traversing of binary tree.
-
Number of leaves of Binary tree: Print all the leaves of binary tree.
-
Print all ancestors of node: Print all the ancestors of the node in a binary tree.
-
Print all the paths from root to leaves: Print all the paths from root to leaf in a binary tree.
-
Size of binary tree(Recursively): Find the size of the binary tree, recursively.
-
Size of binary tree(Non-recursively): Find the size of the binary tree, non-recursively.
-
Vertical sum of binary tree: Find all the vertical sums of the nodes.
-
Lowest common ancestor of two nodes: Given a binary tree (not a binary search tree) and two values say n1 and n2, write a program to find the least common ancestor.
-
Diagonal sum of two nodes: Print the sum of every diagonal in binary tree.
-
Boundary traversal of binary tree: Print the boundary traversal of binary tree.
-
Top view of binary tree: Print the top view of binary tree.
-
Bottom view of binary tree: Print the bottom view of binary tree.
-
Side view of binary tree(Left and Right view): Print the side views of binary tree both the left side view and right side view.
-
Inorder predecessor of binary tree: Print the inorder predecessor of a node in a binary tree.
-
Inorder successor of binary tree: Print the inorder successor of a node in a binary tree.
-
BFS: Breadth First Search (BFS) algorithm traverses a graph in a breadth ward motion and uses a queue to remember to get the next vertex to start a search.
-
DFS: Depth First Search (DFS) algorithm traverses a graph in a depth ward motion and uses a stack to remember to get the next vertex to start a search.
-
Dijkstra Algorithm: an algorithm for finding the shortest path from a starting node to a target node in a weighted graph.
-
Bellman Ford Algorithm: an algorithm that computes the shortest paths from a single source vertex to all the other vertices in a weighted digraph.
-
Floyd Warshell Algorithm: an algorithm for finding the shortest path between all the pairs of vertices in a weighted graph. This algorithm works for both the directed and undirected weighted graphs.
-
Disjoint sets: A disjoint-set data structure is a data structure that keeps track of a set of elements partitioned into a number of disjoint (non-overlapping) subsets. This can be used for determining if two elements are in the same subset. Union: Join two subsets into a single subset.
-
Find cycle in undirected graph(disjoint sets): Finding the cycle inside an undirected graph using the disjoint sets.
-
Find cycle in directed graph(dfs): Finding the cycle inside an directed graph using the dfs.