SlideShare a Scribd company logo
Bubble sort
Insertion sort
Selection sort
Sorting Algorithm
Sorting takes an unordered collection and
makes it an ordered one.
2
512354277 101
5 12 35 42 77 101
1 2 3 4 5 6
1 2 3 4 5 6
"Bubbling Up" the Largest Element
Traverse a collection of elements
Move from the front to the end
“Bubble” the largest value to the end using pair-
wise comparisons and swapping
3
512354277 101
1 2 3 4 5 6
"Bubbling Up" the Largest Element
Traverse a collection of elements
Move from the front to the end
“Bubble” the largest value to the end using pair-
wise comparisons and swapping
4
512354277 101Swap42 77
1 2 3 4 5 6
"Bubbling Up" the Largest Element
Traverse a collection of elements
Move from the front to the end
“Bubble” the largest value to the end using pair-
wise comparisons and swapping
5
512357742 101Swap35 77
1 2 3 4 5 6
"Bubbling Up" the Largest Element
Traverse a collection of elements
Move from the front to the end
“Bubble” the largest value to the end using pair-
wise comparisons and swapping
6
512773542 101Swap12 77
1 2 3 4 5 6
"Bubbling Up" the Largest Element
Traverse a collection of elements
Move from the front to the end
“Bubble” the largest value to the end using pair-
wise comparisons and swapping
7
577123542 101
No need to swap
1 2 3 4 5 6
"Bubbling Up" the Largest Element
Traverse a collection of elements
Move from the front to the end
“Bubble” the largest value to the end using pair-
wise comparisons and swapping
8
577123542 101 Swap5 101
1 2 3 4 5 6
"Bubbling Up" the Largest Element
Traverse a collection of elements
Move from the front to the end
“Bubble” the largest value to the end using pair-
wise comparisons and swapping
9
77123542 5 101
Largest value correctly placed
1 2 3 4 5 6
Repeat “Bubble Up” How Many
Times?
If we have N elements…
And if each time we bubble an element, we
place it in its correct location…
Then we repeat the “bubble up” process N
– 1 times.
This guarantees we’ll correctly
place all N elements.
10
“Bubbling” All the Elements
11
77123542 5 101
5421235 77 101
4253512 77 101
4235512 77 101
4235125 77 101
N-1
1 2 3 4 5 6
Bubble Sort
Algorithm
for i  1 to n-1 do
for j  1 to n-i do
if (A[j+1] < A[j]) swap A[j] and A[j+1] ;
}
}
Analysis:
In general, if the list has n elements, we will have to do
(n-1) + (n-2) …. + 2 +1 = (n-1) n / 2 comparisons.
=O(n^2)
12
Insertion Sort
INSERTION_SORT (A, N)
1.Set A[0] = -∞.
2.Repeat Step 3 to 5 for K = 2, 3, …, N:
3. Set TEMP = A[K] and PTR = K – 1.
4. Repeat while TEMP < A[PTR]:
(a) Set A[PTR+1] = A[PTR]
(b) Set PTR = PTR – 1.
[End of Loop.]
5. Set A[PTR+1] = TEMP.
[End of Loop 2.]
6.Return.
Insertion Sort Example
Sort: 34 8 64 51 32 21
34 8 64 51 32 21
The algorithm sees that 8 is smaller than 34 so it swaps.
8 34 64 51 32 21
51 is smaller than 64, so they swap.
8 34 51 64 32 21
8 34 51 64 32 21 (from previous slide)
The algorithm sees 32 as another smaller number and moves
it to its appropriate location between 8 and 34.
8 32 34 51 64 21
The algorithm sees 21 as another smaller number and moves
into between 8 and 32.
Final sorted numbers:
8 21 32 34 51 64
Insertion Sort Complexity
This Sorting algorithm is frequently used when n is very small.
Worst case occurs when array is in reverse order. The inner loop
must use K – 1 comparisons.
f(n) = 1 + 2 + 3 + ….+ (n – 1)
= n(n – 1)/2
= O(n2
)
In average case, there will be approximately (K – 1)/2 comparisons
in the inner loop.
f(n) = (1 + 2 + 3 + ….+ (n – 1))/2
= n(n – 1)/4
= O(n2
)
Selection Sort
This algorithm sorts an array A with N elements.
SELECTION(A, N)
1.Repeat steps 2 and 3 for k=1 to N-1:
2. Call MIN(A, K, N, LOC).
3. [Interchange A[k] and A[LOC]]
Set Temp:= A[k], A[k]:= A[LOC] and A[LOC]:=Temp.
[End of step 1 Loop.]
1.Exit.
MIN(A, K, N, LOC).
1.Set MIN := A[K] and LOC:= K.
2.Repeat for j=k+1 to N:
If Min>A[j], then: Set Min:= A[j] and LOC:=J.
[End of if structure]
3.Return.
Selection Sort Example
1329648
8329641
8349621
8649321
8964321
8694321
9864321
9864321
Selection Sort Complexity
The number f(n) of comparisons in selection sort
algorithm is independent of original order of elements.
There are n-1 comparisons during pass 1 to find the
smallest element, n-2 comparisons during pass 2 to find
the second smallest element, and so on.
Accordingly,
f (n) = (n-1)+(n-2)+-----+2+1
= n(n-1)/2
= O(n2
)
The f (n) holds the same value O(n2
) both for worst case
and average case.
Comparing the Algorithms
Best Average Worst
Case Case Case
Bubble Sort O(n) O(n2
) O(n2
)
Insertion Sort O(n) O(n2
) O(n2
)
Selection Sort O(n2
) O(n2
) O(n2
)
Thank You

