New answers tagged teaching
Calculating fibonacci numbers. The obvious algorithm is to just implement its recursive mathematical definition as code, and that's O(phi^n). There's a linear algorithm using a straightforward for loop that's O(n), and a O(log n) algorithm that uses a formula for fib(2*n). You could let him sit at a REPL and calculate fib(n) for various n using ...
Compare a linear to a binary search. Linear search has O(n) time complexity vs O(log n) for the binary search. For a large example, such as finding the definition of a word in a dictionary, the time difference will be enormous, and both algorithms can be easily carried out by hand.
Top 50 recent answers are included