0% found this document useful (0 votes)
28 views11 pages

Stack (Quick Sort) and Recursion

Stack

Uploaded by

Rewash Chettri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views11 pages

Stack (Quick Sort) and Recursion

Stack

Uploaded by

Rewash Chettri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 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