Friday, November 9, 2018

Life is tough to work with 18 medium level tree algorithms

Nov. 9, 2018

Introduction


It is my plan to work on 18 medium level tree algorithms. I spent 30 minutes to think about two medium level algorithms, I had hard time to come out clean and elegant solutions for those two algorithms. Life is tough now to work with those medium level algorithms.


Nov. 21, 2018

It is such sweet feeling to solve the algorithm called 863. All nodes distance K in binary tree.

I like to highlight a few things to help me expedite the problem solving process.

1. Use Dictionary<TreeNode, HashSet<TreeNode> to represent the graph
2. Tree traversal algorithm is easy to write
3. Understand the graph - directed graph using Dictionary
4. Use queue to track k steps away nodes, using visted hashset to avoid loops.

Medium level tree algorithms (solved 19, total 39, shared 17)
94. Binary Tree Inorder Traversal using stack
94. Binary Tree Inorder Traversal use recursive function
95. Unique Binary Search Trees II
96. Unique Binary Search Trees
98. Validate Binary Search Tree
102. Binary Tree Level Order Traversal submitted in 2015
102. Binary Tree Level Order Traversal submitted in 2018
105. Construct Binary Tree from Preorder and Inorder Traversal
106. Construct Binary Tree from Inorder and Postorder Traversal
113. Path Sum II
114. Flatten Binary Tree to Linked List
129. Sum Root to Leaf Numbers
199. Binary Tree Right Side View
222. Count Complete Tree Nodes
236. Lowest Common Ancestor of a Binary Tree
337. House Robber III
450. Delete Node in a BST
662. Maximum Width of Binary Tree
684. Redundant Connection union find using array
684. Redundant Connection using Dictionary<Int, HashSet>
863. All Nodes Distance K in Binary Tree

No comments:

Post a Comment