SlideShare a Scribd company logo
Quick Sort
Using
Divide And Conquer
Algorithm
Name : Mrunal Sanjay Patil
Roll No : FYMCA2064
What is Quick Sort ?
 Ranking manner Quick Sort is the most widely used of all the other sorting
algorithms because they are faster and consume less memory.
 Fastest known sorting algorithm in practice
 Quick sort is a highly efficient sorting algorithm and is based on partitioning of
array of data into smaller arrays.
 A large array is partitioned into two arrays one of which holds
values smaller than the specified value, say pivot, based on which the
partition is made and another array holds values greater than
the pivot value.
Divide and Conquer
Divide :
Divide the problem into a number of sub-problems
Similar sub-problems of smaller size
Conquer :
Conquer the sub-problems Solve the sub-problems
recursively.
Sub-problem size small enough  solve the problems in
straightforward manner
Combine :
Combine the solutions of the sub-problems
Obtain the solution for the original problem
How we use divide and conquer algorithm for
Quicksort
 Sort an array A[p…r]
 Divide
Partition the array A into 2 subarrays A[p..q] and A[q+1..r], such that each element of
A[p..q] is smaller than or equal to each element in A[q+1..r]
Need to find index q to partition the array
≤
 Conquer
Recursively sort A[p..q] and A[q+1..r] using Quicksort.
First sort A[p..q] and then sort A[q+1..r] individually.
 Combine
Trivial: the arrays are sorted in place
No additional work is required to combine them.
The entire array is now sorted.
≤
Basic idea (The first step towards sorting the
elements)
 Pick some number as pivot from the array
 Move all numbers less than pivot to the beginning of the array
 Move all numbers greater than (or equal to) pivot to the end of the array
 Quicksort the numbers less than pivot
 Quicksort the numbers greater than or equal to pivot
pivot
pivot
numbers less than pivot numbers greater than or equal to
Example
41 62 13 84 35 96
Pivot = 41 i j
35
84
13
62
41
If i > j then swap i and j Else j--
96
35
84
13
62
41
i j
41 > 35 = true
35
84
13
62
41
i j
swap 41 and 35
96
96
Unsorted array of 6 elements
41 > 96 = false then j--
i j
41
84
13
62
35 96
Pivot = j = 41 do i++
i j
62 > 41 = true
j
41
84
13
i
62
swap 41 and 62
j
62
84
13
i
41
Pivot = i = 41 do j--
35 35 96
41
84
13
62 84
62
35 96
96
41 > 84 = false do j-- 41 > 13 = True
j
13
i
41 62
84
35
j
84
13
i
41 62
35 96
swap 41 and 13 Pivot = j = 41 do
96
j
41
i
13 62
84
35 96
j
13
i
41 62
84
35 96
i = j
41
13
35
a[0] a[1] a[2] a[3] a[4] a[5]
numbers less than
pivot
numbers greater than or
equal to pivot
Now we sort numbers less than pivot
13
35
41 62
84 96
62
84 96
j
41
i
13 62
84
35 96
13 41 62
84 96
Pivot = 35
j
i
35
35 > 13 = true
Left side Array sorted
Now, we sort numbers greater than
35 41 62
84
13 96
13 41 62
84
j
i
35 96
swap 35 and 13
35 41
13
Pivot = 84
84 > 62 = True
35 41
13
swap 84 and 62
Both Sub-Arrays are
sorted
62
35 41
13
j
i
84
84 > 96 = false
do j--
96 62
j
i
84 96
62
84 96
35 41 84
13 62 96
 Algorithm
 Program
Quick Sort Space Complexity
 Basic approach : O(n)
 Modified approach : O(logn)
Quick Sort Time Complexity
 Best Time Complexity : O(nlogn)
 Average Time Complexity : O(nlogn)
 Worst Time Complexity : O(n^2)
The amount of computer time needs to run to completion.
The amount of computer space (memory) needs to
run to completion.
Divide-and-conquer

More Related Content

What's hot

Data Structure Sorting
Data Structure SortingData Structure Sorting
Data Structure Sorting
Muhazzab Chouhadry
 
Systems of linear equations and augmented matrices
Systems of linear equations and augmented matricesSystems of linear equations and augmented matrices
Systems of linear equations and augmented matricesST ZULAIHA NURHAJARURAHMAH
 
