2014年1月14日
摘要: Sort List2014.1.14 23:17Sort a linked list inO(nlogn) time using constant space complexity.Solution: The first thing I thought of about this problem is merge sort. It's weakness in space complexity is perfectly avoided with linked list, as you won't need another O(n) space when merging two s 阅读全文
posted @ 2014-01-14 23:19 zhuli19901106 阅读(184) 评论(0) 推荐(0)
摘要: Insertion Sort List2014.1.14 21:58Sort a linked list using insertion sort.Solution: Everyone must've have learned about insertion sort on some data structure textbooks, like "Data Structures & Algorithm Analysis". They usually present you with source code for insertion sort on arra 阅读全文
posted @ 2014-01-14 22:13 zhuli19901106 阅读(148) 评论(0) 推荐(0)
摘要: Binary Tree Postorder Traversal2014.1.14 21:17Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].Note:Recursive solution is trivial, could you do it iteratively?Solution1: Recursive solution is trivial,... 阅读全文
posted @ 2014-01-14 21:38 zhuli19901106 阅读(294) 评论(0) 推荐(0)
摘要: Binary Tree Preorder Traversal2014.1.14 02:36Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Note:Recursive solution is trivial, could you do it iteratively?Solution1: The recursive version of preorde... 阅读全文
posted @ 2014-01-14 02:38 zhuli19901106 阅读(205) 评论(0) 推荐(0)