SlideShare a Scribd company logo
BUBBLE SORT
Presented By :
Ashish Sadavarti
SORTING
Sorting takes an unordered collection and makes
it an ordered one.
1 2 3 4 5 6
1 2 3 4 5 6
12 20 6 66 105 2
2 6 12 20 66 105
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 much efficient when a list is having more then 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
technique but it is easy because it deals with only two
elements at a time.
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
5
12
35
42
77 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
5
12
35
42
77 101
1 2 3 4 5 6
Swap
42 77
"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
77
42 101
1 2 3 4 5 6
Swap
35 77
"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
77
35
42 101
1 2 3 4 5 6
Swap
12 77
"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
77
12
35
42 101
1 2 3 4 5 6
No need to swap
"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
77
12
35
42 101
1 2 3 4 5 6
Swap
5 101
"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
77
12
35
42 5
1 2 3 4 5 6
101
Largest value correctly placed
The “Bubble Up” Algorithm
index <- 1
last_compare_at <- n – 1
loop
exitif(index > last_compare_at)
if(A[index] > A[index + 1]) then
Swap(A[index], A[index + 1])
endif
index <- index + 1
endloop
No, Swap isn’t built in.
Procedure Swap(a, b isoftype in/out Num)
t isoftype Num
t <- a
a <- b
b <- t
endprocedure // Swap
LB
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
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.
“Bubbling” All the Elements
77
12
35
42 5
1 2 3 4 5 6
101
5
42
12
35 77
1 2 3 4 5 6
101
42
5
35
12 77
1 2 3 4 5 6
101
42
35
5
12 77
1 2 3 4 5 6
101
42
35
12
5 77
1 2 3 4 5 6
101
N
-
1
Reducing the Number of
Comparisons
12
35
42
77 101
1 2 3 4 5 6
5
77
12
35
42 5
1 2 3 4 5 6
101
5
42
12
35 77
1 2 3 4 5 6
101
42
5
35
12 77
1 2 3 4 5 6
101
42
35
5
12 77
1 2 3 4 5 6
101
Reducing the Number of
Comparisons
● On the Nth “bubble up”, we only need to
do MAX-N comparisons.
● For example:
○ This is the 4th “bubble up”
○ MAX is 6
○ Thus we have 2 comparisons to do
42
5
35
12 77
1 2 3 4 5 6
101
Putting It All Together
N is … // Size of Array
Arr_Type definesa Array[1..N] of Num
Procedure Swap(n1, n2 isoftype in/out Num)
temp isoftype Num
temp <- n1
n1 <- n2
n2 <- temp
endprocedure // Swap
procedure Bubblesort(A isoftype in/out Arr_Type)
to_do, index isoftype Num
to_do <- N – 1
loop
exitif(to_do = 0)
index <- 1
loop
exitif(index > to_do)
if(A[index] > A[index + 1]) then
Swap(A[index], A[index + 1])
endif
index <- index + 1
endloop
to_do <- to_do - 1
endloop
endprocedure // Bubblesort
Inner
loop
Outer
loop
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
○ Can finish early if no swapping
occurs
● We reduce the number of elements
we compare each time one is
correctly placed
Credits
● https://www.slideshare.net/manekar007/bubbl
e-sort-19001719
22
THANKYOU!

More Related Content

Similar to BUBBLESORT

Sorting of arrays, types in c++ .IST .ppt
Sorting of arrays, types in c++ .IST .pptSorting of arrays, types in c++ .IST .ppt
Sorting of arrays, types in c++ .IST .ppt
saadpisjes
 
Bubble sort/ Exchange sort Algorithmdata structures and algorithms-2018,bs it...
Bubble sort/ Exchange sort Algorithmdata structures and algorithms-2018,bs it...Bubble sort/ Exchange sort Algorithmdata structures and algorithms-2018,bs it...
Bubble sort/ Exchange sort Algorithmdata structures and algorithms-2018,bs it...
Muhammad Abuzar
 
MYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptx
MYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptxMYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptx
MYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptx
ArjayBalberan1
 
Bubble sort
Bubble sort Bubble sort
Bubble sort
rmsz786
 
Bubble sort
Bubble sortBubble sort
Bubble sort
amna izzat
 
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
 
CSE225_LEC3 (1).pptx
CSE225_LEC3 (1).pptxCSE225_LEC3 (1).pptx
CSE225_LEC3 (1).pptx
MamunurRasidAsif
 
Unit vii sorting
Unit   vii sorting Unit   vii sorting
Unit vii sorting
Tribhuvan University
 
Bubble sort
Bubble sortBubble sort
Bubble sort
Ali Asgher
 
Unit 7 sorting
Unit   7 sortingUnit   7 sorting
Unit 7 sorting
Dabbal Singh Mahara
 
Bubble sort
Bubble sortBubble sort
Bubble sort
Rashmi R Upadhya
 
L 14-ct1120
L 14-ct1120L 14-ct1120
L 14-ct1120
Zia Ush Shamszaman
 
Insertion and merge sort
Insertion and merge sortInsertion and merge sort
Insertion and merge sort
Preetham Devisetty
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
Edward Blurock
 
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisAnalysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Radhika Talaviya
 
8 elementary sorts-bubble
8 elementary sorts-bubble8 elementary sorts-bubble
8 elementary sorts-bubble
irdginfo
 
TREE BST HEAP GRAPH
TREE BST HEAP GRAPHTREE BST HEAP GRAPH
TREE BST HEAP GRAPH
Shahariar Rabby
 
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
m.kumarasamy college of engineering
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
Zaid Hameed
 
Heapsortokkay
HeapsortokkayHeapsortokkay
Heapsortokkay
Remesha
 

Similar to BUBBLESORT (20)

Sorting of arrays, types in c++ .IST .ppt
Sorting of arrays, types in c++ .IST .pptSorting of arrays, types in c++ .IST .ppt
Sorting of arrays, types in c++ .IST .ppt
 
Bubble sort/ Exchange sort Algorithmdata structures and algorithms-2018,bs it...
Bubble sort/ Exchange sort Algorithmdata structures and algorithms-2018,bs it...Bubble sort/ Exchange sort Algorithmdata structures and algorithms-2018,bs it...
Bubble sort/ Exchange sort Algorithmdata structures and algorithms-2018,bs it...
 
MYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptx
MYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptxMYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptx
MYSQL DATABASE MYSQL DATABASE MYSQL DATABASE BUBLESORT.pptx
 
Bubble sort
Bubble sort Bubble sort
Bubble sort
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
Sorting and Hashing Algorithm full pdfs.
Sorting and Hashing Algorithm full pdfs.Sorting and Hashing Algorithm full pdfs.
Sorting and Hashing Algorithm full pdfs.
 
CSE225_LEC3 (1).pptx
CSE225_LEC3 (1).pptxCSE225_LEC3 (1).pptx
CSE225_LEC3 (1).pptx
 
Unit vii sorting
Unit   vii sorting Unit   vii sorting
Unit vii sorting
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
Unit 7 sorting
Unit   7 sortingUnit   7 sorting
Unit 7 sorting
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
L 14-ct1120
L 14-ct1120L 14-ct1120
L 14-ct1120
 
Insertion and merge sort
Insertion and merge sortInsertion and merge sort
Insertion and merge sort
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisAnalysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysis
 
8 elementary sorts-bubble
8 elementary sorts-bubble8 elementary sorts-bubble
8 elementary sorts-bubble
 
TREE BST HEAP GRAPH
TREE BST HEAP GRAPHTREE BST HEAP GRAPH
TREE BST HEAP GRAPH
 
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Heapsortokkay
HeapsortokkayHeapsortokkay
Heapsortokkay
 

More from Ashish Sadavarti

Ministry of School
Ministry of SchoolMinistry of School
Ministry of School
Ashish Sadavarti
 
