SlideShare a Scribd company logo
Name
Reg #
Grade
BUBBLE SORTING
Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly
steps through the list to be sorted, compares each pair of adjacent items and swaps them if
they are in the wrong order. The pass through the list is repeated until no swaps are needed,
which indicates that the list is sorted. The algorithm, which is a comparison sort, is named for
the way smaller elements "bubble" to the top of the list. Although the algorithm is simple, it is
too slow and impractical for most problems even when compared to insertion sort. It can be
practical if the input is usually in sort order but may occasionally have some out-of-order
elements nearly in position.
Aim:
Write a program toSort valuesinAscending orDescendingOrderusingBubble SortTechniquein
LinearArray.
Theory:
The first element in the list is compared with the second. If the first element is found greater
than the second, then both are made to swap places. Now the second element is compared
with the third and again if second is greater than the third, they are swapped, . This process is
repeated for all the elements. Finally the greatest value in the list reaches the last index. Now
one number is at its correct place so to sort the whole array, the complete above process is
repeated equal to the number of elements in the list.
//Suppose the array arr[] has to be sorted in ascending oder
//and there are N elements:
Begin
For p = 0 To N-1 Loop
For q = 0 To Less Than N_1 LOOP
If arr[q]>arr[q+1] Then
Interchange arr[q] with arr[q+1]
EndifEndfor ,EndforStop
Algorithm:
(Bubble Sort) BUBBLE (A, N)
Here A is an Array with N elements stored in it. This algorithm sorts
the elements in A.
1. Repeat Steps 2 to 4 for Pass = 1 to N – 1
2. Set Swapped = 0 and K = 0
3. Repeat while K < (N – Pass)
(a) if A[ K ] > A[ K + 1] then
Interchange A[ K ] and A[ K + 1 ] and
Set Swapped = 1
[ End of if structure. ]
(b) Set K = K + 1
[ End of inner loop of step-3. ]
4. if Swapped = 0 then break the outer loop of step-1
[ End of outer loop of step-1. ]
5. End
Example:
When this first pass through the array is complete, the bubble sort returns to elements one and
two and starts the process all over again. So, when does it stop? The bubble sort knows that it
is finished when it examines the entire array and no "swaps" are needed (thus the list is in
proper order). The bubble sort keeps track of occurring swaps by the use of a flag.
The table below follows an array of numbers before, during, and after a bubble sort
for descending order. A "pass" is defined as one full trip through the array comparing and if
necessary, swapping, adjacent elements. Several passes have to be made through the array
before it is finally sorted.
Array at beginning: 84 69 76 86 94 91
After Pass #1: 84 76 86 94 91 69
After Pass #2: 84 86 94 91 76 69
After Pass #3: 86 94 91 84 76 69
After Pass #4: 94 91 86 84 76 69
After Pass #5 (done): 94 91 86 84 76 69
Code:
Result:
***********

More Related Content

What's hot

Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
Mohammed Hussein
 
Ppt bubble sort
Ppt bubble sortPpt bubble sort
Ppt bubble sort
prabhakar jalasutram
 
Insertion sort
Insertion sortInsertion sort
Selection sort lab mannual
Selection sort lab mannualSelection sort lab mannual
Selection sort lab mannual
maamir farooq
 
Selection sort
Selection sortSelection sort
Selection sort
smlagustin
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
International Islamic University
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
MYER301
 
Priority queues
Priority queuesPriority queues
Priority queues
Priyanka Rana
 
Binary search
Binary searchBinary search
Binary search
AparnaKumari31
 
Sorting
SortingSorting
3.8 quicksort
3.8 quicksort3.8 quicksort
3.8 quicksort
Krish_ver2
 
Merge sort and quick sort
Merge sort and quick sortMerge sort and quick sort
Merge sort and quick sort
Shakila Mahjabin
 
Merge sort algorithm power point presentation
Merge sort algorithm power point presentationMerge sort algorithm power point presentation
Merge sort algorithm power point presentation
University of Science and Technology Chitttagong
 
Merge sort
Merge sortMerge sort
Merge sort
Vidushi Pathak
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
ramya marichamy
 
Hashing
HashingHashing
Hashing
Amar Jukuntla
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
Quick sort
Quick sortQuick sort
Quick sort
amar kakde
 
Quick sort
Quick sortQuick sort
Quick sort
Jehat Hassan
 
Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
Muhazzab Chouhadry
 

