graphs Flashcards

1
Q

Three different Types of Graphps

A

1) Edge Lists
2) Adjacency Matrixes
3) Adjacency Lists

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

Two most common ways to use graph data structures

A

1) Breadth First Search

2) Depth First Search

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

Edge List B-O

A

O(n)

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

Data structure for Edge List

A

Array
[0,1]
[1,2]

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

Adjacency Matrices B-O

A

O(1)

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

Data structure Adjacency Matrix

A

connect 4 type matrix (maybe battleship)

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

Problem with Adjacency Matrix

A

Takes up a lot of space

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

Problem with Edge List

A

slower

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

Data structure Adjacency Lists

A

Write each of it’s neighbors as a list in an array
0 -> [1,4] // 0 is connected to 1 and 4
1 -> [2] // only one neighbor

(an array of arrays)

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

Adjacency Lists 3 Advantages

A

1) Fast lookup
2) easy to find neighbors
3) Not as large as Adjacency Matrices

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

Edge List (unidirectional)

A

Two array lists

[0,2] [2,0]

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

Adjacency Matrix (unidirectional)

A

Flipped gride (both sides)

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

Adjacency Lists (unidirectional)

A

Just add an other item to array

0 -> [1,4,5] // 0 is connected to 1 and 4
1 -> [2,1] // only one neighbor

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

Breadth First Search (what is it)

A

start in the middle and move outward

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

Breadth First Search what 3 things is it used for?

A

1) Social Graphs
2) Recommendations
3) Nearest Neighbors

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

Depth First Search (what is it)

A

Starts with a node and drives deep and ignores nodes around it. Following it till it hit the end

17
Q

Depth First Search what 3 things is it used for?

A

1) Path Fionding
2) Unique solutions (path remains)
3) Cycle detection in graph

18
Q

Breadth First Search uses what structure?

A

Queue (first in first out) FIFO

19
Q

Depth First Search uses what structure?

A

Stack (First in last out) LIFO

20
Q

interview question: Breadth First (uses)

A
Nearest Neighbor (Social Networks, FB, Linkedin)
nearby peers in games
21
Q

interview question: Depth First (uses)

A

Better way to find things faraway (chess game, paths

22
Q

interview question: Breadth First (tech)

A

Queue (first in first out)

23
Q

interview question: Depth First (tech)

A

Stack (in in last out)