SlideShare a Scribd company logo
1 of 11
Download to read offline
Also See more posts : www.comsciguide.blogspot.com
BUBBLE SORT :
Bubble sort is a simple sorting algorithm also called Sinking
algorithm which just goes through a set of data ( list of numbers or characters)
and compares each member with its right neighbour . The pass through the list
is repeated until no more swaps are needed , which indicates that the list is
sorted . Although the algorithm is simple , It is too slow and impractical for a
large set of data.
PSEUDOCODE :
bubble(A,n)
while n>0 // n is the no of elements
k=0
for i=1 to n-1
if (A[i-1] > A[i])
swap A[i-1],A[i]
k=i
n=k;
WORKING :
The bubble sort working with an example :
A[] = {9,3,6,1,8,4,2}
The length of the array is 7 i.e. let n=7.
9 3 6 1 8 4 2
Also See more posts : www.comsciguide.blogspot.com
For 1st
iteration :
9 3 6 1 8 4 2
3 9 6 1 8 4 2
3 6 9 1 8 4 2
3 6 1 9 8 4 2
3 6 1 8 9 4 2
3 6 1 8 4 9 2
3 6 1 8 4 2 9
After 1st
iteration we will get a largest element (9) at the last index
of the array . So for the 2nd
iteration we need not to include it , because as in the
sorted list , the last element will be the largest one.
For 2nd
iteration :
3 6 1 8 4 2
3 6 1 8 4 2
3 1 6 8 4 2
Also See more posts : www.comsciguide.blogspot.com
3 1 6 8 4 2
3 1 6 4 8 2
3 1 6 4 2 8
Here u can observe the second largest element (8) in the array is in it's
place (at n-2 index).
For 3rd
iteration :
3 1 6 4 2
1 3 6 4 2
1 3 6 4 2
1 3 4 6 2
1 3 4 2 6
For 4th
iteration :
1 3 4 2
1 3 4 2
Also See more posts : www.comsciguide.blogspot.com
1 3 4 2
1 3 2 4
For 5th
iteration
1 3 2
1 3 2
1 2 3
For 6th
iteration :
1 2
As here , there is no swaps , IF condition won't execute . So n=k
i.e.(n=1) and the program will stop. Finally the sorted array is
1 2 3 4 6 8 9
PERFORMANCE :
Bubble sort has worst-case and average complexity both О(n2),
where n is the number of items being sorted. There exist many sorting
algorithms with substantially better worst-case or average complexity of
O(nlogn) . Therefore, bubble sort is not a practical sorting algorithm when n is
Also See more posts : www.comsciguide.blogspot.com
large.
The positions of the elements in bubble sort will play a large part in
determining its performance . Large elements at the beginning of the list do not
pose a problem , as they are quickly swapped . Small elements towards the end
however , move to the beginning extremely slowly . This has led to these types
of elements being named rabbits and turtles respectively .
It has a special feature , that the largest element( at last index ) gets
sorted first , with smaller elements taking longer to move to their correct
positions.
The only significant advantage that bubble sort has over most other
implementations, even quicksort, but not insertion sort, is that the ability to
detect that the list is sorted in efficient way .When the list is already sorted
(best-case), the complexity of bubble sort is only O(n). By contrast, most other
algorithms, even those with better average-case complexity, perform their
entire sorting process on the set and thus are more complex.
ANALYSIS :
U will be knowing that we do sort for a set of numbers.
Suppose if u have given array of elements which is already sorted and
one element is added to this..U will be having doubt where we have to
add this element(at the begining or ending of array)..What is that
complexity for this sorting, if we add new element at the last..?
Take a look with an example :
Also See more posts : www.comsciguide.blogspot.com
Let's take this array which is already sorted.
1 2 3 4 6 8 9
Consider the case of adding the new number (assume 5) at the
begining of the array .
The new array becomes
5 1 2 3 4 6 8 9
For 1st
iteration :
5 1 2 3 4 6 8 9
1 5 2 3 4 6 8 9
1 2 5 3 4 6 8 9
1 2 3 5 4 6 8 9
1 2 3 4 5 6 8 9
1 2 3 4 5 6 8 9
1 2 3 4 5 6 8 9
Also See more posts : www.comsciguide.blogspot.com
1 2 3 4 5 6 8 9
FOR 2ND ITERATION :
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
As for 2nd
iteration , no swaping occurs i.e. k=n=1. So there is no chance
of 3rd
iteration and the program exits.
Now consider the case of adding the new number (assume 5 ) at the
begining of the array .
The new array becomes
1 2 3 4 6 8 9 5
For 1st
iteration :
1 2 3 4 6 8 9 5
1 2 3 4 6 8 9 5
Also See more posts : www.comsciguide.blogspot.com
1 2 3 4 6 8 9 5
1 2 3 4 6 8 9 5
1 2 3 4 6 8 9 5
1 2 3 4 6 8 9 5
1 2 3 4 6 8 9 5
1 2 3 4 6 8 5 9
For 2nd
iteration :
1 2 3 4 6 8 5 9
1 2 3 4 6 8 5 9
1 2 3 4 6 8 5 9
1 2 3 4 6 8 5 9
1 2 3 4 6 8 5 9
Also See more posts : www.comsciguide.blogspot.com
1 2 3 4 6 8 5 9
1 2 3 4 6 5 8 9
1 2 3 4 6 5 8 9
For 3rd
iteration :
1 2 3 4 6 5 8 9
1 2 3 4 6 5 8 9
1 2 3 4 6 5 8 9
1 2 3 4 6 5 8 9
1 2 3 4 5 6 8 9
1 2 3 4 5 6 8 9
1 2 3 4 5 6 8 9
1 2 3 4 5 6 8 9
// the array is sorted
and k=7 ..so n=7
For 4th
iteration :
Also See more posts : www.comsciguide.blogspot.com
1 2 3 4 5 6 8 9
1 2 3 4 5 6 8 9
1 2 3 4 5 6 8 9
1 2 3 4 5 6 8 9
1 2 3 4 5 6 8 9
1 2 3 4 5 6 8 9
1 2 3 4 5 6 8 9
1 2 3 4 5 6 8 9
As for 4th
iteration , no swaping occurs i.e. k=n=1. So there no
chance of 5th
iteration and the program exits.
From the analysis , we observe that by adding an element at the
front of index , the cost of running time is less as compared to the cost of
running time for the case of adding element at the last.
Also See more posts : www.comsciguide.blogspot.com
IN PRACTICE :
Bubble sort is one of the simplest sorting algorithm to implement
and easy to understand . Due to its simplicity, bubble sort is often used to
introduce the concept of an algorithm, or a sorting algorithm, to introductory
students.
But due its O(n2) complexity , It will not be efficient for the case of
large lists .Its O(n2) complexity means that its efficiency decreases dramatically
on lists of large number of elements . Even among simple O(n2) sorting
algorithms like insertion sort are usually considerably more efficient.
Also see more posts :
1. Programs those work in C but not in C++
2. Difference between malloc(),calloc(),realloc()
3. Dynamic memory allocation (Stack vs Heap)
4. 3 ways to solve recurrence relations

