Skip to content

Commit

Permalink
Updated Notes
Browse files Browse the repository at this point in the history
  • Loading branch information
SuyashLakhotia committed Oct 24, 2017
1 parent c334526 commit a4e27d7
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 13 deletions.
5 changes: 4 additions & 1 deletion 2 - Algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@

## Dynamic Programming

Dynamic programming is a general method for solving a problem with optimal substructure by breaking it down into overlapping subproblems.
Dynamic programming is a general method for solving a problem with *optimal substructure* by breaking it down into *overlapping subproblems*.

- A problem exhibits *optimal substructure* if an optimal solution to the problem contains within it optimal solutions to subproblems. Additionally, the solution to one subproblem should not affect the solution to another subproblem of the same problem.
- A problem has *overlapping subproblems* when a recursive solution revisits the same problem repeatedly.

**Top-Down:** Memoize (store) the solutions to subproblems and solve problem recursively.

Expand Down
4 changes: 2 additions & 2 deletions 2.2 - Sorting Algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void quicksort(int[] arr, int low, int high) {
- After `i` iterations, the last `i` elements of the array are sorted.
- Sorts in-place. Not stable.<sup>[1](#footnote1)</sup>

### Binary Heap
### Binary Heap (Array Implementation)

- We can implement a binary heap with `n` nodes using an array with the following conditions:
- The left child of `nodes[i]` is `nodes[2i + 1]`.
Expand All @@ -233,7 +233,7 @@ void quicksort(int[] arr, int low, int high) {
void heapSort(int[] arr) {
int n = arr.length;

// Construct initial heap (rearrange array)
// Construct initial max-heap (rearrange array)
for (int i = n / 2 - 1; i >= 0; i--) {
heapify(arr, n, i);
}
Expand Down
8 changes: 4 additions & 4 deletions 2.4 - Pathfinding Algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Dijkstra's Algorithm (Adapted from [Wikipedia](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm), [GIF](assets/Dijkstra.gif))

- Finds the shortest path from a start node to a goal node in a positive weighted directed graph that may have cycles.
- Finds the shortest path from a start node to a goal node in a weighted, directed graph with non-negative edge weights.

1. Assign every node a tentative distance value. Zero for the start node and infinity for all other nodes.
2. Set the start node as current. Mark all other nodes unvisited. Create a set of all the unvisited nodes.
Expand Down Expand Up @@ -72,7 +72,7 @@ Generally, Dijkstra's algorithm takes `O(|E| * T_dk + |V| * T_em)` where `T_dk`

## A* Search Algorithm (Adapted from [Wikipedia](https://en.wikipedia.org/wiki/A*_search_algorithm))

- Finds the shortest path from a start node to a goal node in a positive weighted directed graph that may have cycles.
- Finds the shortest path from a start node to a goal node in a weighted, directed graph with non-negative edge weights.

The A* search algorithm is based on minimizing:

Expand Down Expand Up @@ -141,7 +141,7 @@ where `b` is the branching factor (i.e. average number of successors per state)

## Bellman-Ford Algorithm (Adapted from [Wikipedia](https://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm))

- Finds the shortest path from a single source node to all the other nodes in the graph. If there is a negative weight cycle, then the shortest distances are not calculated and the cycle is reported.
- Finds the shortest path from a single source node to all other nodes in a weighted, directed graph, where edge weights may be negative. If there is a negative weight cycle, then the shortest distances are not calculated and the cycle is reported.

1. Initialize distance for all nodes as infinite, except the source node, which is initialized as zero.
2. Repeat the following `|V| - 1` times:
Expand Down Expand Up @@ -208,7 +208,7 @@ O(|V| |E|)

## Floyd-Warshall Algorithm (Adapted from [Wikipedia](https://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm))

- Finds the shortest paths between all pairs of nodes in a graph with no negative weight cycles.
- Finds the shortest paths between all pairs of nodes in a weighted, directed graph, where edge weights may be negative but there are no negative weight cycles.

1. Initialize the solution matrix as the same as the input graph matrix i.e. the shortest paths are initialized as the paths with no intermediate nodes.
2. For every node `k`, consider it as the intermediate node for a path between `u` & `v`. Then, either:
Expand Down
4 changes: 2 additions & 2 deletions 2.5 - Other Graph Algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Prim's Algorithm (Adapted from [Wikipedia](https://en.wikipedia.org/wiki/Prim%27s_algorithm), [GIF](assets/Prim.gif))

- Finds a minimum spanning tree for a weighted undirected graph.
- Finds a minimum spanning tree for a weighted, undirected graph.
- A minimum spanning tree is a subset of the edges that forms a tree, which contains every vertex, where the total weight of all the edges in the tree is minimized.

1. Create a set `mstSet` that keeps track of the vertices already included in the MST.
Expand Down Expand Up @@ -46,7 +46,7 @@ int[] primMST(int graph[][]) {

## Kruskal's Algorithm (Adapted from [Wikipedia](https://en.wikipedia.org/wiki/Kruskal%27s_algorithm), [GIF](assets/Kruskal.gif))

- Finds a minimum spanning tree for a weighted undirected graph.
- Finds a minimum spanning tree for a weighted, undirected graph.

1. Create a graph `F` (a set of trees), where each vertex of the input graph is a separate tree.
2. Create a set `S` containing all the edges of the graph.
Expand Down
12 changes: 12 additions & 0 deletions 8 - Miscellaneous.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@
- `n! / ((n - k)!)`: Permutations of `n` items taken `k` at a time.
- `n! / (k! (n - k)!)`: Combinations of `n` items taken `k` at a time.

### Probability

```
P(A and B) = P(B | A) P(A)
P(A or B) = P(A) + P(B) - P(A and B)
P(A and B) = P(A) P(B) // if A & B are independent
P(A or B) = P(A) + P(B) // if A & B are mutually exclusive
P(A | B) = (P(B | A) P(A)) / P(B)
```

## Internet

### HTTP Methods
Expand Down
1 change: 1 addition & 0 deletions References.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This repository really doesn't do justice to these great resources and is in no

- Computer Science Courses @ Nanyang Technological University, Singapore
- [Cracking the Coding Interview, 6th Edition - Gayle Laakmann McDowell](https://www.amazon.com/Cracking-Coding-Interview-Programming-Questions/dp/0984782850)
- Introduction to Algorithms, 3rd Edition - Cormen et. al
- [Hacking a Google Interview Handouts](http://courses.csail.mit.edu/iap/interview/Hacking_a_Google_Interview_Handout_1.pdf)
- [Big O Cheat Sheet](http://bigocheatsheet.com/)
- [GeeksforGeeks](http://www.geeksforgeeks.org/)
Expand Down
14 changes: 10 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
- Bipartite Graph
- Elaborate Self-Balancing BSTs

- Databases

- Regular Expressions

- Networking Fundamentals
- TCP/IP, OSI
- Internet, HTTP, Basics of Search

- Complexity Theory
- P, NP & NP-Complete

- Math
- Prime Numbers, Sieve of Eratosthenes

- Regular Expressions

- Databases
- Fundamentals
- SQL

0 comments on commit a4e27d7

Please sign in to comment.