随笔分类 -  sort and search

heap
摘要: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.... 阅读全文

posted @ 2014-10-29 03:41 brave_bo 阅读(269) 评论(0) 推荐(0)

select sort
摘要:http://www.youtube.com/watch?v=EdUWyka7kpI 阅读全文

posted @ 2014-10-28 08:14 brave_bo 阅读(131) 评论(0) 推荐(0)

quick sort and find the k largest number in array.
摘要:1. using priortyqueue. priortyqueue是没有固定size的. http://wlh0706-163-com.iteye.com/blog/1850125 源码PriorityQueue(int initialCapacity, Comparator comparat... 阅读全文

posted @ 2014-10-28 08:11 brave_bo 阅读(161) 评论(0) 推荐(0)

counting sort ( can sort 0-k Auxiliary Space: O(n+k) Time Complexity: O(n+k) )
摘要: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... 阅读全文

posted @ 2014-10-24 06:25 brave_bo 阅读(163) 评论(0) 推荐(0)

Searching an Element in a Rotated Sorted Array
摘要: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... 阅读全文

posted @ 2014-10-09 06:25 brave_bo 阅读(265) 评论(0) 推荐(0)

Rotating an array in place
摘要: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, ... 阅读全文

posted @ 2014-10-09 05:53 brave_bo 阅读(195) 评论(0) 推荐(0)

Finding intersection of two sorted arrays
摘要: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... 阅读全文

posted @ 2014-10-09 03:12 brave_bo 阅读(206) 评论(0) 推荐(0)

radix sort
摘要:(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... 阅读全文

posted @ 2014-08-28 04:15 brave_bo 阅读(150) 评论(0) 推荐(0)

rebalance
摘要:rebalance a heapheap is a complete binary tree.⑴最大堆的插入 由于需要维持完全二叉树的形态,需要先将要插入的结点x放在最底层的最右边,插入后满 足完全二叉树的特点; 然后把x依次向上调整到合适位置满足堆的性质,例如下图中插入80,先将80放在最后,然后... 阅读全文

posted @ 2014-08-25 14:29 brave_bo 阅读(355) 评论(0) 推荐(0)

quicksort liner find kth smallest or
摘要: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... 阅读全文

posted @ 2014-02-16 15:27 brave_bo 阅读(308) 评论(0) 推荐(0)

leetcode -- find the lowest common ancestor
摘要:Given a binary tree, find the lowest common ancestor of two given nodes in the tree. _______3______ / \ ___5__ _... 阅读全文

posted @ 2013-08-16 05:09 brave_bo 阅读(262) 评论(0) 推荐(0)

导航