SlideShare a Scribd company logo
By- Sumita Das
Presentation On Binary Search, Quick
Sort, Merge Sort And Problems
Created by Sumita Das
Binary Search
• If we have an ordered list and we know how
many things are in the list (i.e., number of records
in a file), we can use a different strategy.
• The binary search gets its name because the
algorithm continually divides the list into two
parts.
Created by Sumita Das
How a Binary Search Works
Always look at the center
value. Each time you get to
discard half of the remaining
list.
Created by Sumita Das
Initialize
FailureGet Midpoint
High < Low
< >Compare
Adjust High Adjust Low
Success=
Created by Sumita Das
Algorithm:
Low= 1; High = n;
while Low < High {
m = floor( (Low+High)/2 );
if k <= A[m]
then High = m - 1
else Low = m + 1
}
if A[Low] = k then j = Low else j = 0
Created by Sumita Das
•Similar to merge sort - divide-and-
conquer recursive algorithm
•One of the fastest sorting algorithms
•Average running time O(NlogN)
•Worst-case running time O(N2
)
Quick sort
Created by Sumita Das
Basic idea
1.Pick one element in the array, which will be
the pivot.
2.Make one pass through the array, called a
partition step, re-arranging the entries so that:
•the pivot is in its proper place.
•entries smaller than the pivot are to the left
of the pivot.
•entries larger than the pivot are to its right.
Created by Sumita Das
3.Recursively apply quick sort to the part
of the array that is to the left of the pivot,
and to the right part of the array.
Note:
Here we don't have the merge step, at
the end all the elements are in the proper
order.
Created by Sumita Das
Algorithm:
• Input: Array E and indices first, and last, s.t. elements
E[i] are defined for first ≤ i ≤ last
• Ouput: E[first], …, E[last] is a sorted rearrangement of
the array
• Void quickSort(Element[] E, int first, int last)
if (first < last)
Element pivotElement = E[first];
int splitPoint = partition(E, pivotElement, first,
last);
quickSort (E, first, splitPoint –1 );
quickSort (E, splitPoint +1, last );
return;
Created by Sumita Das
Merge Sort
• Uses recursion. Slightly faster than heap, but uses
twice as much memory from the 2nd
array.
• Sometimes called “divide and conquer” sort.
• Works by recursively splitting an array into two
equal halves, sorting the items, then re-merging
them back into a new array.
Created by Sumita Das
Algorithm:
• Split array A[1..n] in two and make copies of each half in
arrays B[1.. n/2 ] and C[1.. n/2 ]
• sort arrays B and C
• Merge sorted arrays B and C into array A
Created by Sumita Das
Using Divide and Conquer: Merge Sort
• Merge Sort Strategy
Sorted
Merge
Sorted Sorted
Sort recursively
by Mergesort
Sort recursively
by Mergesort
first last
(first + last)/2
Created by Sumita Das
Example : Binary Searching
14?
14?
Created by Sumita Das
Binary Searching
14
Created by Sumita Das
Example : Quick sort
Created by Sumita Das
Example : Merge Sort
– n Power of 2
1 2 3 4 5 6 7 8
q = 462317425
1 2 3 4
7425
5 6 7 8
6231
1 2
25
3 4
74
5 6
31
7 8
62
1
5
2
2
3
4
4
7 1
6
3
7
2
8
6
5
Divide
Example – n Power of 2
1
5
2
2
3
4
4
7 1
6
3
7
2
8
6
5
1 2 3 4 5 6 7 8
76543221
1 2 3 4
7542
5 6 7 8
6321
1 2
52
3 4
74
5 6
31
7 8
62
Conquer
and
Merge
Example – n Not a Power of 2
62537416274
1 2 3 4 5 6 7 8 9 10 11
q = 6
416274
1 2 3 4 5 6
62537
7 8 9 10 11
q = 9q = 3
274
1 2 3
416
4 5 6
537
7 8 9
62
10 11
74
1 2
2
3
16
4 5
4
6
37
7 8
5
9
2
10
6
11
4
1
7
2
6
4
1
5
7
7
3
8
Divide
Example – n Not a Power of 2
77665443221
1 2 3 4 5 6 7 8 9 10 11
764421
1 2 3 4 5 6
76532
7 8 9 10 11
742
1 2 3
641
4 5 6
753
7 8 9
62
10 11
2
3
4
6
5
9
2
10
6
11
4
1
7
2
6
4
1
5
7
7
3
8
74
1 2
61
4 5
73
7 8
Conquer
and
Merge
References
[1]Introduction to Algorithms 2nd ,Cormen, Leiserson, Rivest and
Stein, The MIT Press, 2001.
Thank you….
Created by Sumita Das
Ad