RELIGION IN INDIA
RELIGION IN INDIARELIGION IN INDIA
RELIGION IN INDIA
Ashish Sadavarti
 
5V_DC POWER Supply
5V_DC POWER Supply5V_DC POWER Supply
5V_DC POWER Supply
Ashish Sadavarti
 
Derivatives & Risk Management
Derivatives & Risk Management Derivatives & Risk Management
Derivatives & Risk Management
Ashish Sadavarti
 
Stationary Store Management System
Stationary Store Management SystemStationary Store Management System
Stationary Store Management System
Ashish Sadavarti
 
ARTIFICIAL INTELIGENCE
ARTIFICIAL INTELIGENCEARTIFICIAL INTELIGENCE
ARTIFICIAL INTELIGENCE
Ashish Sadavarti
 
STEPPER MOTOR CONTROLLER USING MICROCONTROLLER
STEPPER MOTOR CONTROLLER USING MICROCONTROLLERSTEPPER MOTOR CONTROLLER USING MICROCONTROLLER
STEPPER MOTOR CONTROLLER USING MICROCONTROLLER
Ashish Sadavarti
 
Develop a shadow sensor alarm using IC 741
Develop a shadow sensor alarm using IC 741Develop a shadow sensor alarm using IC 741
Develop a shadow sensor alarm using IC 741
Ashish Sadavarti
 
BUILD A CIRCUIT FOR EVEN PARITY GENERATOR
BUILD A CIRCUIT FOR EVEN PARITY GENERATORBUILD A CIRCUIT FOR EVEN PARITY GENERATOR
BUILD A CIRCUIT FOR EVEN PARITY GENERATOR
Ashish Sadavarti
 
build a circuit for battery charger for charging a battery of 6V, 4AH
build a circuit for battery charger for charging a battery of 6V, 4AHbuild a circuit for battery charger for charging a battery of 6V, 4AH
build a circuit for battery charger for charging a battery of 6V, 4AH
Ashish Sadavarti
 
SIMULATE AND BUILD CIRCUIT ON GENRAL PURPOSE PCB OF 4:1 MULTIPLEXER .pptx
SIMULATE AND BUILD CIRCUIT ON GENRAL PURPOSE PCB OF 4:1 MULTIPLEXER .pptxSIMULATE AND BUILD CIRCUIT ON GENRAL PURPOSE PCB OF 4:1 MULTIPLEXER .pptx
SIMULATE AND BUILD CIRCUIT ON GENRAL PURPOSE PCB OF 4:1 MULTIPLEXER .pptx
Ashish Sadavarti
 
BUILD A ROOM TEMPERATURE MEASURMENT CIRCUIT USING MICROCONTROLLER.pptx
BUILD A ROOM TEMPERATURE MEASURMENT CIRCUIT USING MICROCONTROLLER.pptxBUILD A ROOM TEMPERATURE MEASURMENT CIRCUIT USING MICROCONTROLLER.pptx
BUILD A ROOM TEMPERATURE MEASURMENT CIRCUIT USING MICROCONTROLLER.pptx
Ashish Sadavarti
 
DEVELOP A SOUND SENSOR USING LM 324 AND MICROPHONE.pptx
DEVELOP A SOUND SENSOR USING LM 324 AND MICROPHONE.pptxDEVELOP A SOUND SENSOR USING LM 324 AND MICROPHONE.pptx
DEVELOP A SOUND SENSOR USING LM 324 AND MICROPHONE.pptx
Ashish Sadavarti
 
BUILD CIRCUIT TO GENERATE FSK FREQUENCY SHIFT KEYING.pptx
BUILD CIRCUIT TO GENERATE FSK FREQUENCY SHIFT KEYING.pptxBUILD CIRCUIT TO GENERATE FSK FREQUENCY SHIFT KEYING.pptx
BUILD CIRCUIT TO GENERATE FSK FREQUENCY SHIFT KEYING.pptx
Ashish Sadavarti
 