What's hot (20)

Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Ppt bubble sort
Ppt bubble sortPpt bubble sort
Ppt bubble sort
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Selection sort lab mannual
Selection sort lab mannualSelection sort lab mannual
Selection sort lab mannual
 
Selection sort
Selection sortSelection sort
Selection sort
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Priority queues
Priority queuesPriority queues
Priority queues
 
Binary search
Binary searchBinary search
Binary search
 
Sorting
SortingSorting
Sorting
 
3.8 quicksort
3.8 quicksort3.8 quicksort
3.8 quicksort
 
Merge sort and quick sort
Merge sort and quick sortMerge sort and quick sort
Merge sort and quick sort
 
Merge sort algorithm power point presentation
Merge sort algorithm power point presentationMerge sort algorithm power point presentation
Merge sort algorithm power point presentation
 
Merge sort
Merge sortMerge sort
Merge sort
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Hashing
HashingHashing
Hashing
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Quick sort
Quick sortQuick sort
Quick sort
 
Quick sort
Quick sortQuick sort
Quick sort
 
Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
 

Viewers also liked

An Introduction To Python - Working With Data
An Introduction To Python - Working With DataAn Introduction To Python - Working With Data
An Introduction To Python - Working With Data
Blue Elephant Consulting
 
Matlab
MatlabMatlab
Matlab
Kelin Jose
 
PANCASILA (makalah falsafah pancasila)
PANCASILA (makalah falsafah pancasila) PANCASILA (makalah falsafah pancasila)
PANCASILA (makalah falsafah pancasila)
tita_chubie
 
Bin Sorting And Bubble Sort By Luisito G. Trinidad
Bin Sorting And Bubble Sort By Luisito G. TrinidadBin Sorting And Bubble Sort By Luisito G. Trinidad
Bin Sorting And Bubble Sort By Luisito G. Trinidad
LUISITO TRINIDAD
 
Sorting bubble-sort anim
Sorting   bubble-sort animSorting   bubble-sort anim
Sorting bubble-sort anim
Fajar Zain
 
Matlab basic and image
Matlab basic and imageMatlab basic and image
Matlab basic and image
Divyanshu Rasauria
 
PKI dan Kekejaman Terhadap Ulama
PKI dan Kekejaman Terhadap UlamaPKI dan Kekejaman Terhadap Ulama
PKI dan Kekejaman Terhadap Ulama
a.r.i.e INSTITUTE, my future math project!
 
TNI AD Mengenai Komunis
TNI AD Mengenai KomunisTNI AD Mengenai Komunis
Matlab Basic Tutorial
Matlab Basic TutorialMatlab Basic Tutorial
Matlab Basic Tutorial
Muhammad Rizwan
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
Eleonora Ciceri
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
multimedia9
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
Leslie Samuel
 

Viewers also liked (12)

An Introduction To Python - Working With Data
An Introduction To Python - Working With DataAn Introduction To Python - Working With Data
An Introduction To Python - Working With Data
 
Matlab
MatlabMatlab
Matlab
 
PANCASILA (makalah falsafah pancasila)
PANCASILA (makalah falsafah pancasila) PANCASILA (makalah falsafah pancasila)
PANCASILA (makalah falsafah pancasila)
 
Bin Sorting And Bubble Sort By Luisito G. Trinidad
Bin Sorting And Bubble Sort By Luisito G. TrinidadBin Sorting And Bubble Sort By Luisito G. Trinidad
Bin Sorting And Bubble Sort By Luisito G. Trinidad
 
Sorting bubble-sort anim
Sorting   bubble-sort animSorting   bubble-sort anim
Sorting bubble-sort anim
 
Matlab basic and image
Matlab basic and imageMatlab basic and image
Matlab basic and image
 
PKI dan Kekejaman Terhadap Ulama
PKI dan Kekejaman Terhadap UlamaPKI dan Kekejaman Terhadap Ulama
PKI dan Kekejaman Terhadap Ulama
 
TNI AD Mengenai Komunis
TNI AD Mengenai KomunisTNI AD Mengenai Komunis
TNI AD Mengenai Komunis
 
Matlab Basic Tutorial
Matlab Basic TutorialMatlab Basic Tutorial
Matlab Basic Tutorial
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
 

Similar to Bubble sorting lab manual

