Skip to content

Commit 9f910ba

Browse files
authored
add bubble sort docs
1 parent d8ad4ec commit 9f910ba

File tree

1 file changed

+61
-27
lines changed

1 file changed

+61
-27
lines changed

sorting/bubble-sort/README.md

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,76 @@
1-
# Bubble sort
2-
3-
| | |
4-
| ------------------------- | ---------------------------------- |
5-
|Data structure | Array |
6-
|Worst-case performance |О(n²) comparisons, О(n²) swaps |
7-
|Best-case performance |О(n) comparisons, О(1) swaps |
8-
|Average performance |О(n²) comparisons, О(n²) swaps |
9-
|Worst-case space complexity|O(1) auxiliary |
10-
1+
# Bubble Sort
112

123
A bubble sort, a sorting algorithm that continuously steps through a list,
134
swapping items until they appear in the correct order. The list was plotted
145
in a Cartesian coordinate system, with each point (x, y) indicating that the value y is
156
stored at index x. Then the list would be sorted by bubble sort according to every pixel's value.
167
Note that the largest end gets sorted first, with smaller elements taking longer to move to their correct positions.
178

18-
![img](https://upload.wikimedia.org/wikipedia/commons/3/37/Bubble_sort_animation.gif)
199

20-
An example of bubble sort. Starting from the beginning of the list, compare every adjacent pair,
21-
swap their position if they are not in the right order (the latter one is smaller than the former one).
22-
After each iteration, one less element (the last one) is needed to be compared until there are no more
23-
elements left to be compared.
10+
## Performance
11+
12+
| Complexity | |
13+
| -------------------------- | ----------------------------------- |
14+
| Worst-case performance | О(n²) comparisons, О(n²) swaps |
15+
| Best-case performance | О(n) comparisons, О(1) swaps |
16+
| Average performance | О(n²) comparisons, О(n²) swaps |
17+
| Worst-case space complexity| O(1) auxiliary |
18+
19+
![img](https://upload.wikimedia.org/wikipedia/commons/3/37/Bubble_sort_animation.gif)
2420

2521

2622
![img](https://upload.wikimedia.org/wikipedia/commons/c/c8/Bubble-sort-example-300px.gif)
2723

24+
# Helpful Links
25+
26+
- Bubble Sort at [Wikipedia](https://en.wikipedia.org/wiki/Bubble_sort)
27+
- Bubble Sort at [Geeks for Geeks](https://www.geeksforgeeks.org/bubble-sort/)
28+
- Bubble Sort at [Tutorials Point](https://www.tutorialspoint.com/data_structures_algorithms/bubble_sort_algorithm.htm)
2829

2930
# Implementations
3031

31-
| Language | Source |
32-
| :-: | :-: |
33-
| <img src="http://konpa.github.io/devicon/devicon.git/icons/c/c-original.svg" width="30px"> | [bubble_sort.c](bubble_sort.c)|
34-
| <img src="http://konpa.github.io/devicon/devicon.git/icons/cplusplus/cplusplus-original.svg" width="30px"> | [bubble_sort.cpp](bubble_sort.cpp)|
35-
| <img src="http://konpa.github.io/devicon/devicon.git/icons/java/java-original.svg" width="30px"> | [BubbleSort.java](BubbleSort.java)|
36-
| <img src="http://konpa.github.io/devicon/devicon.git/icons/python/python-original.svg" width="30px"> | [bubble_sort.py](bubble_sort.py)|
37-
| <img src="http://konpa.github.io/devicon/devicon.git/icons/javascript/javascript-original.svg" width="30px"> | [bubble_sort.js](bubble_sort.js)|
38-
| <img src="https://cdn-images-1.medium.com/max/600/1*FEE98iWinlZBYkxBAG8MvA.png" width="30px"> | [bubble_sort.sh](bubble_sort.sh)|
39-
| <img src="http://konpa.github.io/devicon/devicon.git/icons/php/php-original.svg" width="30px"> | [bubble_sort.php](bubble_sort.php)|
40-
| <img src="http://konpa.github.io/devicon/devicon.git/icons/ruby/ruby-original.svg" width="30px"> | [bubble_sort.rb](bubble_sort.rb)|
41-
| <img src="http://konpa.github.io/devicon/devicon.git/icons/swift/swift-original.svg" width="30px"> | [bubble_sort.swift](bubble_sort.swift)|
42-
| <img src="http://konpa.github.io/devicon/devicon.git/icons/go/go-original.svg" width="30px"> | [bubble_sort.go](bubble_sort.go)|
32+
| Language | 👍 | Source | Run it Online |
33+
| :-------------------------------------------------------------------------------------------------------------------------------: | :-: | :--------------------------------------------: | :-----------------------: |
34+
| <img src="http://konpa.github.io/devicon/devicon.git/icons/c/c-original.svg" width="30px"> || [bubble_sort.c](https://github.com/AllAlgorithms/c/blob/master/sorting/bubble_sort.c) ||
35+
| <img src="http://konpa.github.io/devicon/devicon.git/icons/cplusplus/cplusplus-original.svg" width="30px"> ||[bubble_sort.cpp](algorithm.cpp) ||
36+
| <img src="http://konpa.github.io/devicon/devicon.git/icons/java/java-original.svg" width="30px"> ||[BubbleSort.java](https://github.com/AllAlgorithms/java/blob/master/sorting/BubbleSort.java) ||
37+
| <img src="http://konpa.github.io/devicon/devicon.git/icons/python/python-original.svg" width="30px"> ||[bubble_sort.py](https://github.com/AllAlgorithms/python/blob/master/sorting/bubble_sort.py) ||
38+
| <img src="http://konpa.github.io/devicon/devicon.git/icons/javascript/javascript-original.svg" width="30px"> ||[bubbleSort.js](https://github.com/AllAlgorithms/javascript/blob/master/sorting/bubbleSort.js) ||
39+
| <img src="https://cdn-images-1.medium.com/max/600/1*FEE98iWinlZBYkxBAG8MvA.png" width="30px"> ||[bubble_sort.sh](https://github.com/AllAlgorithms/shell/blob/master/sorting/bubble_sort.sh) ||
40+
| <img src="http://konpa.github.io/devicon/devicon.git/icons/php/php-original.svg" width="30px"> ||[bubble_sort.php](https://github.com/AllAlgorithms/php/blob/master/sorting/bubble_sort.php) ||
41+
| <img src="http://konpa.github.io/devicon/devicon.git/icons/ruby/ruby-original.svg" width="30px"> ||[bubble_sort.rb](https://github.com/AllAlgorithms/ruby/blob/master/sorting/bubble_sort.rb) ||
42+
| <img src="http://konpa.github.io/devicon/devicon.git/icons/swift/swift-original.svg" width="30px"> ||[bubble_sort.swift](https://github.com/AllAlgorithms/swift/blob/master/sorting/bubble_sort.swift) ||
43+
| <img src="http://konpa.github.io/devicon/devicon.git/icons/go/go-original.svg" width="30px"> ||[bubble_sort.go](https://github.com/AllAlgorithms/go/blob/master/sorting/bubblesort/bubble_sort.go) ||
44+
| <img src="https://cdn.svgporn.com/logos/r-lang.svg" width="30px"> ||[algorithm.r](algorithm.r) ||
45+
| <img src="https://cdn.svgporn.com/logos/scala.svg" width="30px"> ||[algorithm.scala](algorithm.scala) ||
46+
| <img src="http://www.cappuccino-project.org/img/cappuccino-icon-8c7fb1dd.png" width="30px"> ||[algorithm.j](algorithm.j) ||
47+
| <img src="https://raw.githubusercontent.com/librariesio/pictogram/master/vendor/assets/images/fortran/fortran.png" width="30px"> ||[algorithm.f95](algorithm.f95) ||
48+
| <img src="https://cdn.abranhe.com/projects/algorithms/logos/brainfuck.svg" width="30px"> ||[algorithm.bf](algorithm.bf) ||
49+
| <img src="https://cdn.svgporn.com/logos/kotlin.svg" width="30px"> ||[algorithm.kt](algorithm.kt) ||
50+
| <img src="https://upload.wikimedia.org/wikipedia/commons/5/5d/Clojure_logo.svg" width="30px"> ||[algorithm.clj](algorithm.clj) ||
51+
| <img src="https://racket-lang.org/img/racket-logo.svg" width="30px"> ||[algorithm.m](example_source.m) ||
52+
| <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Maxima-new.svg/128px-Maxima-new.svg.png" width="30px"> ||[algorithm.rkt](algorithm.rkt) ||
53+
| <img src="http://www.lolcode.org/img/logo.png" width="30px"> ||[algorithm.lol](algorithm.lol) ||
54+
| <img src="https://upload.wikimedia.org/wikipedia/en/9/9e/AppleScript_Editor_Logo.png" width="30px"> ||[algorithm.applescript](algorithm.applescript) ||
55+
| <img src="https://cdn.svgporn.com/logos/erlang.svg" width="30px"> ||[algorithm.erl](algorithm.erl) ||
56+
| <img src="https://cdn.svgporn.com/logos/fsharp.svg" width="30px"> ||[algorithm.fsx](algorithm.fsx) ||
57+
| <img src="https://cdn.svgporn.com/logos/lua.svg" width="30px"> ||[algorithm.lua](algorithm.lua) ||
58+
| <img src="https://cdn.svgporn.com/logos/typescript-icon.svg" width="30px"> ||[algorithm.ts](algorithm.ts) ||
59+
| <img src="https://common-lisp.net/static/imgs/lisplogo.png" width="30px"> ||[algorithm.lisp](algorithm.lisp) ||
60+
| <img src="https://www.rust-lang.org/logos/rust-logo-blk.svg" width="30px"> ||[algorithm.rs](algorithm.rs) ||
61+
| <img src="https://cdn.abranhe.com/projects/algorithms/logos/assembly.svg" width="30px"> ||[algorithm.asm](algorithm.asm) ||
62+
| <img src="https://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png" width="30px"> ||[algorithm.m](algorithm.m) ||
63+
| <img src="https://cdn.svgporn.com/logos/perl.svg" width="30px"> ||[algorithm.pl](algorithm.pl) ||
64+
| <img src="https://julialang.org/v2/img/logo.svg" width="30px"> ||[algorithm.jl](algorithm.jl) ||
65+
| <img src="http://konpa.github.io/devicon/devicon.git/icons/csharp/csharp-original.svg" width="30px"> ||[bubblesort.cs](https://github.com/AllAlgorithms/csharp/blob/master/sorting/bubblesort.cs) ||
66+
| <img src="https://www.haskell.org/static/img/haskell-logo.svg" width="30px"> ||[algorithm.hs](algorithm.hs) ||
67+
68+
69+
# Github or External Libraries
70+
71+
- [bubble-srt](https://github.com/abranhe/bubble-srt) by [@abranhe](https://git.io/abranhe)
72+
73+
# Videos
74+
75+
- [Youtube](https://www.youtube.com/watch?v=Jdtq5uKz-w4) video about Bubble Sort.
76+

0 commit comments

Comments
 (0)