More Related Content

What's hot

What's hot (20)

Sorting
SortingSorting
Sorting
 
Shell sort
Shell sortShell sort
Shell sort
 
Merge sort
Merge sortMerge sort
Merge sort
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Lect11 Sorting
Lect11 SortingLect11 Sorting
Lect11 Sorting
 
Quick Select (Decrease and Conquer)
Quick Select (Decrease and Conquer) Quick Select (Decrease and Conquer)
Quick Select (Decrease and Conquer)
 
3.5 merge sort
3.5 merge sort3.5 merge sort
3.5 merge sort
 
Bubblesort Algorithm
Bubblesort AlgorithmBubblesort Algorithm
Bubblesort Algorithm
 
Shell sort in Data Structure Using C
Shell sort in Data Structure Using CShell sort in Data Structure Using C
Shell sort in Data Structure Using C
 
Sorting Seminar Presentation by Ashin Guha Majumder
Sorting Seminar Presentation by Ashin Guha MajumderSorting Seminar Presentation by Ashin Guha Majumder
Sorting Seminar Presentation by Ashin Guha Majumder
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Radix and Shell sort
Radix and Shell sortRadix and Shell sort
Radix and Shell sort
 
sorting algorithm graphical method
sorting algorithm graphical method sorting algorithm graphical method
sorting algorithm graphical method
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Sorting
SortingSorting
Sorting
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
Sorting Techniques
Sorting TechniquesSorting Techniques
Sorting Techniques
 
Sorting
SortingSorting
Sorting
 
Chapter 14 Searching and Sorting
Chapter 14 Searching and SortingChapter 14 Searching and Sorting
Chapter 14 Searching and Sorting
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 

Similar to one main advantage of bubble sort as compared to others

Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.pptLegesseSamuel
 