DEVELOP A GAS LEAKAGE DETECTOR .pptx
DEVELOP A GAS LEAKAGE DETECTOR .pptxDEVELOP A GAS LEAKAGE DETECTOR .pptx
DEVELOP A GAS LEAKAGE DETECTOR .pptx
Ashish Sadavarti
 
BUILD DC TIME DELAY RELAY USING PUT ON ZERO (0) PCB .pptx
BUILD DC TIME DELAY RELAY USING PUT ON ZERO (0) PCB .pptxBUILD DC TIME DELAY RELAY USING PUT ON ZERO (0) PCB .pptx
BUILD DC TIME DELAY RELAY USING PUT ON ZERO (0) PCB .pptx
Ashish Sadavarti
 
PREPARE A CHART OF STEPPER MOTOR TO DISPLAY ITS FEATURES AND STEPS FOR ITS OP...
PREPARE A CHART OF STEPPER MOTOR TO DISPLAY ITS FEATURES AND STEPS FOR ITS OP...PREPARE A CHART OF STEPPER MOTOR TO DISPLAY ITS FEATURES AND STEPS FOR ITS OP...
PREPARE A CHART OF STEPPER MOTOR TO DISPLAY ITS FEATURES AND STEPS FOR ITS OP...
Ashish Sadavarti
 
SIMULATE AND CIRCUIT ON GENERAL PURPOSE PCB OF HALF ADDER.pptx
SIMULATE AND CIRCUIT ON GENERAL PURPOSE PCB OF HALF ADDER.pptxSIMULATE AND CIRCUIT ON GENERAL PURPOSE PCB OF HALF ADDER.pptx
SIMULATE AND CIRCUIT ON GENERAL PURPOSE PCB OF HALF ADDER.pptx
Ashish Sadavarti
 
TO CONSTRUCT THE CIRCUIT FOR ONE BIT ERROR CORRECTION USING HAMMING CODE.pptx
TO CONSTRUCT THE CIRCUIT FOR ONE BIT ERROR CORRECTION USING HAMMING CODE.pptxTO CONSTRUCT THE CIRCUIT FOR ONE BIT ERROR CORRECTION USING HAMMING CODE.pptx
TO CONSTRUCT THE CIRCUIT FOR ONE BIT ERROR CORRECTION USING HAMMING CODE.pptx
Ashish Sadavarti
 
Industrial Control Circuits .pptx
Industrial Control Circuits .pptxIndustrial Control Circuits .pptx
Industrial Control Circuits .pptx
Ashish Sadavarti
 

More from Ashish Sadavarti (20)

Ministry of School
Ministry of SchoolMinistry of School
Ministry of School
 
RELIGION IN INDIA
RELIGION IN INDIARELIGION IN INDIA
RELIGION IN INDIA
 
5V_DC POWER Supply
5V_DC POWER Supply5V_DC POWER Supply
5V_DC POWER Supply
 
Derivatives & Risk Management
Derivatives & Risk Management Derivatives & Risk Management
Derivatives & Risk Management
 
Stationary Store Management System
Stationary Store Management SystemStationary Store Management System
Stationary Store Management System
 
ARTIFICIAL INTELIGENCE
ARTIFICIAL INTELIGENCEARTIFICIAL INTELIGENCE
ARTIFICIAL INTELIGENCE
 
STEPPER MOTOR CONTROLLER USING MICROCONTROLLER
STEPPER MOTOR CONTROLLER USING MICROCONTROLLERSTEPPER MOTOR CONTROLLER USING MICROCONTROLLER
STEPPER MOTOR CONTROLLER USING MICROCONTROLLER
 
Develop a shadow sensor alarm using IC 741
Develop a shadow sensor alarm using IC 741Develop a shadow sensor alarm using IC 741
Develop a shadow sensor alarm using IC 741
 
BUILD A CIRCUIT FOR EVEN PARITY GENERATOR
BUILD A CIRCUIT FOR EVEN PARITY GENERATORBUILD A CIRCUIT FOR EVEN PARITY GENERATOR
BUILD A CIRCUIT FOR EVEN PARITY GENERATOR
 