More Related Content

What's hot (20)

8th pre alg -l41
8th pre alg -l418th pre alg -l41
8th pre alg -l41
jdurst65
 
Merge sort-algorithm for computer science engineering students
Merge sort-algorithm for computer science engineering studentsMerge sort-algorithm for computer science engineering students
Merge sort-algorithm for computer science engineering students
University of Science and Technology Chitttagong
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
Tareq Hasan
 
Algorithm designing using divide and conquer algorithms
Algorithm designing using divide and conquer algorithmsAlgorithm designing using divide and conquer algorithms
Algorithm designing using divide and conquer algorithms
SiddhantShelake
 
10 merge sort
10 merge sort10 merge sort
10 merge sort
irdginfo
 
Daa final
Daa finalDaa final
Daa final
Gagan019
 
Merge sort algorithm
Merge sort algorithmMerge sort algorithm
Merge sort algorithm
Shubham Dwivedi
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Dr Shashikant Athawale
 
03 dc
03 dc03 dc
03 dc
Hira Gul
 
Advance heat transfer 2
Advance heat transfer 2Advance heat transfer 2
Advance heat transfer 2
JudeOliverMaquiran1
 
Sorting and searching
Sorting and searchingSorting and searching
Sorting and searching
kalyanineve
 
4 ESO Academics - UNIT 02 - POWERS, ROOTS AND LOGARITHMS
4 ESO Academics - UNIT 02 - POWERS, ROOTS AND LOGARITHMS4 ESO Academics - UNIT 02 - POWERS, ROOTS AND LOGARITHMS
4 ESO Academics - UNIT 02 - POWERS, ROOTS AND LOGARITHMS
Gogely The Great
 
Linear Systems Gauss Seidel
Linear Systems   Gauss SeidelLinear Systems   Gauss Seidel
Linear Systems Gauss Seidel
Eric Davishahl
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
Mohd Arif
 
Functions
FunctionsFunctions
Functions
Maurice Verreck
 
Quick sort Algorithm Discussion And Analysis
Quick sort Algorithm Discussion And AnalysisQuick sort Algorithm Discussion And Analysis
Quick sort Algorithm Discussion And Analysis
SNJ Chaudhary
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
Madhu Bala
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Emmanuel college
 
Split and list technique for solving hard problems
Split and list technique for solving hard problemsSplit and list technique for solving hard problems
Split and list technique for solving hard problems
Rohit Kumar Singh
 