Lecture_14Sorting.pptx
Lecture_14Sorting.pptxLecture_14Sorting.pptx
Lecture_14Sorting.pptxjeevankjeevan
 
Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Muhammad Hammad Waseem
 
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 assignmenteeeeeee.pptx
algorithm assignmenteeeeeee.pptxalgorithm assignmenteeeeeee.pptx
algorithm assignmenteeeeeee.pptxkassahungebrie
 
Ijcse13 05-01-048
Ijcse13 05-01-048Ijcse13 05-01-048
Ijcse13 05-01-048vital vital
 
Ijcse13 05-01-048
Ijcse13 05-01-048Ijcse13 05-01-048
Ijcse13 05-01-048vital vital
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithmsZaid Hameed
 
Insersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in AlgoritmInsersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in AlgoritmEhsan Ehrari
 
Merge sort analysis and its real time applications
Merge sort analysis and its real time applicationsMerge sort analysis and its real time applications
Merge sort analysis and its real time applicationsyazad dumasia
 
Lecture 11.2 : sorting
Lecture 11.2 :  sortingLecture 11.2 :  sorting
Lecture 11.2 : sortingVivek Bhargav
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arraysmaamir farooq
 

Similar to one main advantage of bubble sort as compared to others (20)

Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.ppt
 
Lecture_14Sorting.pptx
Lecture_14Sorting.pptxLecture_14Sorting.pptx
Lecture_14Sorting.pptx
 
Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]
 
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 assignmenteeeeeee.pptx
algorithm assignmenteeeeeee.pptxalgorithm assignmenteeeeeee.pptx
algorithm assignmenteeeeeee.pptx
 
Ijcse13 05-01-048
Ijcse13 05-01-048Ijcse13 05-01-048
Ijcse13 05-01-048
 
Ijcse13 05-01-048
Ijcse13 05-01-048Ijcse13 05-01-048
Ijcse13 05-01-048
 
sorting_part1.ppt
sorting_part1.pptsorting_part1.ppt
sorting_part1.ppt
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
SHELL SORT-2.pptx
SHELL SORT-2.pptxSHELL SORT-2.pptx
SHELL SORT-2.pptx
 
Sorting
SortingSorting
Sorting
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Sortsearch
SortsearchSortsearch
Sortsearch
 
Sorting
SortingSorting
Sorting
 
Insersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in AlgoritmInsersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in Algoritm
 
Sorting
SortingSorting
Sorting
 
Merge sort analysis and its real time applications
Merge sort analysis and its real time applicationsMerge sort analysis and its real time applications
Merge sort analysis and its real time applications
 
Algo PPT.pdf
Algo PPT.pdfAlgo PPT.pdf
Algo PPT.pdf
 
Lecture 11.2 : sorting
Lecture 11.2 :  sortingLecture 11.2 :  sorting
Lecture 11.2 : sorting
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
 

More from Ajay Chimmani

24 standard interview puzzles - Secret mail puzzle
24 standard interview puzzles - Secret mail puzzle24 standard interview puzzles - Secret mail puzzle
24 standard interview puzzles - Secret mail puzzleAjay Chimmani
 
24 standard interview puzzles - The pot of beans
24 standard interview puzzles - The pot of beans24 standard interview puzzles - The pot of beans
24 standard interview puzzles - The pot of beansAjay Chimmani
 
24 standard interview puzzles - How strog is an egg
24 standard interview puzzles - How strog is an egg24 standard interview puzzles - How strog is an egg
24 standard interview puzzles - How strog is an eggAjay Chimmani
 
24 standard interview puzzles - 4 men in hats
24 standard interview puzzles - 4 men in hats24 standard interview puzzles - 4 men in hats
24 standard interview puzzles - 4 men in hatsAjay Chimmani
 
Aptitude Training - TIME AND DISTANCE 3
Aptitude Training - TIME AND DISTANCE 3Aptitude Training - TIME AND DISTANCE 3
Aptitude Training - TIME AND DISTANCE 3Ajay Chimmani
 
Aptitude Training - PIPES AND CISTERN
Aptitude Training - PIPES AND CISTERNAptitude Training - PIPES AND CISTERN
Aptitude Training - PIPES AND CISTERNAjay Chimmani
 
Aptitude Training - PROFIT AND LOSS
Aptitude Training - PROFIT AND LOSSAptitude Training - PROFIT AND LOSS
Aptitude Training - PROFIT AND LOSSAjay Chimmani
 
