Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

Algorithms Lesson 4: Quicksort

Loading...

Sign in or sign up now!
125,466
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Sep 10, 2009

http://xoax.net/

For this lesson, we explain and demonstrate graphically how to perform the quicksort algorithm with a pseudocode implementation.

Please submit all questions to our forum: http://xoax.net/forum/

  • likes, 12 dislikes

Link to this comment:

Share to:

Top Comments

  • The pseudocode was particularly helpful. I am writing an algorithms exam tomorrow, and this video's helped me make sure I know what's going on.

  • u save me dude!!!!

see all

All Comments (82)

Sign In or Sign Up now to post a comment!
  • Worst case maybe N^2, but don't forget that if you shuffle the array(before any sorting) and pick the median as the pivot, then use insertion sort for small enough sections, you can avoid N^2 with a very high probability, getting closer to the best case, Nlg(N). This is why this algorithm is widely used in the industry...

  • @VinUnleaded182

    Umm no. Has nothing to do with "worst case scenario".

  • @vileguy "After it swaps, the cursors move forward."

    You are assuming unique values. KHCshadow1 was talking about duplicate values, which will produce an infinite loop.

  • @unrealhacker12

    Yeah man. You're right! Good catch.

  • @illusionist50

    In this case, there will be an infinite loop, because the 17's will swap back and forth indefinitely WITHOUT ADVANCING THE CURSORS. See the line of code that advances the L cursor "while (A[L] < pivot) L = L + 1". Now substitute the value 17 for A[L] and pivot. Notice condition will always be false, therefore cursor will not advance. Same story with the R cursor.

  • @unrealhacker12 yea its called the worst case scenario

  • @unrealhacker12

    not really, what you are talking about is the worst case scenario. However, it will not be infinite loop. But it will sort the items one at a time costing O(n^2) "quadratic complexity"

    swapping 17 with another 17 can happen only once because after that, the two pointers which are doing the swaps will intersect and that is a stop condition for the q sort algorithm.

    By the way this is the third method to do a quick sort.

  • I don't see how this algorithm would work, if 17, 32, 29, 17, 37, 15, 10, 42, 15,17 if the pivot was the last element 17 then it would get caught in a loop indefinitely swapping 17 with 17 as both are equal to the pivot.

  • you are the man! thank you dude!

    could you please let me know how did you make this video? what program did you used?

View all Comments »
Loading...
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more