Skip to content

Commit 0c1bd92

Browse files
committed
modufy description
1 parent 92856cb commit 0c1bd92

File tree

5 files changed

+94
-50
lines changed

5 files changed

+94
-50
lines changed

Diff for: sorting/bubble_sort.cpp

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
// Implementation of Bubble sort.
2-
// Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm
3-
// that repeatedly steps through the input list element by element,
4-
// comparing the current element with the one after it, swapping their values if needed.
5-
// These passes through the list are repeated until no swaps had to be performed during a pass,
6-
// meaning that the list has become fully sorted. (Source wiki) https://en.wikipedia.org/wiki/Bubble_sort
1+
/*
2+
Here's how the Bubble Sort algorithm works:
73
8-
// Time Complexity worst-case and average complexity O(n^{2})
9-
// Bubble sort is O(n) on a list that is already sorted i.e. Best case
4+
1. We start by comparing the first two elements of the array. If the first element is greater than the second
5+
element, we swap them.
6+
2. We then compare the second and third elements. If the second element is greater than the third element,
7+
we swap them.
8+
3. We continue this process until we reach the end of the array. At this point, the largest element will
9+
be at the end of the array.
10+
4. We then repeat steps 1-3 for the remaining unsorted portion of the array until the entire array is sorted.
11+
12+
The time complexity of Bubble Sort is O(n^2) in the worst and average case, and O(n) in the best case when
13+
the input array is already sorted.
14+
15+
The space complexity is O(1) as Bubble Sort operates on the input array in-place.
1016
11-
// Sample Input : [2, 1, 9, 3, 5, 4, 0]
12-
// Output : [0 1 2 3 4 5 9]
17+
Bubble sort is O(n) on a list that is already sorted i.e. Best case
18+
19+
Sample Input : [2, 1, 9, 3, 5, 4, 0]
20+
Output : [0 1 2 3 4 5 9]
21+
*/
1322
#include <iostream>
1423
#include <vector>
1524

Diff for: sorting/bubble_sort.go

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
// Implementation of Bubble sort.
2-
// Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm
3-
// that repeatedly steps through the input list element by element,
4-
// comparing the current element with the one after it, swapping their values if needed.
5-
// These passes through the list are repeated until no swaps had to be performed during a pass,
6-
// meaning that the list has become fully sorted. (Source wiki) https://en.wikipedia.org/wiki/Bubble_sort
1+
/*
2+
Here's how the Bubble Sort algorithm works:
73
8-
// Time Complexity worst-case and average complexity O(n^{2})
9-
// Bubble sort is O(n) on a list that is already sorted i.e. Best case
4+
1. We start by comparing the first two elements of the array. If the first element is greater than the second
5+
element, we swap them.
6+
2. We then compare the second and third elements. If the second element is greater than the third element,
7+
we swap them.
8+
3. We continue this process until we reach the end of the array. At this point, the largest element will
9+
be at the end of the array.
10+
4. We then repeat steps 1-3 for the remaining unsorted portion of the array until the entire array is sorted.
11+
12+
The time complexity of Bubble Sort is O(n^2) in the worst and average case, and O(n) in the best case when
13+
the input array is already sorted.
14+
15+
The space complexity is O(1) as Bubble Sort operates on the input array in-place.
1016
11-
// Sample Input : [2, 1, 9, 3, 5, 4, 0]
12-
// Output : [0 1 2 3 4 5 9]
17+
Bubble sort is O(n) on a list that is already sorted i.e. Best case
18+
19+
Sample Input : [2, 1, 9, 3, 5, 4, 0]
20+
Output : [0 1 2 3 4 5 9]
21+
*/
1322

1423
package main
1524