Aptitude Training - SOLID GEOMETRY 1
Aptitude Training - SOLID GEOMETRY 1Aptitude Training - SOLID GEOMETRY 1
Aptitude Training - SOLID GEOMETRY 1Ajay Chimmani
 
Aptitude Training - SIMPLE AND COMPOUND INTEREST
Aptitude Training - SIMPLE AND COMPOUND INTERESTAptitude Training - SIMPLE AND COMPOUND INTEREST
Aptitude Training - SIMPLE AND COMPOUND INTERESTAjay Chimmani
 
Aptitude Training - TIME AND DISTANCE 4
Aptitude Training - TIME AND DISTANCE 4Aptitude Training - TIME AND DISTANCE 4
Aptitude Training - TIME AND DISTANCE 4Ajay Chimmani
 
Aptitude Training - TIME AND DISTANCE 1
Aptitude Training - TIME AND DISTANCE 1Aptitude Training - TIME AND DISTANCE 1
Aptitude Training - TIME AND DISTANCE 1Ajay Chimmani
 
Aptitude Training - PROBLEMS ON CUBES
Aptitude Training - PROBLEMS ON CUBESAptitude Training - PROBLEMS ON CUBES
Aptitude Training - PROBLEMS ON CUBESAjay Chimmani
 
Aptitude Training - RATIO AND PROPORTION 1
Aptitude Training - RATIO AND PROPORTION 1Aptitude Training - RATIO AND PROPORTION 1
Aptitude Training - RATIO AND PROPORTION 1Ajay Chimmani
 
Aptitude Training - PROBABILITY
Aptitude Training - PROBABILITYAptitude Training - PROBABILITY
Aptitude Training - PROBABILITYAjay Chimmani
 
Aptitude Training - RATIO AND PROPORTION 4
Aptitude Training - RATIO AND PROPORTION 4Aptitude Training - RATIO AND PROPORTION 4
Aptitude Training - RATIO AND PROPORTION 4Ajay Chimmani
 
Aptitude Training - NUMBERS
Aptitude Training - NUMBERSAptitude Training - NUMBERS
Aptitude Training - NUMBERSAjay Chimmani
 
Aptitude Training - RATIO AND PROPORTION 2
Aptitude Training - RATIO AND PROPORTION 2Aptitude Training - RATIO AND PROPORTION 2
Aptitude Training - RATIO AND PROPORTION 2Ajay Chimmani
 
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2Ajay Chimmani
 
Aptitude Training - PERCENTAGE 2
Aptitude Training - PERCENTAGE 2Aptitude Training - PERCENTAGE 2
Aptitude Training - PERCENTAGE 2Ajay Chimmani
 
Aptitude Training - PERCENTAGE 1
Aptitude Training - PERCENTAGE 1Aptitude Training - PERCENTAGE 1
Aptitude Training - PERCENTAGE 1Ajay Chimmani
 

More from Ajay Chimmani (20)

24 standard interview puzzles - Secret mail puzzle
24 standard interview puzzles - Secret mail puzzle24 standard interview puzzles - Secret mail puzzle
24 standard interview puzzles - Secret mail puzzle
 
24 standard interview puzzles - The pot of beans
24 standard interview puzzles - The pot of beans24 standard interview puzzles - The pot of beans
24 standard interview puzzles - The pot of beans
 
24 standard interview puzzles - How strog is an egg
24 standard interview puzzles - How strog is an egg24 standard interview puzzles - How strog is an egg
24 standard interview puzzles - How strog is an egg
 
24 standard interview puzzles - 4 men in hats
24 standard interview puzzles - 4 men in hats24 standard interview puzzles - 4 men in hats
24 standard interview puzzles - 4 men in hats
 
Aptitude Training - TIME AND DISTANCE 3
Aptitude Training - TIME AND DISTANCE 3Aptitude Training - TIME AND DISTANCE 3
Aptitude Training - TIME AND DISTANCE 3
 
Aptitude Training - PIPES AND CISTERN
Aptitude Training - PIPES AND CISTERNAptitude Training - PIPES AND CISTERN
Aptitude Training - PIPES AND CISTERN
 
Aptitude Training - PROFIT AND LOSS
Aptitude Training - PROFIT AND LOSSAptitude Training - PROFIT AND LOSS
Aptitude Training - PROFIT AND LOSS
 
Aptitude Training - SOLID GEOMETRY 1
Aptitude Training - SOLID GEOMETRY 1Aptitude Training - SOLID GEOMETRY 1
Aptitude Training - SOLID GEOMETRY 1
 