More Related Content

What's hot (20)

Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
Waqar Akram
 
Regular Languages
Regular LanguagesRegular Languages
Regular Languages
parmeet834
 
Quick sort
Quick sortQuick sort
Quick sort
Jehat Hassan
 
Merge sort
Merge sortMerge sort
Merge sort
Vidushi Pathak
 
Recursive Descent Parsing
Recursive Descent Parsing  Recursive Descent Parsing
Recursive Descent Parsing
Md Tajul Islam
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
Amrinder Arora
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph Algorithms
Mohamed Loey
 
Quicksort Presentation
Quicksort PresentationQuicksort Presentation
Quicksort Presentation
irdginfo
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
hodcsencet
 
Algorithms Lecture 8: Pattern Algorithms
Algorithms Lecture 8: Pattern AlgorithmsAlgorithms Lecture 8: Pattern Algorithms
Algorithms Lecture 8: Pattern Algorithms
Mohamed Loey
 
Hash table
Hash tableHash table
Hash table
Rajendran
 
Merge sort algorithm
Merge sort algorithmMerge sort algorithm
Merge sort algorithm
Shubham Dwivedi
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
sumitbardhan
 
Merge sort
Merge sortMerge sort
Merge sort
Rojin Khadka
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Dr Shashikant Athawale
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
Saga Valsalan
 
3.8 quicksort
3.8 quicksort3.8 quicksort
3.8 quicksort
Krish_ver2
 
Unit I - Evaluation of expression
Unit I - Evaluation of expressionUnit I - Evaluation of expression
Unit I - Evaluation of expression
DrkhanchanaR
 
Best,worst,average case .17581556 045
Best,worst,average case .17581556 045Best,worst,average case .17581556 045
Best,worst,average case .17581556 045
university of Gujrat, pakistan
 
Master method
Master method Master method
Master method
Rajendran
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
Waqar Akram
 
Regular Languages
Regular LanguagesRegular Languages
Regular Languages
parmeet834
 
Recursive Descent Parsing
Recursive Descent Parsing  Recursive Descent Parsing
Recursive Descent Parsing
Md Tajul Islam
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
Amrinder Arora
 
Algorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph AlgorithmsAlgorithms Lecture 7: Graph Algorithms
Algorithms Lecture 7: Graph Algorithms
Mohamed Loey
 
Quicksort Presentation
Quicksort PresentationQuicksort Presentation
Quicksort Presentation
irdginfo
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
hodcsencet
 
Algorithms Lecture 8: Pattern Algorithms
Algorithms Lecture 8: Pattern AlgorithmsAlgorithms Lecture 8: Pattern Algorithms
Algorithms Lecture 8: Pattern Algorithms
Mohamed Loey
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
sumitbardhan
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
Saga Valsalan
 
Unit I - Evaluation of expression
Unit I - Evaluation of expressionUnit I - Evaluation of expression
Unit I - Evaluation of expression
DrkhanchanaR
 
Master method
Master method Master method
Master method
Rajendran
 

Viewers also liked (20)

Merge sort and quick sort
Merge sort and quick sortMerge sort and quick sort
Merge sort and quick sort
Shakila Mahjabin
 
Quick Sort , Merge Sort , Heap Sort
Quick Sort , Merge Sort ,  Heap SortQuick Sort , Merge Sort ,  Heap Sort
Quick Sort , Merge Sort , Heap Sort
Mohammed Hussein
 
Meaghan technology report
Meaghan technology reportMeaghan technology report
Meaghan technology report
Marq2014
 
Im260 presentation
Im260 presentationIm260 presentation
Im260 presentation
mojo0402
 
eCommerce Report 2016
eCommerce Report 2016eCommerce Report 2016
eCommerce Report 2016
eCommerce Institute
 
Difference b/w LED and LCD
Difference b/w LED and LCD Difference b/w LED and LCD
Difference b/w LED and LCD
Infant Gopinath
 
Digital marketing overview bl
Digital marketing overview blDigital marketing overview bl
Digital marketing overview bl
Manish Chaudhary
 
Quick sort-Data Structure
Quick sort-Data StructureQuick sort-Data Structure
Quick sort-Data Structure
Jeanie Arnoco
 
Ecommerce
EcommerceEcommerce
Ecommerce
Syed Ahmed
 
Binary search
Binary searchBinary search
Binary search
Gaurav Solanki
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
NeoClassical
 
Top 10 inventions that changed the world (elenka maam)
Top 10 inventions that changed the world (elenka maam)Top 10 inventions that changed the world (elenka maam)
Top 10 inventions that changed the world (elenka maam)
sheldon pereira
 
Internet banking - College Project
Internet banking - College ProjectInternet banking - College Project
Internet banking - College Project
Sheril Daniel
 
Quick Sort
Quick SortQuick Sort
Quick Sort
priyankanaidu6
 
Newspaper vs internet
Newspaper vs internetNewspaper vs internet
Newspaper vs internet
Thinesh Pergas
 
Co education
Co educationCo education
Co education
Shahzad Gul
 
Coeducation
CoeducationCoeducation
Coeducation
skmaken
 
Social Network Analysis
Social Network AnalysisSocial Network Analysis
Social Network Analysis
Giorgos Cheliotis
 
Ecommerce final ppt
Ecommerce final pptEcommerce final ppt
Ecommerce final ppt
reemalmarri
 
Newspapers vs internet news
Newspapers vs internet newsNewspapers vs internet news
Newspapers vs internet news
greatnewsupdate
 
Quick Sort , Merge Sort , Heap Sort
Quick Sort , Merge Sort ,  Heap SortQuick Sort , Merge Sort ,  Heap Sort
Quick Sort , Merge Sort , Heap Sort
Mohammed Hussein
 
Meaghan technology report
Meaghan technology reportMeaghan technology report
Meaghan technology report
Marq2014
 
Im260 presentation
Im260 presentationIm260 presentation
Im260 presentation
mojo0402
 
Difference b/w LED and LCD
Difference b/w LED and LCD Difference b/w LED and LCD
Difference b/w LED and LCD
Infant Gopinath
 
Digital marketing overview bl
Digital marketing overview blDigital marketing overview bl
Digital marketing overview bl
Manish Chaudhary
 
Quick sort-Data Structure
Quick sort-Data StructureQuick sort-Data Structure
Quick sort-Data Structure
Jeanie Arnoco
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
NeoClassical
 
Top 10 inventions that changed the world (elenka maam)
Top 10 inventions that changed the world (elenka maam)Top 10 inventions that changed the world (elenka maam)
Top 10 inventions that changed the world (elenka maam)
sheldon pereira
 
Internet banking - College Project
Internet banking - College ProjectInternet banking - College Project
Internet banking - College Project
Sheril Daniel
 
Coeducation
CoeducationCoeducation
Coeducation
skmaken
 
Ecommerce final ppt
Ecommerce final pptEcommerce final ppt
Ecommerce final ppt
reemalmarri
 
Newspapers vs internet news
Newspapers vs internet newsNewspapers vs internet news
Newspapers vs internet news
greatnewsupdate
 
Ad

Similar to Presentation on binary search, quick sort, merge sort and problems (20)

Class13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdfClass13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdf
AkashSingh625550
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
Dr.Umadevi V
 
quick sort by deepak.pptx
quick sort by deepak.pptxquick sort by deepak.pptx
quick sort by deepak.pptx
DeepakM509554
 
Parallel Sorting Algorithms. Quicksort. Merge sort. List Ranking
Parallel Sorting Algorithms. Quicksort. Merge sort. List RankingParallel Sorting Algorithms. Quicksort. Merge sort. List Ranking
Parallel Sorting Algorithms. Quicksort. Merge sort. List Ranking
SukhrobAtoev2
 
Data analysis and algorithms - UNIT 2.pptx
Data analysis and algorithms - UNIT 2.pptxData analysis and algorithms - UNIT 2.pptx
Data analysis and algorithms - UNIT 2.pptx
sgrishma559
 