Sorting
SortingSorting
Selection Sort and Insertion Sort
Selection Sort and Insertion SortSelection Sort and Insertion Sort
Selection Sort and Insertion Sort
tamayaoraquel
 
Selection sort and insertion sort
Selection sort and insertion sortSelection sort and insertion sort
Selection sort and insertion sort
May Ann Mendoza
 
Sorting method data structure
Sorting method data structureSorting method data structure
Sorting method data structure
sunilchute1
 
Unit v data structure-converted
Unit  v data structure-convertedUnit  v data structure-converted
Unit v data structure-converted
Shri Shankaracharya College, Bhilai,Junwani
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
maamir farooq
 
Sorting
SortingSorting
Unit vii sorting
Unit   vii sorting Unit   vii sorting
Unit vii sorting
Tribhuvan University
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
haramaya university
 
Sorting
SortingSorting
Sorting
BHARATH KUMAR
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
CHANDAN KUMAR
 
Sorting
SortingSorting
Sorting
Ghaffar Khan
 
Data Structure
Data StructureData Structure
Data Structure
HarshGupta663
 
Sorting algorithums > Data Structures & Algorithums
Sorting algorithums  > Data Structures & AlgorithumsSorting algorithums  > Data Structures & Algorithums
Sorting algorithums > Data Structures & Algorithums
Ain-ul-Moiz Khawaja
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & Searching
ThenmozhiK5
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
prakashvs7
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
SonaPathak4
 
Sorting Data structure And Algorithm.pptx
Sorting Data structure And Algorithm.pptxSorting Data structure And Algorithm.pptx
Sorting Data structure And Algorithm.pptx
subhanalichand514
 
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
 
Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.ppt
LegesseSamuel
 

Similar to Bubble sorting lab manual (20)

Sorting
SortingSorting
Sorting
 
Selection Sort and Insertion Sort
Selection Sort and Insertion SortSelection Sort and Insertion Sort
Selection Sort and Insertion Sort
 
Selection sort and insertion sort
Selection sort and insertion sortSelection sort and insertion sort
Selection sort and insertion sort
 
Sorting method data structure
Sorting method data structureSorting method data structure
Sorting method data structure
 
Unit v data structure-converted
Unit  v data structure-convertedUnit  v data structure-converted
Unit v data structure-converted
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
 
Sorting
SortingSorting
Sorting
 
Unit vii sorting
Unit   vii sorting Unit   vii sorting
Unit vii sorting
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
 
Sorting
SortingSorting
Sorting
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Sorting
SortingSorting
Sorting
 
Data Structure
Data StructureData Structure
Data Structure
 
Sorting algorithums > Data Structures & Algorithums
Sorting algorithums  > Data Structures & AlgorithumsSorting algorithums  > Data Structures & Algorithums
Sorting algorithums > Data Structures & Algorithums
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & Searching
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
 
Sorting Data structure And Algorithm.pptx
Sorting Data structure And Algorithm.pptxSorting Data structure And Algorithm.pptx
Sorting Data structure And Algorithm.pptx
 
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
 
Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.ppt
 

More from maamir farooq

Ooad lab1
Ooad lab1Ooad lab1
Ooad lab1
maamir farooq
 
Lesson 03
Lesson 03Lesson 03
Lesson 03
maamir farooq
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
maamir farooq
 
Php client libray
Php client librayPhp client libray
Php client libray
maamir farooq
 
Swiftmailer
SwiftmailerSwiftmailer
Swiftmailer
maamir farooq
 
Lect15
Lect15Lect15
Lec 7
Lec 7Lec 7
Lec 6
Lec 6Lec 6
Lec 5
Lec 5Lec 5
J query 1.7 cheat sheet
J query 1.7 cheat sheetJ query 1.7 cheat sheet
J query 1.7 cheat sheet
maamir farooq
 
Assignment
AssignmentAssignment
Assignment
maamir farooq
 
Java script summary
Java script summaryJava script summary
Java script summary
maamir farooq
 
Lec 3
Lec 3Lec 3
Lec 2
Lec 2Lec 2
Lec 1
Lec 1Lec 1
Css summary
Css summaryCss summary
Css summary
maamir farooq
 
Manual of image processing lab
Manual of image processing labManual of image processing lab
Manual of image processing lab
maamir farooq
 
Session management
Session managementSession management
Session management
maamir farooq
 
Data management
Data managementData management
Data management
maamir farooq
 