Aptitude Training - SIMPLE AND COMPOUND INTEREST
Aptitude Training - SIMPLE AND COMPOUND INTERESTAptitude Training - SIMPLE AND COMPOUND INTEREST
Aptitude Training - SIMPLE AND COMPOUND INTEREST
 
Aptitude Training - TIME AND DISTANCE 4
Aptitude Training - TIME AND DISTANCE 4Aptitude Training - TIME AND DISTANCE 4
Aptitude Training - TIME AND DISTANCE 4
 
Aptitude Training - TIME AND DISTANCE 1
Aptitude Training - TIME AND DISTANCE 1Aptitude Training - TIME AND DISTANCE 1
Aptitude Training - TIME AND DISTANCE 1
 
Aptitude Training - PROBLEMS ON CUBES
Aptitude Training - PROBLEMS ON CUBESAptitude Training - PROBLEMS ON CUBES
Aptitude Training - PROBLEMS ON CUBES
 
Aptitude Training - RATIO AND PROPORTION 1
Aptitude Training - RATIO AND PROPORTION 1Aptitude Training - RATIO AND PROPORTION 1
Aptitude Training - RATIO AND PROPORTION 1
 
Aptitude Training - PROBABILITY
Aptitude Training - PROBABILITYAptitude Training - PROBABILITY
Aptitude Training - PROBABILITY
 
Aptitude Training - RATIO AND PROPORTION 4
Aptitude Training - RATIO AND PROPORTION 4Aptitude Training - RATIO AND PROPORTION 4
Aptitude Training - RATIO AND PROPORTION 4
 
Aptitude Training - NUMBERS
Aptitude Training - NUMBERSAptitude Training - NUMBERS
Aptitude Training - NUMBERS
 
Aptitude Training - RATIO AND PROPORTION 2
Aptitude Training - RATIO AND PROPORTION 2Aptitude Training - RATIO AND PROPORTION 2
Aptitude Training - RATIO AND PROPORTION 2
 
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
 
Aptitude Training - PERCENTAGE 2
Aptitude Training - PERCENTAGE 2Aptitude Training - PERCENTAGE 2
Aptitude Training - PERCENTAGE 2
 
Aptitude Training - PERCENTAGE 1
Aptitude Training - PERCENTAGE 1Aptitude Training - PERCENTAGE 1
Aptitude Training - PERCENTAGE 1
 

Recently uploaded

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 