Tri Merge Sorting Algorithm
Tri Merge Sorting AlgorithmTri Merge Sorting Algorithm
Tri Merge Sorting Algorithm
Ashim Sikder
 
3.8 quick sort
3.8 quick sort3.8 quick sort
3.8 quick sort
Krish_ver2
 
Sorting
SortingSorting
Sorting
invertis university
 
SORT AND SEARCH ARRAY WITH WITH C++.pptx
SORT AND SEARCH ARRAY WITH WITH C++.pptxSORT AND SEARCH ARRAY WITH WITH C++.pptx
SORT AND SEARCH ARRAY WITH WITH C++.pptx
narifmsit18seecs
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
Pranay Neema
 
Algorithms and Data Structures - Parahyangan Catholic University Credit Lionov
Algorithms and Data Structures - Parahyangan Catholic University Credit LionovAlgorithms and Data Structures - Parahyangan Catholic University Credit Lionov
Algorithms and Data Structures - Parahyangan Catholic University Credit Lionov
Pratik Parmar
 
Algorithms Analysis & Design - Lecture 8
Algorithms Analysis & Design - Lecture 8Algorithms Analysis & Design - Lecture 8
Algorithms Analysis & Design - Lecture 8
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
Data Structure and algorithms for software
Data Structure and algorithms for softwareData Structure and algorithms for software
Data Structure and algorithms for software
ManishShukla712917
 
Quick-Sort Algorithm and pivot selection
Quick-Sort Algorithm and pivot selectionQuick-Sort Algorithm and pivot selection
Quick-Sort Algorithm and pivot selection
SubhranjaliBehera
 
Lec 6 Divide and conquer of Data Structures & Algortihms
Lec 6 Divide and conquer of Data Structures & AlgortihmsLec 6 Divide and conquer of Data Structures & Algortihms
Lec 6 Divide and conquer of Data Structures & Algortihms
haseebanjum2611
 
Sorting algorithms bubble sort to merge sort.pdf
Sorting  algorithms bubble sort to merge sort.pdfSorting  algorithms bubble sort to merge sort.pdf
Sorting algorithms bubble sort to merge sort.pdf
AyeshaMazhar21
 
Unit III Version I.pptx
Unit III Version I.pptxUnit III Version I.pptx
Unit III Version I.pptx
ssuserd602fd
 
9.Sorting & Searching
9.Sorting & Searching9.Sorting & Searching
9.Sorting & Searching
Mandeep Singh
 
Data Structures & Algorithms - Lecture 1
Data Structures & Algorithms - Lecture 1Data Structures & Algorithms - Lecture 1
Data Structures & Algorithms - Lecture 1
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptx
VarchasvaTiwari2
 
Class13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdfClass13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdf
AkashSingh625550
 
quick sort by deepak.pptx
quick sort by deepak.pptxquick sort by deepak.pptx
quick sort by deepak.pptx
DeepakM509554
 
Parallel Sorting Algorithms. Quicksort. Merge sort. List Ranking
Parallel Sorting Algorithms. Quicksort. Merge sort. List RankingParallel Sorting Algorithms. Quicksort. Merge sort. List Ranking
Parallel Sorting Algorithms. Quicksort. Merge sort. List Ranking
SukhrobAtoev2
 
Data analysis and algorithms - UNIT 2.pptx
Data analysis and algorithms - UNIT 2.pptxData analysis and algorithms - UNIT 2.pptx
Data analysis and algorithms - UNIT 2.pptx
sgrishma559
 
Tri Merge Sorting Algorithm
Tri Merge Sorting AlgorithmTri Merge Sorting Algorithm
Tri Merge Sorting Algorithm
Ashim Sikder
 
3.8 quick sort
3.8 quick sort3.8 quick sort
3.8 quick sort
Krish_ver2
 
SORT AND SEARCH ARRAY WITH WITH C++.pptx
SORT AND SEARCH ARRAY WITH WITH C++.pptxSORT AND SEARCH ARRAY WITH WITH C++.pptx
SORT AND SEARCH ARRAY WITH WITH C++.pptx
narifmsit18seecs
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
Pranay Neema
 
