Stack (Quick Sort) and Recursion

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

Data Structures

Lecture: Quick Sort

By
Arvind Kumar
Asst. Professor

Lovely Professional University, Punjab


Blank
Recursive Algorithm
• QUICKSORT(A, p, r)
1. if p < r
2. q =PARTITION(A, p, r)
3. QUICKSORT(A, p, q-1)
4. QUICKSORT(A, q +1, r)
5. Exit
Blank
Recursive Algorithm(partition)
PARTITION(A, p, r)
1. x = A[r]
2. i = p-1
3. for j = p to r – 1
4. if A[j]<=x
5. i=i+1
6. exchange A[i]with A[j]
7. exchange A[i+1] with A[r]
8. return i + 1
Blank
Example:
Complexity of Quick sort
• Worst case
– O(n2)

• Average case
– O(n log n)

• Best case
– O(n log n)
Blank
Blank

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy