What is complexity and Big O notation
Two programs can give the same answer and yet one can take a second and the other a year. The difference is almost never how fast…
Learn to write programs that stay fast as the data grows. In this lesson you will see what complexity and Big O notation are, how to measure time with timeit, how to choose the right data structure, how to compare searches and sorts, and how to speed up an algorithm with memoization and dynamic programming.
Two programs can give the same answer and yet one can take a second and the other a year. The difference is almost never how fast…
Theory says what should happen; measuring confirms what really happens. Python includes simple tools to time code, although they…
Often the algorithm is the same and what changes the speed is where you store the data . Knowing the cost of each structure's…
Searching and sorting are the two most repeated tasks in programming, and they are the best showcase for seeing the difference…
Sometimes an algorithm is slow because it repeats the same computation again and again. The solution is to save the result the…
Create a Python program that counts the steps of four kinds of algorithm for several input sizes and shows how each one grows…
Create a Python program that performs a linear search in a list and counts how many comparisons it needs. In the worst case it is…
Create a Python program that performs a binary search in a sorted list and compares how many steps it needs against linear…
Create a Python program that finds the first repeated element of a list. With two nested loops it is O(n²); with a set ( set ) it…
Create a Python program that finds two different positions of a list whose values add up to a target . With two loops it is…
Create a Python program that finds the elements common to two lists and compares the cost of doing it with nested loops (O(n ·…
Create a Python program that sorts a list with the bubble sort algorithm and counts its comparisons and swaps. It is an O(n²)…
Create a Python program that finds the largest sum of consecutive elements of a list, and compares an O(n²) brute-force solution…
Create a Python program that computes the Fibonacci number in two ways and compares how many calls each one makes. The simple…
Create a Python program that computes the fewest coins needed to pay an amount with dynamic programming , and compares it with…