DSA Slides — 100 Algorithms

Core logic snippets only — read, copy, learn. (Two slides per row on desktop.)

1
Sep 2025
Linear Search
for i in range(len(arr)):
    if arr[i] == target:
        return i
return -1
2
Sep 2025
Binary Search
while left <= right:
    mid = left + (right - left) // 2
    if arr[mid] == target:
        return mid
    elif arr[mid] < target:
        left = mid + 1
    else:
        right = mid - 1
3
Sep 2025
Ternary Search
while left <= right:
    mid1 = left + (right - left) // 3
    mid2 = right - (right - left) // 3

    if arr[mid1] == target:
        return mid1
    elif arr[mid2] == target:
        return mid2
    elif target < arr[mid1]:
        right = mid1 - 1
    elif target > arr[mid2]:
        left = mid2 + 1
    else:
        left = mid1 + 1
        right = mid2 - 1
4
Sep 2025
Jump Search
step = int(sqrt(n))
prev = 0
while prev < n and arr[min(step, n)-1] < target:
    prev = step
    step += int(sqrt(n))
    if prev >= n:
        break
# then linear search in block
5
Sep 2025
Interpolation Search
while low <= high and target >= arr[low] and target <= arr[high]:
    pos = low + int(((target-arr[low])*(high-low)) / (arr[high]-arr[low]))
    if arr[pos] == target:
        return pos
    elif arr[pos] < target:
        low = pos + 1
    else:
        high = pos - 1
6
Sep 2025
Exponential Search
if arr[0] == target:
    return 0
index = 1
while index < n and arr[index] <= target:
    index *= 2
# then binary search in range [index/2, min(index,n-1)]
7
Sep 2025
Bubble Sort
for i in range(n-1):
    for j in range(n-1-i):
        if arr[j] > arr[j+1]:
            arr[j], arr[j+1] = arr[j+1], arr[j]
8
Sep 2025
Selection Sort
for i in range(len(arr)):
    min_idx = i
    for j in range(i+1, len(arr)):
        if arr[j] < arr[min_idx]:
            min_idx = j
    arr[i], arr[min_idx] = arr[min_idx], arr[i]
9
Sep 2025
Insertion Sort
for i in range(1, len(arr)):
    key = arr[i]
    j = i - 1
    while j >= 0 and arr[j] > key:
        arr[j+1] = arr[j]; j -= 1
    arr[j+1] = key
10
Sep 2025
Merge Sort (core)
# after splitting L and R
i = j = k = 0
while i < len(L) and j < len(R):
    if L[i] < R[j]: arr[k] = L[i]; i += 1
    else: arr[k] = R[j]; j += 1
    k += 1
arr[k:] = L[i:] + R[j:]
11
Sep 2025
Quick Sort (partition)
pivot = arr[high]
i = low - 1
for j in range(low, high):
    if arr[j] <= pivot:
        i += 1; arr[i], arr[j] = arr[j], arr[i]
arr[i+1], arr[high] = arr[high], arr[i+1]
return i+1
12
Sep 2025
Heap Sort (heapify)
largest = root
left = 2*root + 1
right = 2*root + 2
if left < n and arr[left] > arr[largest]: largest = left
if right < n and arr[right] > arr[largest]: largest = right
if largest != root:
    arr[root], arr[largest] = arr[largest], arr[root]
    heapify(n, largest)
13
Sep 2025
Counting Sort (core)
count = [0] * (max_val + 1)
for x in arr: count[x] += 1
for i in range(1, len(count)): count[i] += count[i-1]
# build output by placing items using counts (stable)
14
Sep 2025
Radix Sort (LSD pass)
exp = 1
while max_val//exp > 0:
    # stable counting sort by digit (arr[i]//exp % 10)
    exp *= 10
15
Sep 2025
Shell Sort
gap = n//2
while gap > 0:
    for i in range(gap, n):
        temp = arr[i]
        j = i
        while j >= gap and arr[j-gap] > temp:
            arr[j] = arr[j-gap]
            j -= gap
        arr[j] = temp
    gap //= 2
