Algorithms
An algorithm is a precise recipe for solving a problem. Learn the classic ones โ and, more importantly, how to invent your own.
Same problem, very different amounts of work
If the number of items doubles, how much more work does your algorithm do? That one question is the heart of algorithm design.
O(1)instantO(log n)tinyO(n)fairO(n log n)okayO(nยฒ)slow!
binary-search.pseudo
1BEGIN2 SET LIST = [2, 5, 8, 12, 16, 23, 38]3 SET TARGET = 234 SET LOW = 05 SET HIGH = LENGTH(LIST) - 16 WHILE LOW <= HIGH7 SET MID = (LOW + HIGH) DIV 28 IF LIST[MID] = TARGET THEN9 DISPLAY "Found at", MID10 BREAK11 ELSE IF LIST[MID] < TARGET THEN12 SET LOW = MID + 113 ELSE14 SET HIGH = MID - 115 END IF16 END WHILE17END
๐บ Algorithm lessons (Phase 07)
01
What Is an Algorithm?
02
Linear Search
03
Binary Search
04
Counting
05
Frequency Counting
06
Minimum / Maximum
07
Running Totals
08
Prefix Totals
09
Two Pointers
10
Sliding Window
11
Sorting
12
Selection Sort
13
Bubble Sort
14
Insertion Sort
15
Divide and Conquer
16
Greedy Thinking
17
Recursion
18
Base Case
19
Recursive Case
20
Backtracking
21
Memoization
22
Dynamic Programming Intuition
โ๏ธ Algorithm practice
Easy
Linear search
Given SET LIST = [4, 8, 15, 16, 23, 42], TAKE a TARGET and DISPLAY its index, or…
#Searching
Hard
Bubble sort
Sort SET NUMS = [5, 1, 4, 2, 8] into ascending order using bubble sort (don't use SORT!),…
#Sorting
Hard
Recursive sum
Write a recursive FUNCTION SUM_TO(N) that returns 1 + 2 + โฆ + N.
#Recursion