Gauss Jordan
Gauss JordanGauss Jordan
Gauss Jordan
Ezzat Gul
 
Sorting
SortingSorting
Sorting
Gopi Saiteja
 
(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sortingFadhil Ismail
 
Quick sort
Quick sortQuick sort
Quick sort
Jehat Hassan
 
Lecture 6.1 6.2 bt
Lecture 6.1 6.2 btLecture 6.1 6.2 bt
Lecture 6.1 6.2 bt
btmathematics
 
System of linear equations
System of linear equationsSystem of linear equations
System of linear equations
Diler4
 
Ma3bfet par 10.6 5 aug 2014
Ma3bfet par 10.6 5 aug 2014Ma3bfet par 10.6 5 aug 2014
Ma3bfet par 10.6 5 aug 2014
Celumusa Godfrey Nkosi
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
Trupti Agrawal
 
3.8 quick sort
3.8 quick sort3.8 quick sort
3.8 quick sort
Krish_ver2
 
Crout s method for solving system of linear equations
Crout s method for solving system of linear equationsCrout s method for solving system of linear equations
Crout s method for solving system of linear equations
Sugathan Velloth
 
9.4 Cramer's Rule
9.4 Cramer's Rule9.4 Cramer's Rule
9.4 Cramer's Rule
smiller5
 
BSC_COMPUTER _SCIENCE_UNIT-4_DISCRETE MATHEMATICS
BSC_COMPUTER _SCIENCE_UNIT-4_DISCRETE MATHEMATICSBSC_COMPUTER _SCIENCE_UNIT-4_DISCRETE MATHEMATICS
BSC_COMPUTER _SCIENCE_UNIT-4_DISCRETE MATHEMATICS
Rai University
 
Merge Sort
Merge SortMerge Sort
Merge Sort
Nikhil Sonkamble
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
Eleonora Ciceri
 
Mergesort
MergesortMergesort
Mergesort
luzenith_g
 
Matrix by suman sir
Matrix by suman sirMatrix by suman sir
Matrix by suman sir
sumandandal
 

What's hot (20)

Data Structure Sorting
Data Structure SortingData Structure Sorting
Data Structure Sorting
 
Systems of linear equations and augmented matrices
Systems of linear equations and augmented matricesSystems of linear equations and augmented matrices
Systems of linear equations and augmented matrices
 
Gauss Jordan
Gauss JordanGauss Jordan
Gauss Jordan
 
Sorting
SortingSorting
Sorting
 
(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting
 
Quick sort
Quick sortQuick sort
Quick sort
 
Lecture 6.1 6.2 bt
Lecture 6.1 6.2 btLecture 6.1 6.2 bt
Lecture 6.1 6.2 bt
 
System of linear equations
System of linear equationsSystem of linear equations
System of linear equations
 
Ma3bfet par 10.6 5 aug 2014
Ma3bfet par 10.6 5 aug 2014Ma3bfet par 10.6 5 aug 2014
Ma3bfet par 10.6 5 aug 2014
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
3.8 quick sort
3.8 quick sort3.8 quick sort
3.8 quick sort
 
Crout s method for solving system of linear equations
Crout s method for solving system of linear equationsCrout s method for solving system of linear equations
Crout s method for solving system of linear equations
 
Quicksort
QuicksortQuicksort
Quicksort
 
9.4 Cramer's Rule
9.4 Cramer's Rule9.4 Cramer's Rule
9.4 Cramer's Rule
 
BSC_COMPUTER _SCIENCE_UNIT-4_DISCRETE MATHEMATICS
BSC_COMPUTER _SCIENCE_UNIT-4_DISCRETE MATHEMATICSBSC_COMPUTER _SCIENCE_UNIT-4_DISCRETE MATHEMATICS
BSC_COMPUTER _SCIENCE_UNIT-4_DISCRETE MATHEMATICS
 
Merge Sort
Merge SortMerge Sort
Merge Sort
 
Gauss jordan
Gauss jordanGauss jordan
Gauss jordan
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Mergesort
MergesortMergesort
Mergesort
 
Matrix by suman sir
Matrix by suman sirMatrix by suman sir
Matrix by suman sir
 

Similar to Divide-and-conquer

Quick sort
Quick sortQuick sort
Quick sort
Uma mohan
 
Rational equation ex
Rational equation exRational equation ex
Rational equation ex
Lourenzo Gabrielle Manimtim
 
Class13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdfClass13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdf
AkashSingh625550
 
Sorting
SortingSorting
Quick sort
Quick sortQuick sort
Quick sort
Afaq Mansoor Khan
 
Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingChapter 11 - Sorting and Searching
Chapter 11 - Sorting and Searching
Eduardo Bergavera
 
quick sort by deepak.pptx
quick sort by deepak.pptxquick sort by deepak.pptx
quick sort by deepak.pptx
DeepakM509554
 
Sortings .pptx
Sortings .pptxSortings .pptx
Sortings .pptx
MuhammadSheraz836877
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
pppepito86
 
Quick sort.pptx
Quick sort.pptxQuick sort.pptx
Quick sort.pptx
Anbarasan Radhakrishnan R
 
s4_quick_sort.ppt
s4_quick_sort.ppts4_quick_sort.ppt
s4_quick_sort.ppt
AliAhmad38278
 
DIVIDE AND CONQUERMETHOD IN DATASTRUCTURE.pptx
DIVIDE AND CONQUERMETHOD IN DATASTRUCTURE.pptxDIVIDE AND CONQUERMETHOD IN DATASTRUCTURE.pptx
DIVIDE AND CONQUERMETHOD IN DATASTRUCTURE.pptx
LakshmiSamivel
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Muhammad Sarfraz
 
LeetCode Solutions In Java .pdf
LeetCode Solutions In Java .pdfLeetCode Solutions In Java .pdf
LeetCode Solutions In Java .pdf
zupsezekno
 
Sorting ppt
Sorting pptSorting ppt
Sorting ppt
Hassan Mustafa
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
Dr.Umadevi V
 
CSE680-07QuickSort.pptx
CSE680-07QuickSort.pptxCSE680-07QuickSort.pptx
CSE680-07QuickSort.pptx
DeepakM509554
 
Bs,qs,divide and conquer 1
Bs,qs,divide and conquer 1Bs,qs,divide and conquer 1
Bs,qs,divide and conquer 1
subhashchandra197
 
Sorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - NotesSorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - Notes
Omprakash Chauhan
 
Quick sort
Quick sortQuick sort

Similar to Divide-and-conquer (20)

Quick sort
Quick sortQuick sort
Quick sort
 
Rational equation ex
Rational equation exRational equation ex
Rational equation ex
 
Class13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdfClass13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdf
 
Sorting
SortingSorting
Sorting
 
Quick sort
Quick sortQuick sort
Quick sort
 
Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingChapter 11 - Sorting and Searching
Chapter 11 - Sorting and Searching
 
quick sort by deepak.pptx
quick sort by deepak.pptxquick sort by deepak.pptx
quick sort by deepak.pptx
 
Sortings .pptx
Sortings .pptxSortings .pptx
Sortings .pptx
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
Quick sort.pptx
Quick sort.pptxQuick sort.pptx
Quick sort.pptx
 
s4_quick_sort.ppt
s4_quick_sort.ppts4_quick_sort.ppt
s4_quick_sort.ppt
 
DIVIDE AND CONQUERMETHOD IN DATASTRUCTURE.pptx
DIVIDE AND CONQUERMETHOD IN DATASTRUCTURE.pptxDIVIDE AND CONQUERMETHOD IN DATASTRUCTURE.pptx
DIVIDE AND CONQUERMETHOD IN DATASTRUCTURE.pptx
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
LeetCode Solutions In Java .pdf
LeetCode Solutions In Java .pdfLeetCode Solutions In Java .pdf
LeetCode Solutions In Java .pdf
 
Sorting ppt
Sorting pptSorting ppt
Sorting ppt
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
 
CSE680-07QuickSort.pptx
CSE680-07QuickSort.pptxCSE680-07QuickSort.pptx
CSE680-07QuickSort.pptx
 
Bs,qs,divide and conquer 1
Bs,qs,divide and conquer 1Bs,qs,divide and conquer 1
Bs,qs,divide and conquer 1
 
Sorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - NotesSorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - Notes
 
Quick sort
Quick sortQuick sort
Quick sort
 

Recently uploaded

Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
An Approach to Detecting Writing Styles Based on Clustering Techniques
An Approach to Detecting Writing Styles Based on Clustering TechniquesAn Approach to Detecting Writing Styles Based on Clustering Techniques
An Approach to Detecting Writing Styles Based on Clustering Techniques
ambekarshweta25
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
dxobcob
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABSDESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
itech2017
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 

Recently uploaded (20)

Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
An Approach to Detecting Writing Styles Based on Clustering Techniques
An Approach to Detecting Writing Styles Based on Clustering TechniquesAn Approach to Detecting Writing Styles Based on Clustering Techniques
An Approach to Detecting Writing Styles Based on Clustering Techniques
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABSDESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 

Divide-and-conquer

  • 1. Quick Sort Using Divide And Conquer Algorithm Name : Mrunal Sanjay Patil Roll No : FYMCA2064
  • 2. What is Quick Sort ?  Ranking manner Quick Sort is the most widely used of all the other sorting algorithms because they are faster and consume less memory.  Fastest known sorting algorithm in practice  Quick sort is a highly efficient sorting algorithm and is based on partitioning of array of data into smaller arrays.  A large array is partitioned into two arrays one of which holds values smaller than the specified value, say pivot, based on which the partition is made and another array holds values greater than the pivot value.
  • 3. Divide and Conquer Divide : Divide the problem into a number of sub-problems Similar sub-problems of smaller size Conquer : Conquer the sub-problems Solve the sub-problems recursively. Sub-problem size small enough  solve the problems in straightforward manner Combine : Combine the solutions of the sub-problems Obtain the solution for the original problem
  • 4. How we use divide and conquer algorithm for Quicksort  Sort an array A[p…r]  Divide Partition the array A into 2 subarrays A[p..q] and A[q+1..r], such that each element of A[p..q] is smaller than or equal to each element in A[q+1..r] Need to find index q to partition the array ≤
  • 5.  Conquer Recursively sort A[p..q] and A[q+1..r] using Quicksort. First sort A[p..q] and then sort A[q+1..r] individually.  Combine Trivial: the arrays are sorted in place No additional work is required to combine them. The entire array is now sorted. ≤
  • 6. Basic idea (The first step towards sorting the elements)  Pick some number as pivot from the array  Move all numbers less than pivot to the beginning of the array  Move all numbers greater than (or equal to) pivot to the end of the array  Quicksort the numbers less than pivot  Quicksort the numbers greater than or equal to pivot pivot pivot numbers less than pivot numbers greater than or equal to
  • 7. Example 41 62 13 84 35 96 Pivot = 41 i j 35 84 13 62 41 If i > j then swap i and j Else j-- 96 35 84 13 62 41 i j 41 > 35 = true 35 84 13 62 41 i j swap 41 and 35 96 96 Unsorted array of 6 elements 41 > 96 = false then j--
  • 8. i j 41 84 13 62 35 96 Pivot = j = 41 do i++ i j 62 > 41 = true j 41 84 13 i 62 swap 41 and 62 j 62 84 13 i 41 Pivot = i = 41 do j-- 35 35 96 41 84 13 62 84 62 35 96 96
  • 9. 41 > 84 = false do j-- 41 > 13 = True j 13 i 41 62 84 35 j 84 13 i 41 62 35 96 swap 41 and 13 Pivot = j = 41 do 96 j 41 i 13 62 84 35 96 j 13 i 41 62 84 35 96
  • 10. i = j 41 13 35 a[0] a[1] a[2] a[3] a[4] a[5] numbers less than pivot numbers greater than or equal to pivot Now we sort numbers less than pivot 13 35 41 62 84 96 62 84 96 j 41 i 13 62 84 35 96
  • 11. 13 41 62 84 96 Pivot = 35 j i 35 35 > 13 = true Left side Array sorted Now, we sort numbers greater than 35 41 62 84 13 96 13 41 62 84 j i 35 96 swap 35 and 13
  • 12. 35 41 13 Pivot = 84 84 > 62 = True 35 41 13 swap 84 and 62 Both Sub-Arrays are sorted 62 35 41 13 j i 84 84 > 96 = false do j-- 96 62 j i 84 96 62 84 96 35 41 84 13 62 96
  • 15. Quick Sort Space Complexity  Basic approach : O(n)  Modified approach : O(logn) Quick Sort Time Complexity  Best Time Complexity : O(nlogn)  Average Time Complexity : O(nlogn)  Worst Time Complexity : O(n^2) The amount of computer time needs to run to completion. The amount of computer space (memory) needs to run to completion.