State feedback example
State feedback exampleState feedback example
State feedback example
cairo university
 
8th pre alg -l41
8th pre alg -l418th pre alg -l41
8th pre alg -l41
jdurst65
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
Tareq Hasan
 
Algorithm designing using divide and conquer algorithms
Algorithm designing using divide and conquer algorithmsAlgorithm designing using divide and conquer algorithms
Algorithm designing using divide and conquer algorithms
SiddhantShelake
 
10 merge sort
10 merge sort10 merge sort
10 merge sort
irdginfo
 
Sorting and searching
Sorting and searchingSorting and searching
Sorting and searching
kalyanineve
 
4 ESO Academics - UNIT 02 - POWERS, ROOTS AND LOGARITHMS
4 ESO Academics - UNIT 02 - POWERS, ROOTS AND LOGARITHMS4 ESO Academics - UNIT 02 - POWERS, ROOTS AND LOGARITHMS
4 ESO Academics - UNIT 02 - POWERS, ROOTS AND LOGARITHMS
Gogely The Great
 
Linear Systems Gauss Seidel
Linear Systems   Gauss SeidelLinear Systems   Gauss Seidel
Linear Systems Gauss Seidel
Eric Davishahl
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
Mohd Arif
 
Quick sort Algorithm Discussion And Analysis
Quick sort Algorithm Discussion And AnalysisQuick sort Algorithm Discussion And Analysis
Quick sort Algorithm Discussion And Analysis
SNJ Chaudhary
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
Madhu Bala
 
Split and list technique for solving hard problems
Split and list technique for solving hard problemsSplit and list technique for solving hard problems
Split and list technique for solving hard problems
Rohit Kumar Singh
 

Similar to Data Structure and Algorithms Sorting (20)

ds 3Sorting.ppt
ds 3Sorting.pptds 3Sorting.ppt
ds 3Sorting.ppt
AlliVinay1
 
Unit vii sorting
Unit   vii sorting Unit   vii sorting
Unit vii sorting
Tribhuvan University
 
Unit 7 sorting
Unit   7 sortingUnit   7 sorting
Unit 7 sorting
Dabbal Singh Mahara
 
L 14-ct1120
L 14-ct1120L 14-ct1120
L 14-ct1120
Zia Ush Shamszaman
 
Sorting
SortingSorting
Sorting
Zaid Shabbir
 
Sorting
SortingSorting
Sorting
Zaid Shabbir
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
SajalFayyaz
 
Data Structure (MC501)
Data Structure (MC501)Data Structure (MC501)
Data Structure (MC501)
Kamal Singh Lodhi
 
Lecture 13 data structures and algorithms
Lecture 13 data structures and algorithmsLecture 13 data structures and algorithms
Lecture 13 data structures and algorithms
Aakash deep Singhal
 
Different Searching and Sorting Methods.pptx
Different Searching and Sorting Methods.pptxDifferent Searching and Sorting Methods.pptx
Different Searching and Sorting Methods.pptx
Minakshee Patil
 
BUBBLESORT
BUBBLESORT BUBBLESORT
BUBBLESORT
Ashish Sadavarti
 
358 33 powerpoint-slides_14-sorting_chapter-14
358 33 powerpoint-slides_14-sorting_chapter-14358 33 powerpoint-slides_14-sorting_chapter-14
358 33 powerpoint-slides_14-sorting_chapter-14
sumitbardhan
 
Sorting algorithums > Data Structures & Algorithums
Sorting algorithums  > Data Structures & AlgorithumsSorting algorithums  > Data Structures & Algorithums
Sorting algorithums > Data Structures & Algorithums
Ain-ul-Moiz Khawaja
 
DSA_chapter and chapter 3 _03_Sorting Algorithms.pptx
DSA_chapter and chapter 3 _03_Sorting Algorithms.pptxDSA_chapter and chapter 3 _03_Sorting Algorithms.pptx
DSA_chapter and chapter 3 _03_Sorting Algorithms.pptx
tahliildhoore54
 
