SlideShare a Scribd company logo
1 of 11
Sorting
• Sorting takes an unordered collection and
makes it an ordered one.
5
12
35
42
77 101
1 2 3 4 5 6
5 12 35 42 77 101
1 2 3 4 5 6
Exchange/Bubble Sort:
It uses simple algorithm. It sorts by comparing each pair
of adjacent items and swapping them in the order. This
will be repeated until no swaps are needed. The
algorithm got its name from the way smaller elements
"bubble" to the top of the list.
It is not that much efficient, when a list is having more
than a few elements. Among simple sorting algorithms,
algorithms like insertion sort are usually considered as
more efficient.
Bubble sort is little slower compared to other sorting
techniques but it is easy because it deals with only two
elements at a time.
"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
12
35
42
77 101
1 2 3 4 5 6
"Bubbling Up" the Largest Element
5
12
35
42
77 101
1 2 3 4 5 6
Swap
42 77
"Bubbling Up" the Largest Element
5
77
12
35
42 101
1 2 3 4 5 6
No need to swap
Bubble Sort
1. In each pass, we compare adjacent elements and swap them if they are
out of order until the end of the list. By doing so, the 1st pass ends up
“bubbling up” the largest element to the last position on the list
2. The 2nd pass bubbles up the 2nd largest, and so on until, after N-1
passes, the list is sorted.
Example:
Pass 1 89 | 45 68 90 29 34 17 Pass 2 45 | 68 89 29 34 17
45 89 | 68 90 29 34 17 45 68 | 89 29 34 17
68 89 | 90 29 34 17 68 89 | 29 34 17
89 90 | 29 34 17 29 89 | 34 17
29 90 | 34 17 34 89 | 17
34 90 | 17 17 89
17 90
45 68 89 29 34 17 90 45 68 29 34 17 89
largest 2nd largest
Items of Interest
• Notice that only the largest value is
correctly placed
• All other values are still out of order
• So we need to repeat this process
77
12
35
42 5
1 2 3 4 5 6
101
Largest value correctly placed
// Optimized java implementation of Bubble sort
import java.io.*;
class GFG {
// An optimized version of Bubble Sort
static void bubbleSort(int arr[], int n)
{
int i, j, temp;
boolean swapped;
for (i = 0; i < n - 1; i++) {
swapped = false;
for (j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
// Swap arr[j] and arr[j+1]
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
swapped = true;
}
}
// If no two elements were
// swapped by inner loop, then break
if (swapped == false)
break;
}
}
// Function to print an array
static void printArray(int arr[], int size)
{
int i;
for (i = 0; i < size; i++)
System.out.print(arr[i] + " ");
System.out.println();
}
// Driver program
public static void main(String args[])
{
int arr[] = { 64, 34, 25, 12, 22, 11, 90 };
int n = arr.length;
bubbleSort(arr, n);
System.out.println("Sorted array: ");
printArray(arr, n);
}
}
Summary
• “Bubble Up” algorithm will move largest
value to its correct location (to the right)
• Repeat “Bubble Up” until all elements are
correctly placed:
– Maximum of N-1 times
• We reduce the number of elements we
compare each time one is correctly placed
Thank You

More Related Content

Similar to MYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptx

Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.pptLegesseSamuel
 
How bubble sort works
How bubble sort worksHow bubble sort works
How bubble sort worksGaurav Kumar
 
Sorting Algorithms.
Sorting Algorithms.Sorting Algorithms.
Sorting Algorithms.Saket Kumar
 
Sorting and Hashing Algorithm full pdfs.
Sorting and Hashing Algorithm full pdfs.Sorting and Hashing Algorithm full pdfs.
Sorting and Hashing Algorithm full pdfs.NikhilSoni177492
 
sorting and searching.pptx
sorting and searching.pptxsorting and searching.pptx
sorting and searching.pptxParagAhir1
 
