Trees Flashcards

1
Q

Complete binary tree

A

All levels have are fully filled (each node has 2 children) except possibly last level . The last level is filled left to right.

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

Full binary tree

A

Every node has either 0 or two children. No nodes have 1 child.

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

Perfect binary tree

A

Both complete and full. All leaf nodes at same level. Last level has max number of nodes. Perfect trees rare in interviews and real life, just make sure to not assume a tree is perfect.

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

4 Aspects of a tree:

A

1) root node (theoretically optional, but in the interview this is there)
2) root node has 0+ children nodes
3) children have 0+ children nodes
4) no cycles
(May or may not have order, any data type possible as values)

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

Binary tree:

A

A tree where each node has up to 2 child nodes

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

Binary SEARCH tree

A

A binary tree with a useful property: all left descendants <= n

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

Balanced

A

Does not mean the left and right subtrees are exactly the same size. Just that they’re close enough for log(n) Insert and find. Not max balance!!!

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

3 options for traversing binary search tree

A

Post order, pre order, in-order (see pg 103 of ctci for code of each way. Remember that!)

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

Min heap

A

Complete binary tree where each node is smaller than its children. So the root is the minimum element. Max heap is the same just upside down basically

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

Key operations on a min heap:

A

Insert O(log(n))

Extract_min 0(log(n))

Remember how to do these! Ctci 104

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

Trie

A

Basically stores words in a tree. Can have anywhere from 0 to ALPHABETSIZE+1 children for any node. Used for quick prefix lookups

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

Graph vs tree

A

More general than tree. A tree is a connected graph without cycles.

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

Graph:

A

Collection of nodes with edges between some of them. Can be directed or undirected. Might consist of multiple isolated sub graphs.

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

Ways to represent graphs

A
Adjacency list (most popular): 
Every node stores a list of adjacent      vertices. In undirected, an edge between 2 nodes is stored twice (in each notes adjacency list) 

Adjacency matrices: an NxN Boolean matrix where N is number of nodes. The value at a point indicates if there is an edge from node to node.

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

Graph searches;

A

Bfs, dfs (see ctci and do practice problems with this)

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