August 23, 2015
Here is the list of
tree questions worked on:
1. Lowest common
ancestor in Binary Tree (January 6, 2016 - Leetcode question: 236 medium)
https://github.com/jianminchen/LowestCommonAncestorInBinaryTree/blob/master/LowestCommonAncestorB.cs
Lowest common ancestor in Binary Search Tree (January 6, 2016 - Leetcode question: 235 easy)
https://github.com/mengli/leetcode/blob/master/LowestCommonAncestorOfaBinarySearchTree.java
https://github.com/jianminchen/Leetcode_C-/blob/master/235LowestCommonAncestorBSearchTree.cs
https://github.com/jianminchen/Leetcode_C-/blob/master/235LowestCommonAncestorBinarySearchTree.cs
2. Leetcode 102: Binary tree level
order traversal
a few of implementations:
https://github.com/jianminchen/BTreeLevelOrderTraversal
January 7, 2016 review
https://github.com/jianminchen/BTreeLevelOrderTraversal/blob/master/BTreeLevelOrderTraversal4.cs
January 7, 2016 review
https://github.com/jianminchen/BTreeLevelOrderTraversal/blob/master/BTreeLevelOrderTraversal4.cs
3. C# files:
TreeDemo.cpp
Pre Order
Traversal
In Order
Traversal
Post Order
Traversal
Breadth First
Traversal
Breadth First
Traversal Iterative
Pre Order
Traversal Iterative
Post Order
Traversal Iterative*
In Order
Traversal Iterative (A, B two versions)
Count One Child
Node
Recover Binary
Tree
Invert Binary
Tree
Invert Binary
Tree Iterative
--
Tree Post Order
Iterative
Tree In order
Iterative
4. Tree Max Path Sum
5. Linked List To
Binary Search Tree
6. Zigzag order
traversal of a binary Tree
7. Maximum Binary
Tree Path Sum
How to come out the idea using max value cross root? Cannot recall the idea.
Read the blog again (8/25/2015):
http://blog.unieagle.net/2012/12/09/leetcode%E9%A2%98%E7%9B%AE%EF%BC%9Abinary-tree-maximum-path-sum/
https://github.com/jianminchen/Leetcode_C-/blob/master/124BinaryTreeMaximumPathSum.cs
How to come out the idea using max value cross root? Cannot recall the idea.
Read the blog again (8/25/2015):
http://blog.unieagle.net/2012/12/09/leetcode%E9%A2%98%E7%9B%AE%EF%BC%9Abinary-tree-maximum-path-sum/
https://github.com/jianminchen/Leetcode_C-/blob/master/124BinaryTreeMaximumPathSum.cs
The problem can be extended to a tree, not just a binary tree. The solution is here:
http://juliachencoding.blogspot.ca/2015/07/itint5-tree-maximum-path-sum.html
http://juliachencoding.blogspot.ca/2015/07/itint5-tree-maximum-path-sum.html
8. ININT5: tree
maximum path sum
9. Binary Tree
Maximum Distance, diameter of binary
10. Morris Inorder
Traversal
11. Convert sorted
List to binary search tree (I) (Leetcode question: No. 109)
12. Convert sorted
list to binary search tree (II) (over 3 hours debugging to find a bug) (Leetcode question: No. 109)
August 23, 2015
It is so good to have
chance to review post order traversal iterative solution. So, Julia had chance
to read more about the problem, understand another solution using space
O(log(n)), use a prev variable
to keep track of the previously-traversed node.
Also, she had chance to work out using two stacks solution for post order traversal iterative solution.
Like this, First stack, root -> left child -> right child, the order of getting into first stack,
however, second stack, root-> right child -> left child, the order of getting into second stack.
since left, right child both get into the first stack, then, pop out two of them in reverse order.
* Read the following
blog to help understand post order traversal iterative
C# implementation of post order traversal iterative solution, using prev variable to help:
https://github.com/jianminchen/leetcode-tree/blob/master/TreePostOrderIterative_PrevVarirable.cs
https://github.com/jianminchen/leetcode-tree/blob/master/TreePostOrderIterative_PrevVarirable.cs
August 24, 2015
13. Convert sorted list to binary search tree (No. 109)
Read the following blogs:
http://articles.leetcode.com/2010/11/convert-sorted-list-to-balanced-binary.html
C#, bottom up, time O(n), space O(log n) solution:
https://github.com/jianminchen/Leetcode_C-/blob/master/109ConvertSortedListToBinarySearchTreeB.cs
C#, top down, time O(n^2), space O(long n) solution:
worked on code 2 times, first time, the calculation is kind of messy, then, worked on Leetcode question 108, get the idea to make it more simple; tips like len/2 only shows once, afterwards, use m instead. Just need to improve coding, think to make it more abstract, simple.
https://github.com/jianminchen/Leetcode_C-/blob/master/109ConvertSortedListToBinarySearchTreeC.cs
14. Convert sorted array to binary search tree (No. 108)
https://github.com/jianminchen/Leetcode_C-/blob/master/108ConvertSortedArrayToBinarySearchTree.cs
13. Convert sorted list to binary search tree (No. 109)
Read the following blogs:
http://articles.leetcode.com/2010/11/convert-sorted-list-to-balanced-binary.html
C#, bottom up, time O(n), space O(log n) solution:
https://github.com/jianminchen/Leetcode_C-/blob/master/109ConvertSortedListToBinarySearchTreeB.cs
C#, top down, time O(n^2), space O(long n) solution:
worked on code 2 times, first time, the calculation is kind of messy, then, worked on Leetcode question 108, get the idea to make it more simple; tips like len/2 only shows once, afterwards, use m instead. Just need to improve coding, think to make it more abstract, simple.
https://github.com/jianminchen/Leetcode_C-/blob/master/109ConvertSortedListToBinarySearchTreeC.cs
14. Convert sorted array to binary search tree (No. 108)
https://github.com/jianminchen/Leetcode_C-/blob/master/108ConvertSortedArrayToBinarySearchTree.cs
August 27, 2015
Leetcode Tree questions (29 questions):
Leetcode Tree questions (29 questions):
More reading about ternary tree:
https://en.wikipedia.org/wiki/Ternary_search_tree
https://en.wikipedia.org/wiki/Ternary_search_tree
No comments:
Post a Comment