16
Sep 2025
Fibonacci (recursive)
def fib(n):
    if n < 2: return n
    return fib(n-1) + fib(n-2)
17
Sep 2025
Factorial (recursive)
def fact(n):
    if n <= 1: return 1
    return n * fact(n-1)
18
Sep 2025
Binary Tree — Inorder
def inorder(node):
    if node:
        inorder(node.left)
        print(node.val)
        inorder(node.right)
19
Sep 2025
BFS (graph)
from collections import deque
q = deque([start]); visited.add(start)
while q:
    node = q.popleft()
    for nbr in graph[node]:
        if nbr not in visited:
            visited.add(nbr); q.append(nbr)
20
Sep 2025
DFS (recursive)
def dfs(u):
    visited.add(u)
    for v in graph[u]:
        if v not in visited: dfs(v)
21
Sep 2025
Algorithm 21
if condition:
    statement
else:
    other_statement
22
Sep 2025
Algorithm 22
if condition:
    statement
else:
    other_statement
23
Sep 2025
Algorithm 23
if condition:
    statement
else:
    other_statement
24
Sep 2025
Algorithm 24
if condition:
    statement
else:
    other_statement
25
Sep 2025
Algorithm 25
if condition:
    statement
else:
    other_statement
26
Sep 2025
Algorithm 26
if condition:
    statement
else:
    other_statement
27
Sep 2025
Algorithm 27
if condition:
    statement
else:
    other_statement
28
Sep 2025
Algorithm 28
if condition:
    statement
else:
    other_statement
29
Sep 2025
Algorithm 29
if condition:
    statement
else:
    other_statement
30
Sep 2025
Algorithm 30
if condition:
    statement
else:
    other_statement
31
Sep 2025
Algorithm 31
if condition:
    statement
else:
    other_statement
32
Sep 2025
Algorithm 32
if condition:
    statement
else:
    other_statement
33
Sep 2025
Algorithm 33
if condition:
    statement
else:
    other_statement
34
Sep 2025
Algorithm 34
if condition:
    statement
else:
    other_statement
35
Sep 2025
Algorithm 35
if condition:
    statement
else:
    other_statement
36
Sep 2025
Algorithm 36
if condition:
    statement
else:
    other_statement
37
Sep 2025
Algorithm 37
if condition:
    statement
else:
    other_statement
38
Sep 2025
Algorithm 38
if condition:
    statement
else:
    other_statement
39
Sep 2025
Algorithm 39
if condition:
    statement
else:
    other_statement
40
Sep 2025
Algorithm 40
if condition:
    statement
else:
    other_statement
41
Sep 2025
Algorithm 41
if condition:
    statement
else:
    other_statement
42
Sep 2025
Algorithm 42
if condition:
    statement
else:
    other_statement
43
Sep 2025
Algorithm 43
if condition:
    statement
else:
    other_statement
44
Sep 2025
Algorithm 44
if condition:
    statement
else:
    other_statement
45
Sep 2025
Algorithm 45
if condition:
    statement
else:
    other_statement
46
Sep 2025
Algorithm 46
if condition:
    statement
else:
    other_statement
47
Sep 2025
Algorithm 47
if condition:
    statement
else:
    other_statement
48
Sep 2025
Algorithm 48
if condition:
    statement
else:
    other_statement
49
Sep 2025
Algorithm 49
if condition:
    statement
else:
    other_statement
50
Sep 2025
Algorithm 50
if condition:
    statement
else:
    other_statement
51
Sep 2025
Algorithm 51
if condition:
    statement
else:
    other_statement
52
Sep 2025
Algorithm 52
if condition:
    statement
else:
    other_statement
53
Sep 2025
Algorithm 53
if condition:
    statement
else:
    other_statement
54
Sep 2025
Algorithm 54
if condition:
    statement
else:
    other_statement
55
Sep 2025
Algorithm 55
if condition:
    statement
else:
    other_statement
56
Sep 2025
Algorithm 56
if condition:
    statement
