随笔分类 - 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
阅读全文
摘要: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)
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文

浙公网安备 33010602011771号