Bubble Sort
- In each iteration the element on top of array gets sorted.
- Biggest element gets placed in its correct position
- Time Complexity is O(n power 2) or n square
- Outer loop runs for n times (n,n-1,n-2)
- Inner loop runs for n times (n-1,n-2,n-3)
- Ignoring constanats as per asymptotic notations we can say that we get complxity of n square.
- https://github.com/gauravmatta/javacodes/blob/master/PojoClasses/src/javaimplant/sorting/BubbleSort.java
- Example
- 7,8,3,1,2
- 7,3,1,2,8
- 3,1,2,7,8
- 1,2,3,7,8
- 1,2,3,7,8
Comments
Post a Comment