Skip to content

Commit f396f4b

Browse files
committed
Implement tree datastrucure algorithms
1 parent cdc5409 commit f396f4b

File tree

87 files changed

+1949
-586
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1949
-586
lines changed

README.md

+16-27
Original file line numberDiff line numberDiff line change
@@ -136,33 +136,22 @@ List of Programs related to data structures and algorithms
136136

137137
### Tree
138138

139-
1. Maximum depth of binary tree: [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/1.maxDepthBinaryTree/maxDepthBinaryTree.js)
140-
141-
2. Same tree: [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/sameTree.js)
142-
143-
3. Invert or Flip binary tree: [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/invertTree.js)
144-
145-
4. Binary tree maximum path sum: [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/maxPathSum.js)
146-
147-
5. Binary tree level order traversal: [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/levelOrderTraversal.js)
148-
149-
6. Serialize and deserialize binary tree: [JavaScript](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/serializeDeserialize.js)
150-
151-
7. Subtree of another tree: [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/subtree.js)
152-
153-
8. Construct binary tree from preorder and inorder traversal: [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/buildTree.js)
154-
155-
9. Validate BST: [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/validateBST.js)
156-
157-
10. Kth smalleest element in BST: [JavaScript](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/kthSmallestBST.js)
158-
159-
11. Lowest Common Ancestor of BST: [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/lowestCommonAncestor.js)
160-
161-
12. Trie: [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/trie.js)
162-
163-
13. Design and Search words Datastructure: [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/wordDictionary.js)
164-
165-
14. Word search 2: [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/wordSearch2.js)
139+
| No. | Name | Source | Playground | Documentation | Level | Pattern |
140+
| :-: | :--------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------: | :---: | :------------------------------------: |
141+
| 1 | Maximum depth of binary tree | [Source](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/1.maxDepthBinaryTree/maxDepthBinaryTree.js) | [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/1.maxDepthBinaryTree/maxDepthBinaryTree.js) | [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/1.maxDepthBinaryTree/maxDepthBinaryTree.js) | Easy | Depth First Search(DFS) with recursion |
142+
| 2 | Same tree | [Source](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/2.sameTree/sameTree.js) | [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/2.sameTree/sameTree.js) | [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/2.sameTree/sameTree.md) | Easy | Depth First Search(DFS) with recursion |
143+
| 3 | Invert or Flip binary tree | [Source](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/3.invertTree/invertTree.js) | [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/3.invertTree/invertTree.js) | [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/3.invertTree/invertTree.js) | Easy | Swapping nodes and Depth First Search(DFS) with recursion |
144+
| 4 | Binary tree maximum path sum | [Source](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/4.maxPathSum/maxPathSum.js) | [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/4.maxPathSum/maxPathSum.js) | [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/4.maxPathSum/maxPathSum.md) | Hard | DFS using recursion |
145+
| 5 | Binary tree level order traversal | [Source](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/5.levelOrderTraversal/levelOrderTraversal.js) | [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/5.levelOrderTraversal/levelOrderTraversal.js) | [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/5.levelOrderTraversal/levelOrderTraversal.js) | Easy | Depth First Search(DFS) with recursion |
146+
| 6 | Serialize and deserialize binary tree | [Source](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/6.serializeDeserialize/serializeDeserialize.js) | [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/6.serializeDeserialize/serializeDeserialize.js) | [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/6.serializeDeserialize/serializeDeserialize.md) | Hard | DFS preorder traversal |
147+
| 7 | Subtree of another tree | [Source](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/7.subtree/subtree.js) | [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/7.subtree/subtree.js) | [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/7.subtree/subtree.js) | Easy | Depth First Search(DFS) with recursion |
148+
| 8 | Construct binary tree from preorder and inorder traversal | [Source](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/8.buildTree/buildTree.js) | [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/8.buildTree/buildTree.js) | [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/8.buildTree/buildTree.md) | Medium | DFS with recursion |
149+
| 9 | Validate BST | [Source](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/9.validateBST/validateBST.js) | [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/9.validateBST/validateBST.js) | [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/9.validateBST/validateBST.js) | Medium | Depth-First-Search(DFS) using recursion |
150+
| 10 | Kth smallest element in BST | [Source](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/10.kthSmallestBST/kthSmallestBST.js) | [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/10.kthSmallestBST/kthSmallestBST.js) | [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/10.kthSmallestBST/kthSmallestBST.js) | Medium | Iterative inorder traversal using stack |
151+
| 11 | Lowest Common Ancestor of BST | [Source](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/11.lowestCommonAncestor/lowestCommonAncestor.js) | [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/11.lowestCommonAncestor/lowestCommonAncestor.js) | [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/11.lowestCommonAncestor/lowestCommonAncestor.md) | Medium | Iterative tree traversal |
152+
| 12 | Trie | [Source](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/12.trie/trie.js) | [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/12.trie/trie.js) | [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/12.trie/trie.js) | Medium | Iteration over string characters |
153+
| 13 | Design and Search words Datastructure | [Source](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/13.wordDictionary/wordDictionary.js) | [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/13.wordDictionary/wordDictionary.js) | [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/13.wordDictionary/wordDictionary.md) | Medium | Trie and DFS recursion |
154+
| 14 | Word search 2 | [Source](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/14.wordSearch2/wordSearch2.js) | [JavaScript](https://livecodes.io/?console&x=https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/14.wordSearch2/wordSearch2.js) | [Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/algorithms/tree/14.wordSearch2/wordSearch2.js) | Hard | Backtracking with Trie |
166155

167156
### Graph
168157

src/images/construct-tree.png

21.9 KB
Loading

src/images/dictionary.png

28 KB
Loading

src/images/invert-tree.png

35.4 KB
Loading

src/images/invert-tree1.png

16.8 KB
Loading

src/images/kthsmallest-bst.png

18.3 KB
Loading

src/images/level-order-traversal.png

20.5 KB
Loading

src/images/lowest-common-ancestor.png

22.3 KB
Loading

src/images/max-depth-tree.png

20.4 KB
Loading

src/images/max-path-sum1.png

7.83 KB
Loading

src/images/max-path-sum2.png

13.9 KB
Loading

src/images/not-same-tree.png

13.8 KB
Loading

src/images/same-tree.png

27.7 KB
Loading

src/images/serialize-deserialize.png

17.1 KB
Loading

src/images/subtree1.png

32.6 KB
Loading

src/images/subtree2.png

28.5 KB
Loading

src/images/trie.png

35.1 KB
Loading

src/images/validate-bst.png

8.15 KB
Loading

src/images/validate-bst1.png

14.2 KB
Loading

src/images/wordsearch2-1.png

7.52 KB
Loading

src/java1/algorithms/tree/KthSmallestBST.java

-47
This file was deleted.

src/java1/algorithms/tree/LevelOrderTraversal.java

-36
This file was deleted.

src/java1/algorithms/tree/LowestCommonAncestor.java

-32
This file was deleted.

src/java1/algorithms/tree/MaxPathSum.java

-31
This file was deleted.

0 commit comments

Comments
 (0)