SlideShare a Scribd company logo
3
Most read
Data Structure - Quick Sort
Quick sort is a highly efficient sorting algorithm and is based on partitioning
of array of data into smallerarrays. A large array is partitioned into two arrays
one of which holds values smaller than specified value say pivot based on
which the partition is made and another array holds values greater than pivot
value.
The quick sort partitions an array and then calls itself recursively twice to sort
the resulting two subarray. This algorithm is quite efficient for large sized
data sets as its average and worst case complexity are of O(nlogn) where n
are no. of items.
Partition in Quicksort
The below given animated representation explains how to find pivot value in
the array.
The pivot value divides the list in to two parts. And recursively we find pivot
for each sub-lists until all lists contains only one element.
QuickSort Pivot Algorithm
Based on our understanding of partitioning in quicksort, we should now try
to write an algorithm for it here.
Step 1 − Choose the highest index value has pivot
Step 2 − Take two variables to point left and right of the list excluding pivot
Step 3 − left points to the low index
Step 4 − right points to the high
Step 5 − while value at left is less than pivot move right
Step 6 − while value at right is greater than pivot move left
Step 7 − if both step 5 and step 6 does not match swap left and right
Step 8 − if left ≥ right, the point where they met is new pivot
QuickSort Pivot Pseudocode
The pseudocode for the above algorithm can be derived as −
function partitionFunc(left, right, pivot)
leftPointer = left -1
rightPointer = right
while True do
while A[++leftPointer] < pivot do
//do-nothing
end while
while rightPointer > 0 && A[--rightPointer] > pivot do
//do-nothing
end while
if leftPointer >= rightPointer
break
else
swap leftPointer,rightPointer
end if
end while
swap leftPointer,right
return leftPointer
end function
QuickSort Algorithm
Using pivot algorithm recursively we end-up with smaller possible partitions.
Each partition then processed for quick sort. We define recursive algorithm
for quicksort as below −
Step 1 − Make the right-most index value pivot
Step 2 − partition the array using pivot value
Step 3 − quicksort left partition recursively
Step 4 − quicksort right partition recursively
QuickSort Pseudocode
To get more into it, let see the pseudocode for quick sort algorithm −
procedure quickSort(left, right)
if right-left <= 0
return
else
pivot = A[right]
partition = partitionFunc(left, right, pivot)
quickSort(left,partition-1)
quickSort(partition+1,right)
end if
end procedure

More Related Content

PDF
Applications of stack
eShikshak
 
PPT
Bubble sort
Manek Ar
 
PPTX
Merge sort algorithm
Shubham Dwivedi
 
PPTX
FIFO, LRU, OPTIMAL Page Replacement Algorithm
ArijitRoy118
 
PPTX
Merge sort
Sindhoo Oad
 
PDF
DATA STRUCTURE AND ALGORITHM FULL NOTES
Aniruddha Paul
 
PPTX
Bubble sort | Data structure |
MdSaiful14
 
PPT
Merge sort
Vidushi Pathak
 
Applications of stack
eShikshak
 
Bubble sort
Manek Ar
 
Merge sort algorithm
Shubham Dwivedi
 
FIFO, LRU, OPTIMAL Page Replacement Algorithm
ArijitRoy118
 
Merge sort
Sindhoo Oad
 
DATA STRUCTURE AND ALGORITHM FULL NOTES
Aniruddha Paul
 
Bubble sort | Data structure |
MdSaiful14
 
Merge sort
Vidushi Pathak
 

What's hot (20)

PPTX
Queues
Ashim Lamichhane
 
PPTX
Queue in Data Structure
Janki Shah
 
PPTX
Bubble Sort Algorithm Presentation
AhmedAlbutty
 
PPTX
Page replacement
Davin Abraham
 
PPT
Graphs in Data Structure
hafsa komal
 
PPTX
Merge sort and quick sort
Shakila Mahjabin
 
PDF
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
PPT
Queue AS an ADT (Abstract Data Type)
Self-Employed
 
PPTX
Double Hashing.pptx
VikasNirgude2
 