build a circuit for battery charger for charging a battery of 6V, 4AH
build a circuit for battery charger for charging a battery of 6V, 4AHbuild a circuit for battery charger for charging a battery of 6V, 4AH
build a circuit for battery charger for charging a battery of 6V, 4AH
 
SIMULATE AND BUILD CIRCUIT ON GENRAL PURPOSE PCB OF 4:1 MULTIPLEXER .pptx
SIMULATE AND BUILD CIRCUIT ON GENRAL PURPOSE PCB OF 4:1 MULTIPLEXER .pptxSIMULATE AND BUILD CIRCUIT ON GENRAL PURPOSE PCB OF 4:1 MULTIPLEXER .pptx
SIMULATE AND BUILD CIRCUIT ON GENRAL PURPOSE PCB OF 4:1 MULTIPLEXER .pptx
 
BUILD A ROOM TEMPERATURE MEASURMENT CIRCUIT USING MICROCONTROLLER.pptx
BUILD A ROOM TEMPERATURE MEASURMENT CIRCUIT USING MICROCONTROLLER.pptxBUILD A ROOM TEMPERATURE MEASURMENT CIRCUIT USING MICROCONTROLLER.pptx
BUILD A ROOM TEMPERATURE MEASURMENT CIRCUIT USING MICROCONTROLLER.pptx
 
DEVELOP A SOUND SENSOR USING LM 324 AND MICROPHONE.pptx
DEVELOP A SOUND SENSOR USING LM 324 AND MICROPHONE.pptxDEVELOP A SOUND SENSOR USING LM 324 AND MICROPHONE.pptx
DEVELOP A SOUND SENSOR USING LM 324 AND MICROPHONE.pptx
 
BUILD CIRCUIT TO GENERATE FSK FREQUENCY SHIFT KEYING.pptx
BUILD CIRCUIT TO GENERATE FSK FREQUENCY SHIFT KEYING.pptxBUILD CIRCUIT TO GENERATE FSK FREQUENCY SHIFT KEYING.pptx
BUILD CIRCUIT TO GENERATE FSK FREQUENCY SHIFT KEYING.pptx
 
DEVELOP A GAS LEAKAGE DETECTOR .pptx
DEVELOP A GAS LEAKAGE DETECTOR .pptxDEVELOP A GAS LEAKAGE DETECTOR .pptx
DEVELOP A GAS LEAKAGE DETECTOR .pptx
 
BUILD DC TIME DELAY RELAY USING PUT ON ZERO (0) PCB .pptx
BUILD DC TIME DELAY RELAY USING PUT ON ZERO (0) PCB .pptxBUILD DC TIME DELAY RELAY USING PUT ON ZERO (0) PCB .pptx
BUILD DC TIME DELAY RELAY USING PUT ON ZERO (0) PCB .pptx
 
PREPARE A CHART OF STEPPER MOTOR TO DISPLAY ITS FEATURES AND STEPS FOR ITS OP...
PREPARE A CHART OF STEPPER MOTOR TO DISPLAY ITS FEATURES AND STEPS FOR ITS OP...PREPARE A CHART OF STEPPER MOTOR TO DISPLAY ITS FEATURES AND STEPS FOR ITS OP...
PREPARE A CHART OF STEPPER MOTOR TO DISPLAY ITS FEATURES AND STEPS FOR ITS OP...
 
SIMULATE AND CIRCUIT ON GENERAL PURPOSE PCB OF HALF ADDER.pptx
SIMULATE AND CIRCUIT ON GENERAL PURPOSE PCB OF HALF ADDER.pptxSIMULATE AND CIRCUIT ON GENERAL PURPOSE PCB OF HALF ADDER.pptx
SIMULATE AND CIRCUIT ON GENERAL PURPOSE PCB OF HALF ADDER.pptx
 
