Caching
What is Caching?
Caching is a method in Competitve Programming in which you store data so you can access it later faster. For example, you might have a function that takes a number and does lots of different operations to the number. Obviously, just running this function will take some time, so you might use a cache method. Basically, you will store the values of what the function returns in a dictionary so the function can access these values without actually running the operations.
Caching Methods
There are many methods of caching but the main one is storing values in a dictionary and making the keys the parameters you pass into a function. For example, a web browser will cache the HTML for a site when you visit it so it can be accessed faster the next time you visit the page. Because cached items are stored in a dictionary, you can easily remove cached items if you want to.
Using Cache Methods
There are many different cache methods but the main one for Competitve Programming is called Memoization, which we'll learn about in the next tutorial.