随笔分类 -  Sorting Algorithm

摘要:O(n) look for the median(or any target rank) in an array 1 class Solution { 2 public static void main(String[] args) { 3 Solution solution = new Solut 阅读全文
posted @ 2021-01-12 03:22 新一代的天皇巨星 阅读(118) 评论(0) 推荐(0)
摘要:Sort a linked list in O(n log n) time using constant space complexity. Hide Tags Linked List Sort Hide Similar Problems (E) Merge Two Sorted Lists (M) 阅读全文
posted @ 2016-04-25 09:21 新一代的天皇巨星 阅读(157) 评论(0) 推荐(0)
摘要:Heap(An array visualized as a complete binary tree):Heap Operations:Insert, O(log(n)) Add it to the end of the tree and bubbl... 阅读全文
posted @ 2015-01-05 09:31 新一代的天皇巨星 阅读(330) 评论(0) 推荐(0)
摘要:Good for array and linked list. Stable Sort.Time Complexity: Best, Average, Worst => O(nlogn);Space Complexity: O(n), in-place merge sort makes it ver... 阅读全文
posted @ 2015-01-04 12:32 新一代的天皇巨星 阅读(276) 评论(0) 推荐(0)
摘要:Insertion Sort:Time Complexity: Best O(n) (when already sorted); Average O(n^2); Worst O(n^2).Space Complexity: O(1) public static void main(String... 阅读全文
posted @ 2015-01-04 10:11 新一代的天皇巨星 阅读(245) 评论(0) 推荐(0)
摘要:Bucket Sort:Scenario:Work when keys are in a small range.Linked List.Algorithm(Stable):1. Walk through each item and enqueue each item into its approp... 阅读全文
posted @ 2014-12-28 05:24 新一代的天皇巨星 阅读(217) 评论(0) 推荐(0)
摘要:Quick sort is empirically fastest among all the O(nlogn) sorting algorithms.Time Complexity:Best, Average, T(n) = 2T(n/2) + O(n) => O(nlogn)Worst case... 阅读全文
posted @ 2014-12-28 03:51 新一代的天皇巨星 阅读(188) 评论(0) 推荐(0)