Algorithms and Data Structures - Parahyangan Catholic University Credit Lionov
Algorithms and Data Structures - Parahyangan Catholic University Credit LionovAlgorithms and Data Structures - Parahyangan Catholic University Credit Lionov
Algorithms and Data Structures - Parahyangan Catholic University Credit Lionov
Pratik Parmar
 
Data Structure and algorithms for software
Data Structure and algorithms for softwareData Structure and algorithms for software
Data Structure and algorithms for software
ManishShukla712917
 
Quick-Sort Algorithm and pivot selection
Quick-Sort Algorithm and pivot selectionQuick-Sort Algorithm and pivot selection
Quick-Sort Algorithm and pivot selection
SubhranjaliBehera
 
Lec 6 Divide and conquer of Data Structures & Algortihms
Lec 6 Divide and conquer of Data Structures & AlgortihmsLec 6 Divide and conquer of Data Structures & Algortihms
Lec 6 Divide and conquer of Data Structures & Algortihms
haseebanjum2611
 
Sorting algorithms bubble sort to merge sort.pdf
Sorting  algorithms bubble sort to merge sort.pdfSorting  algorithms bubble sort to merge sort.pdf
Sorting algorithms bubble sort to merge sort.pdf
AyeshaMazhar21
 
Unit III Version I.pptx
Unit III Version I.pptxUnit III Version I.pptx
Unit III Version I.pptx
ssuserd602fd
 
9.Sorting & Searching
9.Sorting & Searching9.Sorting & Searching
9.Sorting & Searching
Mandeep Singh
 
Ad

More from Sumita Das (10)

Numerical on bisection method
Numerical on bisection methodNumerical on bisection method
Numerical on bisection method
Sumita Das
 
Numerical on dichotomous search
Numerical on dichotomous searchNumerical on dichotomous search
Numerical on dichotomous search
Sumita Das
 
Loop alignment
Loop alignmentLoop alignment
Loop alignment
Sumita Das
 
Maps in android
Maps in androidMaps in android
Maps in android
Sumita Das
 
Hardware and software parallelism
Hardware and software parallelismHardware and software parallelism
Hardware and software parallelism
Sumita Das
 
Trusted systems1
Trusted systems1Trusted systems1
Trusted systems1
Sumita Das
 
Activity selection problem
Activity selection problemActivity selection problem
Activity selection problem
Sumita Das
 
Multiprotocol label switching
Multiprotocol label switchingMultiprotocol label switching
Multiprotocol label switching
Sumita Das
 
Asymptotic analysis of parallel programs
Asymptotic analysis of parallel programsAsymptotic analysis of parallel programs
Asymptotic analysis of parallel programs
Sumita Das
 
Distributed systems1
Distributed systems1Distributed systems1
Distributed systems1
Sumita Das
 
Numerical on bisection method
Numerical on bisection methodNumerical on bisection method
Numerical on bisection method
Sumita Das
 
Numerical on dichotomous search
Numerical on dichotomous searchNumerical on dichotomous search
Numerical on dichotomous search
Sumita Das
 
Loop alignment
Loop alignmentLoop alignment
Loop alignment
Sumita Das
 
Maps in android
Maps in androidMaps in android
Maps in android
Sumita Das
 
Hardware and software parallelism
Hardware and software parallelismHardware and software parallelism
Hardware and software parallelism
Sumita Das
 
Trusted systems1
Trusted systems1Trusted systems1
Trusted systems1
Sumita Das
 
Activity selection problem
Activity selection problemActivity selection problem
Activity selection problem
Sumita Das
 
Multiprotocol label switching
Multiprotocol label switchingMultiprotocol label switching
Multiprotocol label switching
Sumita Das
 
Asymptotic analysis of parallel programs
Asymptotic analysis of parallel programsAsymptotic analysis of parallel programs
Asymptotic analysis of parallel programs
Sumita Das
 
Distributed systems1
Distributed systems1Distributed systems1
Distributed systems1
Sumita Das
 

Recently uploaded (20)

"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 