PPT
Time complexity
Katang Isip
 
PDF
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
PPT
Complexity of Algorithm
Muhammad Muzammal
 
PPT
Unit 4 external sorting
DrkhanchanaR
 
PPTX
Spanning trees & applications
Tech_MX
 
PPTX
Data structure and its types
Navtar Sidhu Brar
 
PPT
Disk scheduling algorithms
Paresh Parmar
 
PPT
File organization and indexing
raveena sharma
 
PPTX
Data structure using c module 1
smruti sarangi
 
PPT
Queue Data Structure
Lovely Professional University
 
PPTX
Queue - Data Structure - Notes
Omprakash Chauhan
 
Queue in Data Structure
Janki Shah
 
Bubble Sort Algorithm Presentation
AhmedAlbutty
 
Page replacement
Davin Abraham
 
Graphs in Data Structure
hafsa komal
 
Merge sort and quick sort
Shakila Mahjabin
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
Queue AS an ADT (Abstract Data Type)
Self-Employed
 
Double Hashing.pptx
VikasNirgude2
 
Time complexity
Katang Isip
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
Complexity of Algorithm
Muhammad Muzammal
 
Unit 4 external sorting
DrkhanchanaR
 
Spanning trees & applications
Tech_MX
 
Data structure and its types
Navtar Sidhu Brar
 
Disk scheduling algorithms
Paresh Parmar
 
File organization and indexing
raveena sharma
 
Data structure using c module 1
smruti sarangi
 
Queue Data Structure
Lovely Professional University
 
Queue - Data Structure - Notes
Omprakash Chauhan
 
Ad

Similar to Quick sort (20)

PDF
Heap, quick and merge sort
Dr. Mohammad Amir Khusru Akhtar (Ph.D)
 
PPTX
Quick Sort in data structure.pptx
ujjwalmatoliya
 
PPTX
VCE Unit 04vv.pptx
skilljiolms
 
PPT
Algorithm designing using divide and conquer algorithms
SiddhantShelake
 
PPTX
Quick sort by Sania Nisar
Sania Nisar
 
PPT
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
PPTX
data structures and algorithms Unit 3
infanciaj
 
PPTX
Quick sort
amar kakde
 
PPTX
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
VISWANATHAN R V
 
PPTX
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
kncetaruna
 
PPTX
All Searching and Sorting Techniques in Data Structures
sonalishinge2015
 
PPTX
Sorting Algorithms to arrange data in particular format
itsusamazahid
 
PPTX
Sorting
FahadSaeed39
 
PPT
Quick sort data structures
chauhankapil
 
DOCX
Quick sort
Fabia Nayeem
 
PPTX
Power point presentation of Sorting Techniques
kowoxa9882
 
PPTX
Quick sort algorithm
AditiPawaskar5
 
PPTX
AJisthewewrtyuiojhghfdfsgvhjhklopi87ytrytfghjk
PradipTadme
 
PPT
Sorting algorithms in Data Structure
Balamurugan M
 
PPTX
Complexity of algorithms
Jasur Ahmadov
 
Heap, quick and merge sort
Dr. Mohammad Amir Khusru Akhtar (Ph.D)
 
Quick Sort in data structure.pptx
ujjwalmatoliya
 
VCE Unit 04vv.pptx
skilljiolms
 
Algorithm designing using divide and conquer algorithms
SiddhantShelake
 
Quick sort by Sania Nisar
Sania Nisar
 
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
data structures and algorithms Unit 3
infanciaj
 
Quick sort
amar kakde
 
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
VISWANATHAN R V
 
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
kncetaruna
 
All Searching and Sorting Techniques in Data Structures
sonalishinge2015
 
Sorting Algorithms to arrange data in particular format
itsusamazahid
 
Sorting
FahadSaeed39
 
Quick sort data structures
chauhankapil
 
Quick sort
Fabia Nayeem
 
Power point presentation of Sorting Techniques
kowoxa9882
 
Quick sort algorithm
AditiPawaskar5
 
AJisthewewrtyuiojhghfdfsgvhjhklopi87ytrytfghjk
PradipTadme
 
