In this assignment you’ll learn all about efficient code and how to make your own code more efficient. Specifically we’ll introduce the big O notation, which can be used to describe how efficient some piece of code is, and we’ll cover some Python data structures that’ll help make your code more efficient.
These data structures, like dictionaries and sets, can be very useful when writing code in general, but they really shine when making code more efficient. To highlight this, we’ll also show an example of how code can be made more efficient using these structures.
For the assignment, you’ll have to write an indexing system that can search through book texts to find specific words. This program will have to search through large collections of text fast, so it should also be efficient.
Part 1: Learn about computational complexity
Part 2: Data structures and their efficiency
Learn about dictionaries: dictionaries
Learn about tuples: tuples
Learn about sets: sets
Learn about list slicing and indexing: slicing
Part 3: How to write efficient code
Part 4: Write your own efficient code
Assignment Indexing words (assignment): word-index
Assignment Indexing pairs (assignment): pair-index