Algorithms and Data Structures Fundamentals Cheat Sheet
Algorithms and Data Structures Fundamentals Cheat Sheet
STRUCTURES FUNDAMENTALS
structure where it's stored. Sorting examples: mergesort, quicksort, bubble sort,
selection sort, and insertion sort. Searching examples: linear search and binary search.
Graph algorithms
Solve problems of representing graphs as networks. A graph is an abstract notation that
represents the connection between all pairs of objects.
Algorithm: A series of well-defined instructions that tell a computer
Shortest path algorithms
what to do to solve a problem. Algorithms are applied to data structures. Find the shortest path in a graph. Many sorting algorithms exist. An algorithm is selected
based on the type of data, its size, and the user application.
COMPLEXITY AND CORRECTNESS CONCEPTS Data structures: Formats for the organization, management, and
Asymptotic time complexity storage of data that enable efficient access and modification.
A platform- and input-independent analysis that computes the exact running time of an algorithm.
It tells us how a program performs as the size of input grows regardless of the underlying machine.
Big O is used to represent the upper bound, Big Omega is used to represent the lower bound, and Array
Big Theta is used to represent the tight bound of running time. A collection of items of the same variable type that are stored sequentially in memory.
Best suited for retrieving data in a constant time (using index) but don't provide fast data
Time complexity of recursive algorithms insertion or deletion.
Can be computed using the substitution method, Master's theorem, or recursion tree.
Linked list
Asymptotic space complexity A linear sequence of nodes linked together. In a singly linked list, each node contains a
An analysis of how much memory an algorithm takes. value and a pointer to the next node in the list. Linked lists provide faster data insertion
and deletion but slower data retrieval compared to arrays.
Correctness proof techniques
Used to prove that a given algorithm is correct and will always produce the intended output. The Tree
most common and widely used technique is loop invariant, which is based on mathematical A non-linear data structure often used to represent hierarchical data.
induction.
Stack
DESIGN TECHNIQUES A linear structure with last-in, first-out (LIFO) order. Imagine a stack of plates. The last
plate placed on top of the stack is the first taken out.
Brute force
Requires going through all possibilities to find a solution to a problem. The least efficient method Queue
and one that mostly doesn't provide the desired solution in a feasible time. A linear structure with first-in, first-out (FIFO) order. Imagine lining up for a roller coaster.
The first people who line up leave the line for the ride first.
Divide and conquer
Breaks a problem into smaller subtasks that are then solved using recursion and eventually Graph
reassembled. Recursion is the practice in which a function calls itself directly or indirectly. Examples An abstract notation that represents the connection between all pairs of objects.
include merge sort and quicksort.
Hash table
Dynamic programming A structure implemented by storing elements in an array and identifying them through a
Similar to divide and conquer. Divides a big problem into small subtasks and combines their key. A hash function takes in a key and returns an index for which the value is stored.
solutions. Unlike divide and conquer, a subtask may overlap with other subtasks. To reduce
running time, results of each subtask are saved in memory, a process called memoization. Heap
An advanced tree-based data structure used primarily for sorting and implementing
Greedy priority queues.
A solution for each subtask is attempted using the best available local solution, called local optima.
This approach yields optimal results only when local optima leads to the global optima, the best
possible global solution.