Skip to content

All the Data structure related questions with solutions (code) in Java language. Topics include Arrays, Strings, LinkedList, Stack, Queues, Trees, Graphs, Dynamic Programming and much more. :)

Notifications You must be signed in to change notification settings

DevAnuragGarg/Data-Structures-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 

Repository files navigation

Data Structures using Java 🏆

Data structure interview questions with code in JAVA

Dynamic Programming

  1. 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.

  2. 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.

  3. Sieve of Eratosthenes (Find the prime numbers): Given a number n, print all primes smaller than or equal to n.

  4. Longest Common Subsequence: Given two sequences, find the length of the longest subsequence present in both of them.

Arrays

  1. Next greater element (Using stacks): Find the next greater element in an array. If not found for an element show null.

  2. Minimum element in array: Find the minimum element in an array.

  3. Leader in array: Find all the leaders in the array.

  4. KMP Algorithm: Knuth-Morris-Pratt string searching algorithm searches for occurrences of a word W within a main text string S.

Linked List

  1. Binary to Doubly linked list: Construction of doubly linked list from a binary tree.

Trees 🌳

  1. Binary search tree: construct: Construction of binary search tree from integer array.

  2. Pre-Order Traversal of BST: (Recursive): Pre-order traversal of Binary Tree recursively.

  3. Pre-Order Traversal of BST: (Non-Recursive): Pre-order traversal of Binary Tree non-recursively using stacks.

  4. In-Order Traversal of BST: (Recursive): In-order traversal of Binary Tree recursively.

  5. In-Order Traversal of BST: (Non-Recursive): In-order traversal of Binary Tree non-recursively using stacks.

  6. Post-Order Traversal of BST: (Recursive): Post-order traversal of Binary Tree recursively.

  7. Post-Order Traversal of BST: (Non-Recursive): Post-order traversal of Binary Tree non-recursively using stacks.

  8. 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.

  9. Deepest node in Binary Tree: Given a binary tree, find the deepest node in it.

  10. 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.

  11. Height of Binary Tree: Find the Maximum Depth or Height of a Tree.

  12. Level order traversing: Level order traversing of binary tree.

  13. Number of leaves of Binary tree: Print all the leaves of binary tree.

  14. Print all ancestors of node: Print all the ancestors of the node in a binary tree.

  15. Print all the paths from root to leaves: Print all the paths from root to leaf in a binary tree.

  16. Size of binary tree(Recursively): Find the size of the binary tree, recursively.

  17. Size of binary tree(Non-recursively): Find the size of the binary tree, non-recursively.

  18. Vertical sum of binary tree: Find all the vertical sums of the nodes.

  19. 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.

  20. Diagonal sum of two nodes: Print the sum of every diagonal in binary tree.

  21. Boundary traversal of binary tree: Print the boundary traversal of binary tree.

  22. Top view of binary tree: Print the top view of binary tree.

  23. Bottom view of binary tree: Print the bottom view of binary tree.

  24. 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.

  25. Inorder predecessor of binary tree: Print the inorder predecessor of a node in a binary tree.

  26. Inorder successor of binary tree: Print the inorder successor of a node in a binary tree.

Graphs

  1. 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.

  2. 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.

  3. Dijkstra Algorithm: an algorithm for finding the shortest path from a starting node to a target node in a weighted graph.

  4. Bellman Ford Algorithm: an algorithm that computes the shortest paths from a single source vertex to all the other vertices in a weighted digraph.

  5. 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.

  6. 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.

  7. Find cycle in undirected graph(disjoint sets): Finding the cycle inside an undirected graph using the disjoint sets.

  8. Find cycle in directed graph(dfs): Finding the cycle inside an directed graph using the dfs.

About

All the Data structure related questions with solutions (code) in Java language. Topics include Arrays, Strings, LinkedList, Stack, Queues, Trees, Graphs, Dynamic Programming and much more. :)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages