Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Euclidean GCD Lab
Math
Problem shape
Beginner
4
8
15
16
23
42
Core idea
Repeatedly replace the larger number with its remainder.
Step 1 / 5
Problem shape
Math Beginner
Euclidean GCD
Welcome to the Euclidean GCD algorithm lab. Repeatedly replace the larger number with its remainder. Use it when: Use for divisibility, fractions, modular math, and number theory basics. The time complexity is O(log min(a, b)), and the space complexity is O(1). The pseudocode is: while b != 0 temp = a % b a = b b = temp return a As you practice, track the state that changes and the condition that makes the algorithm stop.
Time
O(log min(a, b))
Space
O(1)
Pseudocode
while b != 0
temp = a % b
a = b
b = temp
return a 1.0x