else:
    other_statement
57
Sep 2025
Algorithm 57
if condition:
    statement
else:
    other_statement
58
Sep 2025
Algorithm 58
if condition:
    statement
else:
    other_statement
59
Sep 2025
Algorithm 59
if condition:
    statement
else:
    other_statement
60
Sep 2025
Algorithm 60
if condition:
    statement
else:
    other_statement
61
Sep 2025
Algorithm 61
if condition:
    statement
else:
    other_statement
62
Sep 2025
Algorithm 62
if condition:
    statement
else:
    other_statement
63
Sep 2025
Algorithm 63
if condition:
    statement
else:
    other_statement
64
Sep 2025
Algorithm 64
if condition:
    statement
else:
    other_statement
65
Sep 2025
Algorithm 65
if condition:
    statement
else:
    other_statement
66
Sep 2025
Algorithm 66
if condition:
    statement
else:
    other_statement
67
Sep 2025
Algorithm 67
if condition:
    statement
else:
    other_statement
68
Sep 2025
Algorithm 68
if condition:
    statement
else:
    other_statement
69
Sep 2025
Algorithm 69
if condition:
    statement
else:
    other_statement
70
Sep 2025
Algorithm 70
if condition:
    statement
else:
    other_statement
71
Sep 2025
Algorithm 71
if condition:
    statement
else:
    other_statement
72
Sep 2025
Algorithm 72
if condition:
    statement
else:
    other_statement
73
Sep 2025
Algorithm 73
if condition:
    statement
else:
    other_statement
74
Sep 2025
Algorithm 74
if condition:
    statement
else:
    other_statement
75
Sep 2025
Algorithm 75
if condition:
    statement
else:
    other_statement
76
Sep 2025
Algorithm 76
if condition:
    statement
else:
    other_statement
77
Sep 2025
Algorithm 77
if condition:
    statement
else:
    other_statement
78
Sep 2025
Algorithm 78
if condition:
    statement
else:
    other_statement
79
Sep 2025
Algorithm 79
if condition:
    statement
else:
    other_statement
80
Sep 2025
Algorithm 80
if condition:
    statement
else:
    other_statement
81
Sep 2025
Algorithm 81
if condition:
    statement
else:
    other_statement
82
Sep 2025
Algorithm 82
if condition:
    statement
else:
    other_statement
83
Sep 2025
Algorithm 83
if condition:
    statement
else:
    other_statement
84
Sep 2025
Algorithm 84
if condition:
    statement
else:
    other_statement
85
Sep 2025
Algorithm 85
if condition:
    statement
else:
    other_statement
86
Sep 2025
Algorithm 86
if condition:
    statementldmbkdsbkksb
    dzlbk zdk 
    ,blxmbk xzkbb
    dzmbk
else:
    other_statement
87
Sep 2025
Algorithm 87
if condition:
    statement
else:
    other_statement
88
Sep 2025
Algorithm 88
if condition:
    statement
else:
    other_statement
89
Sep 2025
Algorithm 89
if condition:
    statement
else:
    other_statement
90
Sep 2025
Algorithm 90
if condition:
    statement
else:
    other_statement
91
Sep 2025
Algorithm 91
if condition:
    statement
else:
    other_statement
92
Sep 2025
Algorithm 92
if condition:
    statement
else:
    other_statement
93
Sep 2025
Algorithm 93
if condition:
    statement
else:
    other_statement
94
Sep 2025
Algorithm 94
if condition:
    statement
else:
    other_statement
95
Sep 2025
Algorithm 95
if condition:
    statement
else:
    other_statement
96
Sep 2025
Algorithm 96
if condition:
    statement
else:
    other_statement
97
Sep 2025
Algorithm 97
if condition:
    statement
else:
    other_statement
98
Sep 2025
Algorithm 98
if condition:
    statement
else:
    other_statement
99
Sep 2025
Algorithm 99
if condition:
    statement
else:
    other_statement
100
Sep 2025
Algorithm 100
if condition:
    statement
else:
    other_statement