Presentation on binary search, quick sort, merge sort and problems

  • 1. By- Sumita Das Presentation On Binary Search, Quick Sort, Merge Sort And Problems Created by Sumita Das
  • 2. Binary Search • If we have an ordered list and we know how many things are in the list (i.e., number of records in a file), we can use a different strategy. • The binary search gets its name because the algorithm continually divides the list into two parts. Created by Sumita Das
  • 3. How a Binary Search Works Always look at the center value. Each time you get to discard half of the remaining list. Created by Sumita Das
  • 4. Initialize FailureGet Midpoint High < Low < >Compare Adjust High Adjust Low Success= Created by Sumita Das
  • 5. Algorithm: Low= 1; High = n; while Low < High { m = floor( (Low+High)/2 ); if k <= A[m] then High = m - 1 else Low = m + 1 } if A[Low] = k then j = Low else j = 0 Created by Sumita Das
  • 6. •Similar to merge sort - divide-and- conquer recursive algorithm •One of the fastest sorting algorithms •Average running time O(NlogN) •Worst-case running time O(N2 ) Quick sort Created by Sumita Das
  • 7. Basic idea 1.Pick one element in the array, which will be the pivot. 2.Make one pass through the array, called a partition step, re-arranging the entries so that: •the pivot is in its proper place. •entries smaller than the pivot are to the left of the pivot. •entries larger than the pivot are to its right. Created by Sumita Das
  • 8. 3.Recursively apply quick sort to the part of the array that is to the left of the pivot, and to the right part of the array. Note: Here we don't have the merge step, at the end all the elements are in the proper order. Created by Sumita Das
  • 9. Algorithm: • Input: Array E and indices first, and last, s.t. elements E[i] are defined for first ≤ i ≤ last • Ouput: E[first], …, E[last] is a sorted rearrangement of the array • Void quickSort(Element[] E, int first, int last) if (first < last) Element pivotElement = E[first]; int splitPoint = partition(E, pivotElement, first, last); quickSort (E, first, splitPoint –1 ); quickSort (E, splitPoint +1, last ); return; Created by Sumita Das
  • 10. Merge Sort • Uses recursion. Slightly faster than heap, but uses twice as much memory from the 2nd array. • Sometimes called “divide and conquer” sort. • Works by recursively splitting an array into two equal halves, sorting the items, then re-merging them back into a new array. Created by Sumita Das
  • 11. Algorithm: • Split array A[1..n] in two and make copies of each half in arrays B[1.. n/2 ] and C[1.. n/2 ] • sort arrays B and C • Merge sorted arrays B and C into array A Created by Sumita Das
  • 12. Using Divide and Conquer: Merge Sort • Merge Sort Strategy Sorted Merge Sorted Sorted Sort recursively by Mergesort Sort recursively by Mergesort first last (first + last)/2 Created by Sumita Das
  • 13. Example : Binary Searching 14? 14? Created by Sumita Das
  • 15. Example : Quick sort Created by Sumita Das
  • 16. Example : Merge Sort – n Power of 2 1 2 3 4 5 6 7 8 q = 462317425 1 2 3 4 7425 5 6 7 8 6231 1 2 25 3 4 74 5 6 31 7 8 62 1 5 2 2 3 4 4 7 1 6 3 7 2 8 6 5 Divide
  • 17. Example – n Power of 2 1 5 2 2 3 4 4 7 1 6 3 7 2 8 6 5 1 2 3 4 5 6 7 8 76543221 1 2 3 4 7542 5 6 7 8 6321 1 2 52 3 4 74 5 6 31 7 8 62 Conquer and Merge
  • 18. Example – n Not a Power of 2 62537416274 1 2 3 4 5 6 7 8 9 10 11 q = 6 416274 1 2 3 4 5 6 62537 7 8 9 10 11 q = 9q = 3 274 1 2 3 416 4 5 6 537 7 8 9 62 10 11 74 1 2 2 3 16 4 5 4 6 37 7 8 5 9 2 10 6 11 4 1 7 2 6 4 1 5 7 7 3 8 Divide
  • 19. Example – n Not a Power of 2 77665443221 1 2 3 4 5 6 7 8 9 10 11 764421 1 2 3 4 5 6 76532 7 8 9 10 11 742 1 2 3 641 4 5 6 753 7 8 9 62 10 11 2 3 4 6 5 9 2 10 6 11 4 1 7 2 6 4 1 5 7 7 3 8 74 1 2 61 4 5 73 7 8 Conquer and Merge
  • 20. References [1]Introduction to Algorithms 2nd ,Cormen, Leiserson, Rivest and Stein, The MIT Press, 2001.