Data Structure and algorithms for software
Data Structure and algorithms for softwareData Structure and algorithms for software
Data Structure and algorithms for software
ManishShukla712917
 
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptxDSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
suryatom5775
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
CHANDAN KUMAR
 
Sorting method data structure
Sorting method data structureSorting method data structure
Sorting method data structure
sunilchute1
 
Sorting algorithm
Sorting algorithmSorting algorithm
Sorting algorithm
Muhammad Farhan
 
Sorting pnk
Sorting pnkSorting pnk
Sorting pnk
pinakspatel
 
ds 3Sorting.ppt
ds 3Sorting.pptds 3Sorting.ppt
ds 3Sorting.ppt
AlliVinay1
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
SajalFayyaz
 
Lecture 13 data structures and algorithms
Lecture 13 data structures and algorithmsLecture 13 data structures and algorithms
Lecture 13 data structures and algorithms
Aakash deep Singhal
 
Different Searching and Sorting Methods.pptx
Different Searching and Sorting Methods.pptxDifferent Searching and Sorting Methods.pptx
Different Searching and Sorting Methods.pptx
Minakshee Patil
 
358 33 powerpoint-slides_14-sorting_chapter-14
358 33 powerpoint-slides_14-sorting_chapter-14358 33 powerpoint-slides_14-sorting_chapter-14
358 33 powerpoint-slides_14-sorting_chapter-14
sumitbardhan
 
Sorting algorithums > Data Structures & Algorithums
Sorting algorithums  > Data Structures & AlgorithumsSorting algorithums  > Data Structures & Algorithums
Sorting algorithums > Data Structures & Algorithums
Ain-ul-Moiz Khawaja
 
DSA_chapter and chapter 3 _03_Sorting Algorithms.pptx
DSA_chapter and chapter 3 _03_Sorting Algorithms.pptxDSA_chapter and chapter 3 _03_Sorting Algorithms.pptx
DSA_chapter and chapter 3 _03_Sorting Algorithms.pptx
tahliildhoore54
 
Data Structure and algorithms for software
Data Structure and algorithms for softwareData Structure and algorithms for software
Data Structure and algorithms for software
ManishShukla712917
 
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptxDSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
DSA-sortijejjejjdjjdjdjjsjsjsjsjsjsjng.pptx
suryatom5775
 
Sorting method data structure
Sorting method data structureSorting method data structure
Sorting method data structure
sunilchute1
 
Ad

More from ManishPrajapati78 (14)

Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary Tree
ManishPrajapati78
 
Data Structure and Algorithms Queues
Data Structure and Algorithms QueuesData Structure and Algorithms Queues
Data Structure and Algorithms Queues
ManishPrajapati78
 
Data Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of HanoiData Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of Hanoi
ManishPrajapati78
 
Data Structure and Algorithms Stacks
Data Structure and Algorithms StacksData Structure and Algorithms Stacks
Data Structure and Algorithms Stacks
ManishPrajapati78
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
ManishPrajapati78
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms Arrays
ManishPrajapati78
 
Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms
ManishPrajapati78
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms Hashing
ManishPrajapati78
 
Data Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph TraversalData Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph Traversal
ManishPrajapati78
 
Data Structure and Algorithms Graphs
Data Structure and Algorithms GraphsData Structure and Algorithms Graphs
Data Structure and Algorithms Graphs
ManishPrajapati78
 
Data Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding AlgorithmData Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding Algorithm
ManishPrajapati78
 
Data Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesData Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and Trees
ManishPrajapati78
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL Trees
ManishPrajapati78
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary Tree
ManishPrajapati78
 
Data Structure and Algorithms Queues
Data Structure and Algorithms QueuesData Structure and Algorithms Queues
Data Structure and Algorithms Queues
ManishPrajapati78
 
Data Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of HanoiData Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of Hanoi
ManishPrajapati78
 
Data Structure and Algorithms Stacks
Data Structure and Algorithms StacksData Structure and Algorithms Stacks
Data Structure and Algorithms Stacks
ManishPrajapati78
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
ManishPrajapati78
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms Arrays
ManishPrajapati78
 
