- RECURSION
- Call Stack
- Iterative Approach
- Memoization
- Head Tail
- DATA STRUCTURES
- Arrays, Sets
- Time Complexity
- Hash Tables
- Stacks
- Queues
- Linked Lists
- Trees
- Binary Search Trees
- Tries
- Graphs
- COMPARISION BASED
-
Bubble Sort
- Selection Sort
- Merge Sort
- DIVIDE CONQUER
- Binary Search
- Quicksort
- Karatsuba Multiplication
- GRAPH TRAVERSAL
- Flood Fill
- Depth First Search
- Breadth First Search
- Dijkstra's Algorithm
- DECISION MAKING
- Minimax
- GREEDY
- Coin Change
- Fractional Knapsack
Bubble Sort
The algorithm repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.
def bubble_sort(X):
for i in range(len(X)):
for j in range(len(X) -i-1):
if X[j] > X[j+1]:
X[j], X[j+1] = X[j+1], X[j]
# Example usage
A = [1, 3, 9, 5, 4, 0]
bubble_sort(A)
print("Sorted list =", A)
"""
[0, 1, 3, 4, 5, 9]
"""
Last update: 528 days ago