Sorting algorithms in Data Structure
Balamurugan M
 
Complexity of algorithms
Jasur Ahmadov
 
Ad

More from maamir farooq (20)

DOCX
Ooad lab1
maamir farooq
 
PPT
Lesson 03
maamir farooq
 
PPT
Lesson 02
maamir farooq
 
PDF
Php client libray
maamir farooq
 
PDF
Swiftmailer
maamir farooq
 
PDF
Lect15
maamir farooq
 
PDF
Lec 7
maamir farooq
 
PPTX
Lec 6
maamir farooq
 
PDF
Lec 5
maamir farooq
 
PDF
J query 1.7 cheat sheet
maamir farooq
 
PDF
Assignment
maamir farooq
 
PDF
Java script summary
maamir farooq
 
PDF
Lec 3
maamir farooq
 
PDF
Lec 2
maamir farooq
 
PPTX
Lec 1
maamir farooq
 
PPTX
Css summary
maamir farooq
 
DOCX
Manual of image processing lab
maamir farooq
 
PDF
Session management
maamir farooq
 
PDF
Data management
maamir farooq
 
PPTX
Content provider
maamir farooq
 
Ooad lab1
maamir farooq
 
Lesson 03
maamir farooq
 
Lesson 02
maamir farooq
 
Php client libray
maamir farooq
 
Swiftmailer
maamir farooq
 
J query 1.7 cheat sheet
maamir farooq
 
Assignment
maamir farooq
 
Java script summary
maamir farooq
 
Css summary
maamir farooq
 
Manual of image processing lab
maamir farooq
 
Session management
maamir farooq
 
Data management
maamir farooq
 
Content provider
maamir farooq
 

Recently uploaded (20)

PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
PPTX
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
PDF
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
Basics and rules of probability with real-life uses
ravatkaran694
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 

Quick sort

  • 1. Data Structure - Quick Sort Quick sort is a highly efficient sorting algorithm and is based on partitioning of array of data into smallerarrays. A large array is partitioned into two arrays one of which holds values smaller than specified value say pivot based on which the partition is made and another array holds values greater than pivot value. The quick sort partitions an array and then calls itself recursively twice to sort the resulting two subarray. This algorithm is quite efficient for large sized data sets as its average and worst case complexity are of O(nlogn) where n are no. of items. Partition in Quicksort The below given animated representation explains how to find pivot value in the array. The pivot value divides the list in to two parts. And recursively we find pivot for each sub-lists until all lists contains only one element. QuickSort Pivot Algorithm Based on our understanding of partitioning in quicksort, we should now try to write an algorithm for it here. Step 1 − Choose the highest index value has pivot Step 2 − Take two variables to point left and right of the list excluding pivot Step 3 − left points to the low index Step 4 − right points to the high
  • 2. Step 5 − while value at left is less than pivot move right Step 6 − while value at right is greater than pivot move left Step 7 − if both step 5 and step 6 does not match swap left and right Step 8 − if left ≥ right, the point where they met is new pivot QuickSort Pivot Pseudocode The pseudocode for the above algorithm can be derived as − function partitionFunc(left, right, pivot) leftPointer = left -1 rightPointer = right while True do while A[++leftPointer] < pivot do //do-nothing end while while rightPointer > 0 && A[--rightPointer] > pivot do //do-nothing end while if leftPointer >= rightPointer break else swap leftPointer,rightPointer end if end while swap leftPointer,right return leftPointer end function
  • 3. QuickSort Algorithm Using pivot algorithm recursively we end-up with smaller possible partitions. Each partition then processed for quick sort. We define recursive algorithm for quicksort as below − Step 1 − Make the right-most index value pivot Step 2 − partition the array using pivot value Step 3 − quicksort left partition recursively Step 4 − quicksort right partition recursively QuickSort Pseudocode To get more into it, let see the pseudocode for quick sort algorithm − procedure quickSort(left, right) if right-left <= 0 return else pivot = A[right] partition = partitionFunc(left, right, pivot) quickSort(left,partition-1) quickSort(partition+1,right) end if end procedure