Data Structure and Algorithms
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms
ManishPrajapati78
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms Hashing
ManishPrajapati78
 
Data Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph TraversalData Structure and Algorithms Graph Traversal
Data Structure and Algorithms Graph Traversal
ManishPrajapati78
 
Data Structure and Algorithms Graphs
Data Structure and Algorithms GraphsData Structure and Algorithms Graphs
Data Structure and Algorithms Graphs
ManishPrajapati78
 
Data Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding AlgorithmData Structure and Algorithms Huffman Coding Algorithm
Data Structure and Algorithms Huffman Coding Algorithm
ManishPrajapati78
 
Data Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesData Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and Trees
ManishPrajapati78
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL Trees
ManishPrajapati78
 
Ad

Recently uploaded (20)

SAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.pptSAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.ppt
MuhammadShaheryar36
 
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free DownloadWondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Puppy jhon
 
Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3
Gaurav Sharma
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Intelli grow
 
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdfHow to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
 
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration KeySmadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
joybepari360
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWSWomen in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
BradBedford3
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FMEAutomated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdfdp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
AI-Powered Compliance Solutions for Global Regulations | Certivo
AI-Powered Compliance Solutions for Global Regulations | CertivoAI-Powered Compliance Solutions for Global Regulations | Certivo
AI-Powered Compliance Solutions for Global Regulations | Certivo
certivoai
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlowDevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Making significant Software Architecture decisions
Making significant Software Architecture decisionsMaking significant Software Architecture decisions
Making significant Software Architecture decisions
Bert Jan Schrijver
 
Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
SAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.pptSAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.ppt
MuhammadShaheryar36
 
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free DownloadWondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Puppy jhon
 
Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3
Gaurav Sharma
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Intelli grow
 
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdfHow to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
 
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration KeySmadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
joybepari360
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWSWomen in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
BradBedford3
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FMEAutomated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdfdp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
AI-Powered Compliance Solutions for Global Regulations | Certivo
AI-Powered Compliance Solutions for Global Regulations | CertivoAI-Powered Compliance Solutions for Global Regulations | Certivo
AI-Powered Compliance Solutions for Global Regulations | Certivo
certivoai
 
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlowDevOps for AI: running LLMs in production with Kubernetes and KubeFlow
DevOps for AI: running LLMs in production with Kubernetes and KubeFlow
Aarno Aukia
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Making significant Software Architecture decisions
Making significant Software Architecture decisionsMaking significant Software Architecture decisions
Making significant Software Architecture decisions
Bert Jan Schrijver
 
Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 