(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sortingFadhil Ismail
 
Decimal Long Double Double Double. Represents double-precision floating-point...
Decimal Long Double Double Double. Represents double-precision floating-point...Decimal Long Double Double Double. Represents double-precision floating-point...
Decimal Long Double Double Double. Represents double-precision floating-point...Anwar Patel
 
Chapter2.1 .pptx
Chapter2.1 .pptxChapter2.1 .pptx
Chapter2.1 .pptxRojaPogul1
 
Selection sort
Selection sortSelection sort
Selection sortasra khan
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3smruti sarangi
 
Chapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for printChapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for printAbdii Rashid
 
Algorithm & data structures lec4&5
Algorithm & data structures lec4&5Algorithm & data structures lec4&5
Algorithm & data structures lec4&5Abdul Khan
 

Similar to MYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptx (20)

Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.ppt
 
How bubble sort works
How bubble sort worksHow bubble sort works
How bubble sort works
 
Sorting Algorithms.
Sorting Algorithms.Sorting Algorithms.
Sorting Algorithms.
 
Unit 7 sorting
Unit   7 sortingUnit   7 sorting
Unit 7 sorting
 
Sorting and Hashing Algorithm full pdfs.
Sorting and Hashing Algorithm full pdfs.Sorting and Hashing Algorithm full pdfs.
Sorting and Hashing Algorithm full pdfs.
 
sorting and searching.pptx
sorting and searching.pptxsorting and searching.pptx
sorting and searching.pptx
 
Sorting
SortingSorting
Sorting
 
Sorting
SortingSorting
Sorting
 
simple-sorting algorithms
simple-sorting algorithmssimple-sorting algorithms
simple-sorting algorithms
 
Sorting
SortingSorting
Sorting
 
Sorting
SortingSorting
Sorting
 
Sorting
SortingSorting
Sorting
 
(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting
 
Decimal Long Double Double Double. Represents double-precision floating-point...
Decimal Long Double Double Double. Represents double-precision floating-point...Decimal Long Double Double Double. Represents double-precision floating-point...
Decimal Long Double Double Double. Represents double-precision floating-point...
 
Chapter2.1 .pptx
Chapter2.1 .pptxChapter2.1 .pptx
Chapter2.1 .pptx
 
Selection sort
Selection sortSelection sort
Selection sort
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3
 
Chapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for printChapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for print
 
Algorithm & data structures lec4&5
Algorithm & data structures lec4&5Algorithm & data structures lec4&5
Algorithm & data structures lec4&5
 

More from ArjayBalberan1

MYSQL DATABASE MYSQL DATABASEGroup-1.pptx
MYSQL DATABASE MYSQL DATABASEGroup-1.pptxMYSQL DATABASE MYSQL DATABASEGroup-1.pptx
MYSQL DATABASE MYSQL DATABASEGroup-1.pptxArjayBalberan1
 
Appdev appdev appdev app devAPPDEV 1.2.pptx
Appdev appdev appdev app devAPPDEV 1.2.pptxAppdev appdev appdev app devAPPDEV 1.2.pptx
Appdev appdev appdev app devAPPDEV 1.2.pptxArjayBalberan1
 
Rizals-Family-Childhood-Early-Education.pptx
Rizals-Family-Childhood-Early-Education.pptxRizals-Family-Childhood-Early-Education.pptx
Rizals-Family-Childhood-Early-Education.pptxArjayBalberan1
 
MYSQL DATABASE Operating System Part2 (1).pptx
MYSQL DATABASE Operating System Part2 (1).pptxMYSQL DATABASE Operating System Part2 (1).pptx
MYSQL DATABASE Operating System Part2 (1).pptxArjayBalberan1
 
MYSQL DATABASE APP DEV POWERPOINT 1.pptx
MYSQL DATABASE APP DEV POWERPOINT 1.pptxMYSQL DATABASE APP DEV POWERPOINT 1.pptx
MYSQL DATABASE APP DEV POWERPOINT 1.pptxArjayBalberan1
 
MYSQL DATABASE INTRODUCTION TO JAVASCRIPT.pptx
MYSQL DATABASE INTRODUCTION TO JAVASCRIPT.pptxMYSQL DATABASE INTRODUCTION TO JAVASCRIPT.pptx
MYSQL DATABASE INTRODUCTION TO JAVASCRIPT.pptxArjayBalberan1
 
NETWORK-TOPOLOGIES-VARIOUS-TOPOLOGIES.pptx
NETWORK-TOPOLOGIES-VARIOUS-TOPOLOGIES.pptxNETWORK-TOPOLOGIES-VARIOUS-TOPOLOGIES.pptx
NETWORK-TOPOLOGIES-VARIOUS-TOPOLOGIES.pptxArjayBalberan1
 
MYSQL DATABASE MYSQL DATABASEINSERTION-SORT.pptx
MYSQL DATABASE MYSQL DATABASEINSERTION-SORT.pptxMYSQL DATABASE MYSQL DATABASEINSERTION-SORT.pptx
MYSQL DATABASE MYSQL DATABASEINSERTION-SORT.pptxArjayBalberan1
 
MYSQL DATABASE MYSQL DATABASE merge-sort-grp4.pptx
MYSQL DATABASE MYSQL DATABASE merge-sort-grp4.pptxMYSQL DATABASE MYSQL DATABASE merge-sort-grp4.pptx
MYSQL DATABASE MYSQL DATABASE merge-sort-grp4.pptxArjayBalberan1
 
MYSQL DATABASE MYSQL DATABASEquick-sort.pptx
MYSQL DATABASE MYSQL DATABASEquick-sort.pptxMYSQL DATABASE MYSQL DATABASEquick-sort.pptx
MYSQL DATABASE MYSQL DATABASEquick-sort.pptxArjayBalberan1
 
Selection-sort-in-algorithm and complexity.pptx
Selection-sort-in-algorithm and complexity.pptxSelection-sort-in-algorithm and complexity.pptx
Selection-sort-in-algorithm and complexity.pptxArjayBalberan1
 
Week 7 Github - SI- Architecture.pptx
Week 7 Github - SI-  Architecture.pptxWeek 7 Github - SI-  Architecture.pptx
Week 7 Github - SI- Architecture.pptxArjayBalberan1
 
Week Topic Code Access vs Event Based.pptx
Week Topic Code Access vs Event Based.pptxWeek Topic Code Access vs Event Based.pptx
Week Topic Code Access vs Event Based.pptxArjayBalberan1
 
APP DEV POWERPOINT 2.pptx
APP DEV POWERPOINT 2.pptxAPP DEV POWERPOINT 2.pptx
APP DEV POWERPOINT 2.pptxArjayBalberan1
 

More from ArjayBalberan1 (20)

MYSQL DATABASE MYSQL DATABASEGroup-1.pptx
MYSQL DATABASE MYSQL DATABASEGroup-1.pptxMYSQL DATABASE MYSQL DATABASEGroup-1.pptx
MYSQL DATABASE MYSQL DATABASEGroup-1.pptx
 
Appdev appdev appdev app devAPPDEV 1.2.pptx
Appdev appdev appdev app devAPPDEV 1.2.pptxAppdev appdev appdev app devAPPDEV 1.2.pptx
Appdev appdev appdev app devAPPDEV 1.2.pptx
 
Rizals-Family-Childhood-Early-Education.pptx
Rizals-Family-Childhood-Early-Education.pptxRizals-Family-Childhood-Early-Education.pptx
Rizals-Family-Childhood-Early-Education.pptx
 
MYSQL DATABASE Operating System Part2 (1).pptx
MYSQL DATABASE Operating System Part2 (1).pptxMYSQL DATABASE Operating System Part2 (1).pptx
MYSQL DATABASE Operating System Part2 (1).pptx
 
MYSQL DATABASE APP DEV POWERPOINT 1.pptx
MYSQL DATABASE APP DEV POWERPOINT 1.pptxMYSQL DATABASE APP DEV POWERPOINT 1.pptx
MYSQL DATABASE APP DEV POWERPOINT 1.pptx
 
MYSQL DATABASE INTRODUCTION TO JAVASCRIPT.pptx
MYSQL DATABASE INTRODUCTION TO JAVASCRIPT.pptxMYSQL DATABASE INTRODUCTION TO JAVASCRIPT.pptx
MYSQL DATABASE INTRODUCTION TO JAVASCRIPT.pptx
 
NETWORK-TOPOLOGIES-VARIOUS-TOPOLOGIES.pptx
NETWORK-TOPOLOGIES-VARIOUS-TOPOLOGIES.pptxNETWORK-TOPOLOGIES-VARIOUS-TOPOLOGIES.pptx
NETWORK-TOPOLOGIES-VARIOUS-TOPOLOGIES.pptx
 
MYSQL DATABASE MYSQL DATABASEINSERTION-SORT.pptx
MYSQL DATABASE MYSQL DATABASEINSERTION-SORT.pptxMYSQL DATABASE MYSQL DATABASEINSERTION-SORT.pptx
MYSQL DATABASE MYSQL DATABASEINSERTION-SORT.pptx
 
MYSQL DATABASE MYSQL DATABASE merge-sort-grp4.pptx
MYSQL DATABASE MYSQL DATABASE merge-sort-grp4.pptxMYSQL DATABASE MYSQL DATABASE merge-sort-grp4.pptx
MYSQL DATABASE MYSQL DATABASE merge-sort-grp4.pptx
 
MYSQL DATABASE MYSQL DATABASEquick-sort.pptx
MYSQL DATABASE MYSQL DATABASEquick-sort.pptxMYSQL DATABASE MYSQL DATABASEquick-sort.pptx
MYSQL DATABASE MYSQL DATABASEquick-sort.pptx
 
Selection-sort-in-algorithm and complexity.pptx
Selection-sort-in-algorithm and complexity.pptxSelection-sort-in-algorithm and complexity.pptx
Selection-sort-in-algorithm and complexity.pptx
 
Week 7 Github - SI- Architecture.pptx
Week 7 Github - SI-  Architecture.pptxWeek 7 Github - SI-  Architecture.pptx
Week 7 Github - SI- Architecture.pptx
 
HTML-Lab.pptx
HTML-Lab.pptxHTML-Lab.pptx
HTML-Lab.pptx
 
tableslist.pptx
tableslist.pptxtableslist.pptx
tableslist.pptx
 
Week Topic Code Access vs Event Based.pptx
Week Topic Code Access vs Event Based.pptxWeek Topic Code Access vs Event Based.pptx
Week Topic Code Access vs Event Based.pptx
 
MODULE-01.pptx
MODULE-01.pptxMODULE-01.pptx
MODULE-01.pptx
 
APP DEV POWERPOINT 2.pptx
APP DEV POWERPOINT 2.pptxAPP DEV POWERPOINT 2.pptx
APP DEV POWERPOINT 2.pptx
 
APPDEV 1.pptx
APPDEV 1.pptxAPPDEV 1.pptx
APPDEV 1.pptx
 
ADV PPT 8 LAB.pptx
ADV PPT 8 LAB.pptxADV PPT 8 LAB.pptx
ADV PPT 8 LAB.pptx
 
ADV PPT 2 LAB.pptx
ADV PPT 2 LAB.pptxADV PPT 2 LAB.pptx
ADV PPT 2 LAB.pptx
 

Recently uploaded

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 

Recently uploaded (20)

Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 

MYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptx

  • 1.
  • 2. Sorting • Sorting takes an unordered collection and makes it an ordered one. 5 12 35 42 77 101 1 2 3 4 5 6 5 12 35 42 77 101 1 2 3 4 5 6
  • 3. Exchange/Bubble Sort: It uses simple algorithm. It sorts by comparing each pair of adjacent items and swapping them in the order. This will be repeated until no swaps are needed. The algorithm got its name from the way smaller elements "bubble" to the top of the list. It is not that much efficient, when a list is having more than a few elements. Among simple sorting algorithms, algorithms like insertion sort are usually considered as more efficient. Bubble sort is little slower compared to other sorting techniques but it is easy because it deals with only two elements at a time.
  • 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 5 12 35 42 77 101 1 2 3 4 5 6
  • 5. "Bubbling Up" the Largest Element 5 12 35 42 77 101 1 2 3 4 5 6 Swap 42 77
  • 6. "Bubbling Up" the Largest Element 5 77 12 35 42 101 1 2 3 4 5 6 No need to swap
  • 7. Bubble Sort 1. In each pass, we compare adjacent elements and swap them if they are out of order until the end of the list. By doing so, the 1st pass ends up “bubbling up” the largest element to the last position on the list 2. The 2nd pass bubbles up the 2nd largest, and so on until, after N-1 passes, the list is sorted. Example: Pass 1 89 | 45 68 90 29 34 17 Pass 2 45 | 68 89 29 34 17 45 89 | 68 90 29 34 17 45 68 | 89 29 34 17 68 89 | 90 29 34 17 68 89 | 29 34 17 89 90 | 29 34 17 29 89 | 34 17 29 90 | 34 17 34 89 | 17 34 90 | 17 17 89 17 90 45 68 89 29 34 17 90 45 68 29 34 17 89 largest 2nd largest
  • 8. Items of Interest • Notice that only the largest value is correctly placed • All other values are still out of order • So we need to repeat this process 77 12 35 42 5 1 2 3 4 5 6 101 Largest value correctly placed
  • 9. // Optimized java implementation of Bubble sort import java.io.*; class GFG { // An optimized version of Bubble Sort static void bubbleSort(int arr[], int n) { int i, j, temp; boolean swapped; for (i = 0; i < n - 1; i++) { swapped = false; for (j = 0; j < n - i - 1; j++) { if (arr[j] > arr[j + 1]) { // Swap arr[j] and arr[j+1] temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; swapped = true; } } // If no two elements were // swapped by inner loop, then break if (swapped == false) break; } } // Function to print an array static void printArray(int arr[], int size) { int i; for (i = 0; i < size; i++) System.out.print(arr[i] + " "); System.out.println(); } // Driver program public static void main(String args[]) { int arr[] = { 64, 34, 25, 12, 22, 11, 90 }; int n = arr.length; bubbleSort(arr, n); System.out.println("Sorted array: "); printArray(arr, n); } }
  • 10. Summary • “Bubble Up” algorithm will move largest value to its correct location (to the right) • Repeat “Bubble Up” until all elements are correctly placed: – Maximum of N-1 times • We reduce the number of elements we compare each time one is correctly placed