Visual Demonstration of the QuickSort Algorithm | thuật toán quick sort

thuật toán quick sort. Có phải bạn đang tìm kiếm chủ đề về Visual Demonstration of the QuickSort Algorithm phải không? Nếu đúng như vậy thì mời bạn xem nó ngay tại đây. Xem thêm các video thú vị tại website

VIDEO Visual Demonstration of the QuickSort Algorithm

thuật toán quick sort



Visual demonstration of the QuickSort algorithm

Blog entry: http://blog.bodurov.com/Visualizing-QuickSort-Algorithm

Picture Visual Demonstration of the QuickSort Algorithm

Tag Visual Demonstration of the QuickSort Algorithm

thuật toán quick sort,QuickSort,algorithm,software,programming,sorting

Xem thêm bài viết thuộc chuyên mục: Tổng hợp

31 bình luận về “Visual Demonstration of the QuickSort Algorithm | thuật toán quick sort”

  1. Following your excellent explanation, here is a full implementation in java

    public class QuickSort<Type extends Comparable> {

    public void sort(Type[] array, int left, int right) {
    if (right – left <= 0)
    return;

    // used for recursion
    int origin_left = left;
    int origin_right = right;

    Type pivot = array[left]; // choose the left element as a pivot

    boolean doRight = true; // movement flag

    while (left < right) {
    // right pointer movement
    if (doRight) {
    // move the pointer do nothing
    if (array[right].compareTo(pivot) > 0) {
    right–;
    } else {
    // move the value to the left pointer. and increment the left pointer
    array[left] = array[right];
    left++;
    doRight = false;
    }
    }
    // left pointer movement
    else {
    if (array[left].compareTo(pivot) < 0) {
    // move the pointer do nothing
    left++;
    } else {
    // move the value to the right pointer. and decrement the right pointer
    array[right] = array[left];
    right–;
    doRight = true;
    }
    }
    }
    // left = right. choose any
    int middle = left;

    // place the pivot value
    array[middle] = pivot;

    // process the rest of the sub arrays recursively
    sort(array, origin_left, middle – 1);
    sort(array, middle + 1, origin_right);
    }

    public static void main(String[] args) {
    QuickSort<Integer> quickSort = new QuickSort<Integer>();
    Integer[] array = {4, 8, 1, 6, 3, 7, 2, 5};
    quickSort.sort(array, 0, array.length – 1);
    }
    }

  2. Thank you for the well explanation. The pivot can be seen and estimated better when it is remove from the list of elements and not to mention we all do get confused much times. For every position where the pivot is located at, the left element or the right element has to follow the direction towards the pivot. Keep in mind that the left side has to be lower than the pivot and the right side has to be higher than the pivot. You swap as you move along. Look up different explanations on quicksort to gain firm understanding quick sort is one tough bitch.

  3. This is a good video 🙂
    The explanation is correct, but this does not mention the fact that this is just one of the ways of partitioning possible: Hoare's. There are others such as Lomuto's, which is "simpler" while requiring more swaps. I am in favor of quicksort being explained/illustrated without a specific partition scheme chosen and without any in-place requirement, such as shown by code here: http://ideone.com/nW8fyr

    It is easier to understand in-place partitioning schemes once you know what the algorithm itself is supposed to do. 

Bình luận đã đóng.