Data Structure and Algorithms Sorting

  • 2. Sorting Algorithm Sorting takes an unordered collection and makes it an ordered one. 2 512354277 101 5 12 35 42 77 101 1 2 3 4 5 6 1 2 3 4 5 6
  • 3. "Bubbling Up" the Largest Element Traverse a collection of elements Move from the front to the end “Bubble” the largest value to the end using pair- wise comparisons and swapping 3 512354277 101 1 2 3 4 5 6
  • 4. "Bubbling Up" the Largest Element Traverse a collection of elements Move from the front to the end “Bubble” the largest value to the end using pair- wise comparisons and swapping 4 512354277 101Swap42 77 1 2 3 4 5 6
  • 5. "Bubbling Up" the Largest Element Traverse a collection of elements Move from the front to the end “Bubble” the largest value to the end using pair- wise comparisons and swapping 5 512357742 101Swap35 77 1 2 3 4 5 6
  • 6. "Bubbling Up" the Largest Element Traverse a collection of elements Move from the front to the end “Bubble” the largest value to the end using pair- wise comparisons and swapping 6 512773542 101Swap12 77 1 2 3 4 5 6
  • 7. "Bubbling Up" the Largest Element Traverse a collection of elements Move from the front to the end “Bubble” the largest value to the end using pair- wise comparisons and swapping 7 577123542 101 No need to swap 1 2 3 4 5 6
  • 8. "Bubbling Up" the Largest Element Traverse a collection of elements Move from the front to the end “Bubble” the largest value to the end using pair- wise comparisons and swapping 8 577123542 101 Swap5 101 1 2 3 4 5 6
  • 9. "Bubbling Up" the Largest Element Traverse a collection of elements Move from the front to the end “Bubble” the largest value to the end using pair- wise comparisons and swapping 9 77123542 5 101 Largest value correctly placed 1 2 3 4 5 6
  • 10. Repeat “Bubble Up” How Many Times? If we have N elements… And if each time we bubble an element, we place it in its correct location… Then we repeat the “bubble up” process N – 1 times. This guarantees we’ll correctly place all N elements. 10
  • 11. “Bubbling” All the Elements 11 77123542 5 101 5421235 77 101 4253512 77 101 4235512 77 101 4235125 77 101 N-1 1 2 3 4 5 6
  • 12. Bubble Sort Algorithm for i  1 to n-1 do for j  1 to n-i do if (A[j+1] < A[j]) swap A[j] and A[j+1] ; } } Analysis: In general, if the list has n elements, we will have to do (n-1) + (n-2) …. + 2 +1 = (n-1) n / 2 comparisons. =O(n^2) 12
  • 13. Insertion Sort INSERTION_SORT (A, N) 1.Set A[0] = -∞. 2.Repeat Step 3 to 5 for K = 2, 3, …, N: 3. Set TEMP = A[K] and PTR = K – 1. 4. Repeat while TEMP < A[PTR]: (a) Set A[PTR+1] = A[PTR] (b) Set PTR = PTR – 1. [End of Loop.] 5. Set A[PTR+1] = TEMP. [End of Loop 2.] 6.Return.
  • 14. Insertion Sort Example Sort: 34 8 64 51 32 21 34 8 64 51 32 21 The algorithm sees that 8 is smaller than 34 so it swaps. 8 34 64 51 32 21 51 is smaller than 64, so they swap. 8 34 51 64 32 21 8 34 51 64 32 21 (from previous slide) The algorithm sees 32 as another smaller number and moves it to its appropriate location between 8 and 34. 8 32 34 51 64 21 The algorithm sees 21 as another smaller number and moves into between 8 and 32. Final sorted numbers: 8 21 32 34 51 64
  • 15. Insertion Sort Complexity This Sorting algorithm is frequently used when n is very small. Worst case occurs when array is in reverse order. The inner loop must use K – 1 comparisons. f(n) = 1 + 2 + 3 + ….+ (n – 1) = n(n – 1)/2 = O(n2 ) In average case, there will be approximately (K – 1)/2 comparisons in the inner loop. f(n) = (1 + 2 + 3 + ….+ (n – 1))/2 = n(n – 1)/4 = O(n2 )
  • 16. Selection Sort This algorithm sorts an array A with N elements. SELECTION(A, N) 1.Repeat steps 2 and 3 for k=1 to N-1: 2. Call MIN(A, K, N, LOC). 3. [Interchange A[k] and A[LOC]] Set Temp:= A[k], A[k]:= A[LOC] and A[LOC]:=Temp. [End of step 1 Loop.] 1.Exit. MIN(A, K, N, LOC). 1.Set MIN := A[K] and LOC:= K. 2.Repeat for j=k+1 to N: If Min>A[j], then: Set Min:= A[j] and LOC:=J. [End of if structure] 3.Return.
  • 18. Selection Sort Complexity The number f(n) of comparisons in selection sort algorithm is independent of original order of elements. There are n-1 comparisons during pass 1 to find the smallest element, n-2 comparisons during pass 2 to find the second smallest element, and so on. Accordingly, f (n) = (n-1)+(n-2)+-----+2+1 = n(n-1)/2 = O(n2 ) The f (n) holds the same value O(n2 ) both for worst case and average case.
  • 19. Comparing the Algorithms Best Average Worst Case Case Case Bubble Sort O(n) O(n2 ) O(n2 ) Insertion Sort O(n) O(n2 ) O(n2 ) Selection Sort O(n2 ) O(n2 ) O(n2 )