Algorithms Guide
Resources, Notes, Videos, Solutions
2022
This document provides a complete guide to understanding data structures and
algorithms in computer science. It contains a collection of information compiled by
people who have successfully completed interviews at FAANG companies as well
as a useful information, tips, graphics, etc. to help better understand the subject
matter and be a better coder or to ace that interview.
This guide is provided to you with the mission of making the world’s resources
more accessible to all.
Enjoy!
, BlockTrain.info
Table of Contents
The document is divided as follows.
Table of Contents………………………………………………………………………………………………….………………………..………………2
Complete Data structures and Algorithms Roadmap......................................................................................... 3
Our Aim........................................................................................................................................................3
Practice.........................................................................................................................................................3
Arrays................................................................................................................................................................... 4
Introduction ................................................................................................................................................. 4
Hash maps, tables ........................................................................................................................................ 4
2 Pointers ............................................................................................................................................................. 5
Linked List.............................................................................................................................................................9
Sliding Window.................................................................................................................................................. 13
Binary Search ..................................................................................................................................................... 18
Recursion............................................................................................................................................................25
Backtracking....................................................................................................................................................... 32
BFS, DFS.............................................................................................................................................................. 40
Dynamic Programming ...................................................................................................................................... 52
Trees................................................................................................................................................................... 63
Graphs................................................................................................................................................................ 70
Topological Sorting ............................................................................................................................................ 81
Greedy Algorithms............................................................................................................................................. 85
Priority Queue....................................................................................................................................................88
Tries.................................................................................................................................................................... 93
Additional Topics ............................................................................................................................................... 96
Kadane’s algorithm.....................................................................................................................................96
Djikstra’s algorithm....................................................................................................................................97
AVL Trees....................................................................................................................................................98
Sorting........................................................................................................................................................99
More...........................................................................................................................................................99
Additional Awesomeness .................................................................................................................................. 99
2
, BlockTrain.info
- Enjoy the process and start today. I’m sure you’ll do great. Have fun.
Arrays
Introduction
⭐ Informally, an array is a list of things. It doesn’t matter what the things are; they can be
numbers, words, apple trees, or other arrays. Each thing in an array is called an item or
element. Usually, arrays are enclosed in brackets with each item separated by commas, like
this: [1, 2, 3]. The elements of [1, 2, 3] are 1, 2, and 3.
- Introduction to Arrays
- https://www.cs.cmu.edu/~15122/handouts/03-arrays.pdf
- An Overview of Arrays and Memory (Data Structures & Algorithms #2)
- What is an Array? - Processing Tutorial
Arrays are used with all different types of data structures to solve different problems, so it’s kind
of hard to come up with array questions with just an array logic. Let’s discuss some of the most
famous patterns which concern arrays most of the time.
2D matrices are also arrays and are very commonly asked in interviews. A lot of graph, DP, and
search based questions involve the use of a 2D matrix and it’s important to understand the core
concepts there. We’ve discussed the common patterns in each section below so make sure to
check that out.
Hash maps, tables
⭐ A hash table is a data structure that implements an associative array abstract data type, a
structure that can map keys to values. In other words, we can store anything in the form of key
value pairs.
Example: map<string, string>, means that this is a hashmap where we store string key and
value pairs.
4
, BlockTrain.info
Resources
- Hashmap and Map Powerful Guide
- Data Structure and Algorithms - Hash Table
- Leetcode discuss: Hashtable implementation
Questions
- 1. Two Sum
- 771. Jewels and Stones
- Leetcode : How Many Numbers Are Smaller Than the Current Number
- Partition Labels
_______________________________________
_______________________________________
2 Pointers
⭐ For questions where we’re trying to find a subset, set of elements, or something in a sorted
array -> 2 pointers approach is super useful.
5