Recently uploaded (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

one main advantage of bubble sort as compared to others

  • 1. Also See more posts : www.comsciguide.blogspot.com BUBBLE SORT : Bubble sort is a simple sorting algorithm also called Sinking algorithm which just goes through a set of data ( list of numbers or characters) and compares each member with its right neighbour . The pass through the list is repeated until no more swaps are needed , which indicates that the list is sorted . Although the algorithm is simple , It is too slow and impractical for a large set of data. PSEUDOCODE : bubble(A,n) while n>0 // n is the no of elements k=0 for i=1 to n-1 if (A[i-1] > A[i]) swap A[i-1],A[i] k=i n=k; WORKING : The bubble sort working with an example : A[] = {9,3,6,1,8,4,2} The length of the array is 7 i.e. let n=7. 9 3 6 1 8 4 2
  • 2. Also See more posts : www.comsciguide.blogspot.com For 1st iteration : 9 3 6 1 8 4 2 3 9 6 1 8 4 2 3 6 9 1 8 4 2 3 6 1 9 8 4 2 3 6 1 8 9 4 2 3 6 1 8 4 9 2 3 6 1 8 4 2 9 After 1st iteration we will get a largest element (9) at the last index of the array . So for the 2nd iteration we need not to include it , because as in the sorted list , the last element will be the largest one. For 2nd iteration : 3 6 1 8 4 2 3 6 1 8 4 2 3 1 6 8 4 2
  • 3. Also See more posts : www.comsciguide.blogspot.com 3 1 6 8 4 2 3 1 6 4 8 2 3 1 6 4 2 8 Here u can observe the second largest element (8) in the array is in it's place (at n-2 index). For 3rd iteration : 3 1 6 4 2 1 3 6 4 2 1 3 6 4 2 1 3 4 6 2 1 3 4 2 6 For 4th iteration : 1 3 4 2 1 3 4 2
  • 4. Also See more posts : www.comsciguide.blogspot.com 1 3 4 2 1 3 2 4 For 5th iteration 1 3 2 1 3 2 1 2 3 For 6th iteration : 1 2 As here , there is no swaps , IF condition won't execute . So n=k i.e.(n=1) and the program will stop. Finally the sorted array is 1 2 3 4 6 8 9 PERFORMANCE : Bubble sort has worst-case and average complexity both О(n2), where n is the number of items being sorted. There exist many sorting algorithms with substantially better worst-case or average complexity of O(nlogn) . Therefore, bubble sort is not a practical sorting algorithm when n is
  • 5. Also See more posts : www.comsciguide.blogspot.com large. The positions of the elements in bubble sort will play a large part in determining its performance . Large elements at the beginning of the list do not pose a problem , as they are quickly swapped . Small elements towards the end however , move to the beginning extremely slowly . This has led to these types of elements being named rabbits and turtles respectively . It has a special feature , that the largest element( at last index ) gets sorted first , with smaller elements taking longer to move to their correct positions. The only significant advantage that bubble sort has over most other implementations, even quicksort, but not insertion sort, is that the ability to detect that the list is sorted in efficient way .When the list is already sorted (best-case), the complexity of bubble sort is only O(n). By contrast, most other algorithms, even those with better average-case complexity, perform their entire sorting process on the set and thus are more complex. ANALYSIS : U will be knowing that we do sort for a set of numbers. Suppose if u have given array of elements which is already sorted and one element is added to this..U will be having doubt where we have to add this element(at the begining or ending of array)..What is that complexity for this sorting, if we add new element at the last..? Take a look with an example :
  • 6. Also See more posts : www.comsciguide.blogspot.com Let's take this array which is already sorted. 1 2 3 4 6 8 9 Consider the case of adding the new number (assume 5) at the begining of the array . The new array becomes 5 1 2 3 4 6 8 9 For 1st iteration : 5 1 2 3 4 6 8 9 1 5 2 3 4 6 8 9 1 2 5 3 4 6 8 9 1 2 3 5 4 6 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 8 9
  • 7. Also See more posts : www.comsciguide.blogspot.com 1 2 3 4 5 6 8 9 FOR 2ND ITERATION : 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 As for 2nd iteration , no swaping occurs i.e. k=n=1. So there is no chance of 3rd iteration and the program exits. Now consider the case of adding the new number (assume 5 ) at the begining of the array . The new array becomes 1 2 3 4 6 8 9 5 For 1st iteration : 1 2 3 4 6 8 9 5 1 2 3 4 6 8 9 5
  • 8. Also See more posts : www.comsciguide.blogspot.com 1 2 3 4 6 8 9 5 1 2 3 4 6 8 9 5 1 2 3 4 6 8 9 5 1 2 3 4 6 8 9 5 1 2 3 4 6 8 9 5 1 2 3 4 6 8 5 9 For 2nd iteration : 1 2 3 4 6 8 5 9 1 2 3 4 6 8 5 9 1 2 3 4 6 8 5 9 1 2 3 4 6 8 5 9 1 2 3 4 6 8 5 9
  • 9. Also See more posts : www.comsciguide.blogspot.com 1 2 3 4 6 8 5 9 1 2 3 4 6 5 8 9 1 2 3 4 6 5 8 9 For 3rd iteration : 1 2 3 4 6 5 8 9 1 2 3 4 6 5 8 9 1 2 3 4 6 5 8 9 1 2 3 4 6 5 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 8 9 // the array is sorted and k=7 ..so n=7 For 4th iteration :
  • 10. Also See more posts : www.comsciguide.blogspot.com 1 2 3 4 5 6 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 8 9 As for 4th iteration , no swaping occurs i.e. k=n=1. So there no chance of 5th iteration and the program exits. From the analysis , we observe that by adding an element at the front of index , the cost of running time is less as compared to the cost of running time for the case of adding element at the last.
  • 11. Also See more posts : www.comsciguide.blogspot.com IN PRACTICE : Bubble sort is one of the simplest sorting algorithm to implement and easy to understand . Due to its simplicity, bubble sort is often used to introduce the concept of an algorithm, or a sorting algorithm, to introductory students. But due its O(n2) complexity , It will not be efficient for the case of large lists .Its O(n2) complexity means that its efficiency decreases dramatically on lists of large number of elements . Even among simple O(n2) sorting algorithms like insertion sort are usually considerably more efficient. Also see more posts : 1. Programs those work in C but not in C++ 2. Difference between malloc(),calloc(),realloc() 3. Dynamic memory allocation (Stack vs Heap) 4. 3 ways to solve recurrence relations