Content provider
Content providerContent provider
Content provider
maamir farooq
 

More from maamir farooq (20)

Ooad lab1
Ooad lab1Ooad lab1
Ooad lab1
 
Lesson 03
Lesson 03Lesson 03
Lesson 03
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
 
Php client libray
Php client librayPhp client libray
Php client libray
 
Swiftmailer
SwiftmailerSwiftmailer
Swiftmailer
 
Lect15
Lect15Lect15
Lect15
 
Lec 7
Lec 7Lec 7
Lec 7
 
Lec 6
Lec 6Lec 6
Lec 6
 
Lec 5
Lec 5Lec 5
Lec 5
 
J query 1.7 cheat sheet
J query 1.7 cheat sheetJ query 1.7 cheat sheet
J query 1.7 cheat sheet
 
Assignment
AssignmentAssignment
Assignment
 
Java script summary
Java script summaryJava script summary
Java script summary
 
Lec 3
Lec 3Lec 3
Lec 3
 
Lec 2
Lec 2Lec 2
Lec 2
 
Lec 1
Lec 1Lec 1
Lec 1
 
Css summary
Css summaryCss summary
Css summary
 
Manual of image processing lab
Manual of image processing labManual of image processing lab
Manual of image processing lab
 
Session management
Session managementSession management
Session management
 
Data management
Data managementData management
Data management
 
Content provider
Content providerContent provider
Content provider
 

Recently uploaded

THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
indexPub
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
heathfieldcps1
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
Nguyen Thanh Tu Collection
 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
Iris Thiele Isip-Tan
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
Payaamvohra1
 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
TechSoup
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
nitinpv4ai
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
Nguyen Thanh Tu Collection
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
OH TEIK BIN
 
How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17
Celine George
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
EduSkills OECD
 

Recently uploaded (20)

THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
 
How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
 

Bubble sorting lab manual

  • 1. Name Reg # Grade BUBBLE SORTING Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm, which is a comparison sort, is named for the way smaller elements "bubble" to the top of the list. Although the algorithm is simple, it is too slow and impractical for most problems even when compared to insertion sort. It can be practical if the input is usually in sort order but may occasionally have some out-of-order elements nearly in position. Aim: Write a program toSort valuesinAscending orDescendingOrderusingBubble SortTechniquein LinearArray. Theory: The first element in the list is compared with the second. If the first element is found greater than the second, then both are made to swap places. Now the second element is compared with the third and again if second is greater than the third, they are swapped, . This process is repeated for all the elements. Finally the greatest value in the list reaches the last index. Now one number is at its correct place so to sort the whole array, the complete above process is repeated equal to the number of elements in the list. //Suppose the array arr[] has to be sorted in ascending oder //and there are N elements: Begin For p = 0 To N-1 Loop For q = 0 To Less Than N_1 LOOP If arr[q]>arr[q+1] Then Interchange arr[q] with arr[q+1] EndifEndfor ,EndforStop
  • 2. Algorithm: (Bubble Sort) BUBBLE (A, N) Here A is an Array with N elements stored in it. This algorithm sorts the elements in A. 1. Repeat Steps 2 to 4 for Pass = 1 to N – 1 2. Set Swapped = 0 and K = 0 3. Repeat while K < (N – Pass) (a) if A[ K ] > A[ K + 1] then Interchange A[ K ] and A[ K + 1 ] and Set Swapped = 1 [ End of if structure. ] (b) Set K = K + 1 [ End of inner loop of step-3. ] 4. if Swapped = 0 then break the outer loop of step-1 [ End of outer loop of step-1. ] 5. End Example: When this first pass through the array is complete, the bubble sort returns to elements one and two and starts the process all over again. So, when does it stop? The bubble sort knows that it is finished when it examines the entire array and no "swaps" are needed (thus the list is in proper order). The bubble sort keeps track of occurring swaps by the use of a flag. The table below follows an array of numbers before, during, and after a bubble sort for descending order. A "pass" is defined as one full trip through the array comparing and if necessary, swapping, adjacent elements. Several passes have to be made through the array before it is finally sorted. Array at beginning: 84 69 76 86 94 91 After Pass #1: 84 76 86 94 91 69 After Pass #2: 84 86 94 91 76 69 After Pass #3: 86 94 91 84 76 69 After Pass #4: 94 91 86 84 76 69 After Pass #5 (done): 94 91 86 84 76 69