Algorithms Flashcards
Fizzbuzz
Print Numbers 1 to N. If a Number is divisible by 3 print fizz, if a number is divisible by 5 print buzz, if a number is divisible by 15 print fizz buzz
Pascals Triangle
Triangle of rows of arrays where each cell is the sum of the two cells above it
Needle in Haystack
Return the index where needle starts in haystack if it is a substring
Pivot Index of Array
Return the index where the sum of the left is equal to the sum of the right
Fibonacci w Memoization
Return the nth fib digit in linear time
Reverse a LL
single or double
SLL
push, pop, get(index), insert(index, val), delete(index)
DLL
push, pop, get(index), insert(index, val), delete(index)
Binary Search Tree
Insert(val), find(val)
Merge Sort
Merge function O(n+m), sort O(logn)
Quick Sort
O(nlogn)
Stack
LIFO
Binary Heap
Min or Max, compact as possible, all left children are filled, then all right children are filled
Priority Queue
Min Binary Heap w Priority for nodes
BFS Graph Traversal
use a queue, shift()
DFS Graph Traversal
Recursive. Explore as far down one path before visiting neighbors
Dijktra’s Algorithm
shortest path between two vertices
Capitalize Words Recursively
Given an array of words, return the same array with the words capitalized
Hash Table
hash function, Map(), separate chaining
Queue
FIFO
Graph
add/remove vertex, add/remove edge
Binary Search Iterative/Recursive
Iterative/Recursive
Trie
Trie
Validate BST
recursively