Diff for: sorting/bubble_sort.java

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
// Implementation of Bubble sort.
2-
// Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm
3-
// that repeatedly steps through the input list element by element,
4-
// comparing the current element with the one after it, swapping their values if needed.
5-
// These passes through the list are repeated until no swaps had to be performed during a pass,
6-
// meaning that the list has become fully sorted. (Source wiki) https://en.wikipedia.org/wiki/Bubble_sort
1+
/*
2+
Here's how the Bubble Sort algorithm works:
73
8-
// Time Complexity worst-case and average complexity O(n^{2})
9-
// Bubble sort is O(n) on a list that is already sorted i.e. Best case
4+
1. We start by comparing the first two elements of the array. If the first element is greater than the second
5+
element, we swap them.
6+
2. We then compare the second and third elements. If the second element is greater than the third element,
7+
we swap them.
8+
3. We continue this process until we reach the end of the array. At this point, the largest element will
9+
be at the end of the array.
10+
4. We then repeat steps 1-3 for the remaining unsorted portion of the array until the entire array is sorted.
11+
12+
The time complexity of Bubble Sort is O(n^2) in the worst and average case, and O(n) in the best case when
13+
the input array is already sorted.
14+
15+
The space complexity is O(1) as Bubble Sort operates on the input array in-place.
1016
11-
// Sample Input : [2, 1, 9, 3, 5, 4, 0]
12-
// Output : [0 1 2 3 4 5 9]
17+
Bubble sort is O(n) on a list that is already sorted i.e. Best case
1318
19+
Sample Input : [2, 1, 9, 3, 5, 4, 0]
20+
Output : [0 1 2 3 4 5 9]
21+
*/
1422

1523
public class BubbleSort {
1624
public static void bubbleSort(int[] arr) {

Diff for: sorting/bubble_sort.js

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
// Implementation of Bubble sort.
2-
// Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm
3-
// that repeatedly steps through the input list element by element,
4-
// comparing the current element with the one after it, swapping their values if needed.
5-
// These passes through the list are repeated until no swaps had to be performed during a pass,
6-
// meaning that the list has become fully sorted. (Source wiki) https://en.wikipedia.org/wiki/Bubble_sort
1+
/*
2+
Here's how the Bubble Sort algorithm works:
73
8-
// Time Complexity worst-case and average complexity O(n^{2})
9-
// Bubble sort is O(n) on a list that is already sorted i.e. Best case
4+
1. We start by comparing the first two elements of the array. If the first element is greater than the second
5+
element, we swap them.
6+
2. We then compare the second and third elements. If the second element is greater than the third element,
7+
we swap them.
8+
3. We continue this process until we reach the end of the array. At this point, the largest element will
9+
be at the end of the array.
10+
4. We then repeat steps 1-3 for the remaining unsorted portion of the array until the entire array is sorted.
11+
12+
The time complexity of Bubble Sort is O(n^2) in the worst and average case, and O(n) in the best case when
13+
the input array is already sorted.
14+
15+
The space complexity is O(1) as Bubble Sort operates on the input array in-place.
1016
11-
// Sample Input : [2, 1, 9, 3, 5, 4, 0]
12-
// Output : [0 1 2 3 4 5 9]
17+
Bubble sort is O(n) on a list that is already sorted i.e. Best case
18+
19+
Sample Input : [2, 1, 9, 3, 5, 4, 0]
20+
Output : [0 1 2 3 4 5 9]
21+
*/
1322

1423
function bubbleSort(arr) {
1524
var n = arr.length;

Diff for: sorting/bubble_sort.py

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
# Implementation of Bubble sort.
2-
# Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm
3-
# that repeatedly steps through the input list element by element,
4-
# comparing the current element with the one after it, swapping their values if needed.
5-
# These passes through the list are repeated until no swaps had to be performed during a pass,
6-
# meaning that the list has become fully sorted. (Source wiki) https://en.wikipedia.org/wiki/Bubble_sort
1+
'''
2+
Here's how the Bubble Sort algorithm works:
73
8-
# Time Complexity worst-case and average complexity O(n^{2})
9-
# Bubble sort is O(n) on a list that is already sorted i.e. Best case
4+
1. We start by comparing the first two elements of the array. If the first element is greater than the second
5+
element, we swap them.
6+
2. We then compare the second and third elements. If the second element is greater than the third element,
7+
we swap them.
8+
3. We continue this process until we reach the end of the array. At this point, the largest element will
9+
be at the end of the array.
10+
4. We then repeat steps 1-3 for the remaining unsorted portion of the array until the entire array is sorted.
11+
12+
The time complexity of Bubble Sort is O(n^2) in the worst and average case, and O(n) in the best case when
13+
the input array is already sorted.
14+
15+
The space complexity is O(1) as Bubble Sort operates on the input array in-place.
1016
11-
# Sample Input : [2, 1, 9, 3, 5, 4, 0]
12-
# Output : [0 1 2 3 4 5 9]
17+
Bubble sort is O(n) on a list that is already sorted i.e. Best case
18+
19+
Sample Input : [2, 1, 9, 3, 5, 4, 0]
20+
Output : [0 1 2 3 4 5 9]
21+
'''
1322

1423
def bubbleSort(arr):
1524
n = len(arr)

0 commit comments

Comments
 (0)