TO CONSTRUCT THE CIRCUIT FOR ONE BIT ERROR CORRECTION USING HAMMING CODE.pptx
TO CONSTRUCT THE CIRCUIT FOR ONE BIT ERROR CORRECTION USING HAMMING CODE.pptxTO CONSTRUCT THE CIRCUIT FOR ONE BIT ERROR CORRECTION USING HAMMING CODE.pptx
TO CONSTRUCT THE CIRCUIT FOR ONE BIT ERROR CORRECTION USING HAMMING CODE.pptx
 
Industrial Control Circuits .pptx
Industrial Control Circuits .pptxIndustrial Control Circuits .pptx
Industrial Control Circuits .pptx
 

Recently uploaded

openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
kalichargn70th171
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 

Recently uploaded (20)

openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 

BUBBLESORT

  • 1. BUBBLE SORT Presented By : Ashish Sadavarti
  • 2. SORTING Sorting takes an unordered collection and makes it an ordered one. 1 2 3 4 5 6 1 2 3 4 5 6 12 20 6 66 105 2 2 6 12 20 66 105
  • 3. 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 much efficient when a list is having more then 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 technique but it is easy because it deals with only two elements at a time. 3
  • 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 ● 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 Swap 42 77
  • 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 12 35 77 42 101 1 2 3 4 5 6 Swap 35 77
  • 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 5 12 77 35 42 101 1 2 3 4 5 6 Swap 12 77
  • 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 5 77 12 35 42 101 1 2 3 4 5 6 No need to swap
  • 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 5 77 12 35 42 101 1 2 3 4 5 6 Swap 5 101
  • 10. "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 77 12 35 42 5 1 2 3 4 5 6 101 Largest value correctly placed
  • 11. The “Bubble Up” Algorithm index <- 1 last_compare_at <- n – 1 loop exitif(index > last_compare_at) if(A[index] > A[index + 1]) then Swap(A[index], A[index + 1]) endif index <- index + 1 endloop
  • 12. No, Swap isn’t built in. Procedure Swap(a, b isoftype in/out Num) t isoftype Num t <- a a <- b b <- t endprocedure // Swap LB
  • 13. 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
  • 14. 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.
  • 15. “Bubbling” All the Elements 77 12 35 42 5 1 2 3 4 5 6 101 5 42 12 35 77 1 2 3 4 5 6 101 42 5 35 12 77 1 2 3 4 5 6 101 42 35 5 12 77 1 2 3 4 5 6 101 42 35 12 5 77 1 2 3 4 5 6 101 N - 1
  • 16. Reducing the Number of Comparisons 12 35 42 77 101 1 2 3 4 5 6 5 77 12 35 42 5 1 2 3 4 5 6 101 5 42 12 35 77 1 2 3 4 5 6 101 42 5 35 12 77 1 2 3 4 5 6 101 42 35 5 12 77 1 2 3 4 5 6 101
  • 17. Reducing the Number of Comparisons ● On the Nth “bubble up”, we only need to do MAX-N comparisons. ● For example: ○ This is the 4th “bubble up” ○ MAX is 6 ○ Thus we have 2 comparisons to do 42 5 35 12 77 1 2 3 4 5 6 101
  • 18. Putting It All Together
  • 19. N is … // Size of Array Arr_Type definesa Array[1..N] of Num Procedure Swap(n1, n2 isoftype in/out Num) temp isoftype Num temp <- n1 n1 <- n2 n2 <- temp endprocedure // Swap
  • 20. procedure Bubblesort(A isoftype in/out Arr_Type) to_do, index isoftype Num to_do <- N – 1 loop exitif(to_do = 0) index <- 1 loop exitif(index > to_do) if(A[index] > A[index + 1]) then Swap(A[index], A[index + 1]) endif index <- index + 1 endloop to_do <- to_do - 1 endloop endprocedure // Bubblesort Inner loop Outer loop
  • 21. 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 ○ Can finish early if no swapping occurs ● We reduce the number of elements we compare each time one is correctly placed