Learning algorithms

In the next sections we will study various algorithms and techniques asked in interview problems. But before we dive in, let's discuss how to actually study algorithms.

Learning a particular algorithm for the first time always takes time, so don't rush it. Be sure you understand the core principles of the algorithm you are studying. Try to write your own code from scratch. Ask questions like: why is this algorithm needed? What are its defining characteristics, how is it different from other algorithms? When is it useful and why?

Where to study algorithms?

Thankfully, there are a lot of resources available for studying algorithms. Often, to find what you need it's enough just to check Wikipedia or do a quick Google search.

Here are some more great resources I recommend:

  • Introduction to Algorithms by Cormen, et al – probably the best book on algorithms. It's very precise, mathy and dives deep into the heart of algorithms. When you want to deeply understand some topic in and out, this is the best resource for it.
  • Competitive Programmer’s Handbook by Antti Laaksonen – targeted for competitive programming, this book gives very succinct and clear explanations of many common algorithms used in the interview questions as well. Also, unlike Introduction to Algorithms, that provides only a pseudocode of algorithms, Competitive Programmer’s Handbook contains clean working implementations in C++ for a lot of algorithms it describes.

    The book is available free online. Also it has a companion set of problems, that you can try if you are feeling adventurous :)
  • Cracking the Coding Interview by Gayle McDowell also has a lot of nice descriptions of interview problems and algorithms.
  • CP-Algorithms.com provides detailed descriptions and implementations for a lot of algorithms, especially harder ones.

Solve problems

Of course, the best method to learn algorithm is to learn how to use it. For this, practice the algorithm on various related problems. You can find recommended problems for each topic in the next sections.