Algorithms Flashcards

1
Q

Fizzbuzz

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Pascals Triangle

A

Triangle of rows of arrays where each cell is the sum of the two cells above it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Needle in Haystack

A

Return the index where needle starts in haystack if it is a substring

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Pivot Index of Array

A

Return the index where the sum of the left is equal to the sum of the right

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Fibonacci w Memoization

A

Return the nth fib digit in linear time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Reverse a LL

A

single or double

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

SLL

A

push, pop, get(index), insert(index, val), delete(index)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

DLL

A

push, pop, get(index), insert(index, val), delete(index)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Binary Search Tree

A

Insert(val), find(val)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Merge Sort

A

Merge function O(n+m), sort O(logn)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Quick Sort

A

O(nlogn)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Stack

A

LIFO

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Binary Heap

A

Min or Max, compact as possible, all left children are filled, then all right children are filled

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Priority Queue

A

Min Binary Heap w Priority for nodes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

BFS Graph Traversal

A

use a queue, shift()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

DFS Graph Traversal

A

Recursive. Explore as far down one path before visiting neighbors

17
Q

Dijktra’s Algorithm

A

shortest path between two vertices

18
Q

Capitalize Words Recursively

A

Given an array of words, return the same array with the words capitalized

19
Q

Hash Table

A

hash function, Map(), separate chaining

20
Q

Queue

A

FIFO

21
Q

Graph

A

add/remove vertex, add/remove edge

22
Q

Binary Search Iterative/Recursive

A

Iterative/Recursive

23
Q

Trie

A

Trie

24
Q

Validate BST

A

recursively

25
Q

Staircase Problem

A

recursively

26
Q

Search a 2D Matrix

A

Integers in each row are sorted in ascending from left to right.
Integers in each column are sorted in ascending from top to bottom.

27
Q

Merge 2 sorted linked lists

A

similar to merging two sorted arrays

28
Q

Deserialize BST

A

construct BST from a string or array

29
Q

Is BST Balanced?

A

abs value of difference in height between subtrees <=1

30
Q

Lowest common ancestor for a BST

A

given root, x node, y node

31
Q

Serialize BST

A

given BST, construct a string

32
Q

Find Min area of rectangle given array of points

A

use a hashmap, find diagonals, calculate area

33
Q

Unique BST given n

A

Cartesean Numbers F(i,n) = G(i-1) * G(n-i)

34
Q

Level Order Traversal of BST

A

use BFS