摘要:http://www.youtube.com/watch?v=-6-xKgLOZPMbinary heap : it is a complete binary tree.index from 0:i left = 2i +1; i right = 2i +2, i parent = (i-1)/2....
阅读全文
摘要:http://www.youtube.com/watch?v=EdUWyka7kpI
阅读全文
摘要:1. using priortyqueue. priortyqueue是没有固定size的. http://wlh0706-163-com.iteye.com/blog/1850125 源码PriorityQueue(int initialCapacity, Comparator comparat...
阅读全文
摘要:http://www.youtube.com/watch?v=o3FUC6l89tMhttp://www.geeksforgeeks.org/counting-sort/only 0 - k can not be negtive71522 最大7.new array(7).0 1 2 3 4 5...
阅读全文
摘要:Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). How do you find an elemen...
阅读全文
摘要:April 13, 2010inUncategorizedRotate a one-dimensional array of n elements to the right by k steps.For instance, with n=7 and k=3, the array {a, b, c, ...
阅读全文
摘要:Find the intersection of two sorted arrays.Let’s called array1 as A and array2 as B, each with size m and n.The obvious brute-force solution is to sca...
阅读全文
摘要:(radix sort)Problem StatementGiven an integer array of length N, containing values in the range 1,2,3…N^2. Sort the array in O(N) time.//http://www.ge...
阅读全文
摘要:rebalance a heapheap is a complete binary tree.⑴最大堆的插入 由于需要维持完全二叉树的形态,需要先将要插入的结点x放在最底层的最右边,插入后满 足完全二叉树的特点; 然后把x依次向上调整到合适位置满足堆的性质,例如下图中插入80,先将80放在最后,然后...
阅读全文
摘要:Let's solve a problem with application of quick sort.Problem statementGiven an set of numbers in non-sorted order, find the Kth smallest element.Kth s...
阅读全文
摘要:Given a binary tree, find the lowest common ancestor of two given nodes in the tree. _______3______ / \ ___5__ _...
阅读全文