Algorithm
Algorithm
START
// Declare variables
INPUT num1
INPUT num2
// Perform addi on
END
START
sum ← 0
FOR i ← 1 TO n DO
INPUT number
END FOR
END
START
// Declare variables
INPUT num1
INPUT num2
END
START
// Input dimensions
// Input matrix A
FOR i ← 0 TO m-1 DO
FOR j ← 0 TO n-1 DO
INPUT A[i][j]
END FOR
END FOR
// Input matrix B
FOR i ← 0 TO n-1 DO
FOR j ← 0 TO p-1 DO
INPUT B[i][j]
END FOR
END FOR
FOR i ← 0 TO m-1 DO
FOR j ← 0 TO p-1 DO
C[i][j] ← 0
END FOR
END FOR
FOR i ← 0 TO m-1 DO
FOR j ← 0 TO p-1 DO
FOR k ← 0 TO n-1 DO
END FOR
END FOR
END FOR
FOR i ← 0 TO m-1 DO
FOR j ← 0 TO p-1 DO
OUTPUT C[i][j]
END FOR
END FOR
END
START
FOR i ← 0 TO m-1 DO
FOR j ← 0 TO n-1 DO
INPUT A[i][j]
END FOR
END FOR
FOR j ← 0 TO n-1 DO
INPUT B[i][j]
END FOR
END FOR
FOR i ← 0 TO m-1 DO
FOR j ← 0 TO n-1 DO
END FOR
END FOR
FOR i ← 0 TO m-1 DO
FOR j ← 0 TO n-1 DO
OUTPUT C[i][j]
END FOR
END FOR
END
START
INPUT n
DECLARE array[n]
// Input array elements
FOR i ← 0 TO n-1 DO
INPUT array[i]
END FOR
// Find uniqueness
FOR i ← 0 TO n-1 DO
count ← 0
FOR j ← 0 TO n-1 DO
count ← count + 1
END IF
END FOR
IF count = 1 THEN
END IF
END FOR
START
INPUT n
DECLARE array[n]
// Input array elements
FOR i ← 0 TO n-1 DO
INPUT array[i]
END FOR
INPUT key
found ← false
FOR i ← 0 TO n-1 DO
found ← true
BREAK
END IF
END FOR
END IF
END
START
INPUT n
factorial ← 1
IF n = 0 THEN
ELSE
// Loop from 1 to n
FOR i ← 1 TO n DO
factorial ← factorial × i
END FOR
END IF
END
START
INPUT n
a←0
b←1
IF n ≥ 1 THEN
OUTPUT a
END IF
IF n ≥ 2 THEN
OUTPUT b
END IF
FOR i ← 3 TO n DO
next ← a + b
OUTPUT next
a←b
b ← next
END FOR
END
START
INPUT n
count ← 0
IF n = 0 THEN
count ← 1
ELSE
WHILE n > 0 DO
n ← n DIV 2
count ← count + 1
END WHILE
END IF
OUTPUT "Number of binary digits: ", count
END
m,y,s,o,r,e,c,i,t,y and e,x,a,m,p,l,e and a,l,g,o,r,i,t,h,m do sor ng Inser on Bubble Quick Merge
Selec on sort
Label Characters
1. Mysore ['m','y','s','o','r','e','c','i','t','y']
2. Example ['e','x','a','m','p','l','e']
3. Algorithm ['a','l','g','o','r','i','t','h','m']
Inser on Sort
Mysore ['c','e','i','m','o','r','s','t','y','y']
Example ['a','e','e','l','m','p','x']
Algorithm ['a','g','h','i','l','m','o','r','t']
Bubble Sort
Bubble Sort repeatedly swaps adjacent elements if they’re in the wrong order.
Mysore ['c','e','i','m','o','r','s','t','y','y']
Example ['a','e','e','l','m','p','x']
Algorithm ['a','g','h','i','l','m','o','r','t']
Quick Sort
Mysore ['c','e','i','m','o','r','s','t','y','y']
Example ['a','e','e','l','m','p','x']
Algorithm ['a','g','h','i','l','m','o','r','t']
Merge Sort
Merge Sort divides the list into halves, recursively sorts, and merges.
Mysore ['c','e','i','m','o','r','s','t','y','y']
Example ['a','e','e','l','m','p','x']
Algorithm ['a','g','h','i','l','m','o','r','t']
Selec on Sort
Selec on Sort selects the smallest element and swaps it into place.
Mysore ['c','e','i','m','o','r','s','t','y','y']
Example ['a','e','e','l','m','p','x']
Algorithm ['a','g','h','i','l','m','o','r','t']
Inser on Sort builds the sorted array from le to right by shi ing elements.
Pass 3: [m, o, s, y, r, e, c, i, t, y]
Pass 4: [m, o, r, s, y, e, c, i, t, y]
Pass 5: [e, m, o, r, s, y, c, i, t, y]
Pass 6: [c, e, m, o, r, s, y, i, t, y]
Pass 7: [c, e, i, m, o, r, s, y, t, y]
Pass 8: [c, e, i, m, o, r, s, t, y, y]
Pass 9: [c, e, i, m, o, r, s, t, y, y]
Pass 1: [m, s, o, r, e, c, i, t, y, y]
Pass 2: [m, o, r, e, c, i, s, t, y, y]
Pass 3: [m, o, e, c, i, r, s, t, y, y]
Pass 4: [m, e, c, i, o, r, s, t, y, y]
Pass 5: [e, c, i, m, o, r, s, t, y, y]
Pass 6: [c, e, i, m, o, r, s, t, y, y]
Choose pivot = y
Recurse on [m, s, o, r, e, c, i, t]
Splits the list, sorts each half, and merges them back.
Sort + merge:
→ [m, y] → [m, y]
→ [s, o, r] → [o, r, s]
→ [e, c] → [c, e]
→ [i, t, y] → [i, t, y]
Merge:
→ [m, o, r, s, y]
→ [c, e, i, t, y]
Final merge:
→ [c, e, i, m, o, r, s, t, y, y]
Pass 2: [c, e, s, o, r, y, m, i, t, y]
Pass 3: [c, e, i, o, r, y, m, s, t, y]
Pass 4: [c, e, i, m, r, y, o, s, t, y]
Pass 5: [c, e, i, m, o, y, r, s, t, y]
Pass 6: [c, e, i, m, o, r, y, s, t, y]
Pass 7: [c, e, i, m, o, r, s, y, t, y]
Pass 8: [c, e, i, m, o, r, s, t, y, y]
Pass 1: [e, x, a, m, p, l, e]
Pass 2: [a, e, x, m, p, l, e]
Pass 3: [a, e, m, x, p, l, e]
Pass 4: [a, e, m, p, x, l, e]
Pass 5: [a, e, l, m, p, x, e]
Pass 6: [a, e, e, l, m, p, x]
Pass 1: [e, a, m, p, l, e, x]
Pass 2: [a, e, m, l, e, p, x]
Pass 3: [a, e, l, e, m, p, x]
Pass 4: [a, e, e, l, m, p, x]
Pass 5: [a, e, e, l, m, p, x]
Quick Sort – Trace
Pivot = e
Merge → [a, e, e, l, m, p, x]
Pass 1: [a, x, e, m, p, l, e]
Pass 2: [a, e, x, m, p, l, e]
Pass 3: [a, e, e, m, p, l, x]
Pass 4: [a, e, e, l, p, m, x]
Pass 5: [a, e, e, l, m, p, x]
Pass 6: [a, e, e, l, m, p, x]
Pass 1: [a, l, g, o, r, i, t, h, m]
Pass 2: [a, g, l, o, r, i, t, h, m]
Pass 3: [a, g, l, o, r, i, t, h, m]
Pass 4: [a, g, l, o, r, i, t, h, m]
Pass 5: [a, g, i, l, o, r, t, h, m]
Pass 6: [a, g, i, l, o, r, t, h, m]
Pass 7: [a, g, h, i, l, o, r, t, m]
Pass 8: [a, g, h, i, l, m, o, r, t]
Pass 1: [a, g, l, o, i, r, h, m, t]
Pass 2: [a, g, l, i, o, h, m, r, t]
Pass 3: [a, g, i, l, h, m, o, r, t]
Pass 4: [a, g, h, i, l, m, o, r, t]
Pivot = m
Final: [a, g, h, i, l, m, o, r, t]
Pass 1: [a, l, g, o, r, i, t, h, m]
Pass 2: [a, g, l, o, r, i, t, h, m]
Pass 3: [a, g, h, o, r, i, t, l, m]
Pass 4: [a, g, h, i, r, o, t, l, m]
Pass 5: [a, g, h, i, l, o, t, r, m]
Pass 6: [a, g, h, i, l, m, t, r, o]
Pass 7: [a, g, h, i, l, m, o, r, t]