Data Structures & Algorithms Flashcards

1
Q

Stacks - use cases

A

Recursive algorithms - push temporary data to the stack as you recurse and remove as you backtrack (e.g. if the recursive check failed)

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

Queues - use cases

A

Breadth-first search: store nodes we need to process - each time a node is processed, add adjacent nodes to the back of the queue so that they can be processed in the order they’re viewed

Implementing a cache

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

Complete binary tree

A

Every level of the tree is fully filled, except maybe last level (rightmost)

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

Full binary tree

A

Every node has either zero or 2 children, no nodes with only one child

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

Perfect binary tree

A

Both full & complete - all leaf nodes are at the same level, and each level has the max (2) # of nodes

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

In-order tree traversal (binary tree)

A

Visit left branch, then current node, then right branch

Depth first search

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

Pre-order tree traversal (binary tree)

A

Visit current node before child nodes, root is always first

Depth first search

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

Post-order tree traversal (binary tree)

A

Visit current node after child nodes, root is always last

Depth first search

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

Tree

A

Type of graph - connected graph without cycles

Data structure composed of nodes

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

Graph

A

Not all graphs are trees
Collection of nodes with edges between some of them
Directed –> goes one way
Undirected goes both ways
Can consist of multiple isolated subgraphs
Can have cycles, or be acyclic

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

Binary search tree (BST)

A

Not the same as a binary tree
Binary tree in which every node fits an ordering property: all left nodes are smaller than the right node

Clarify: sometimes duplicates aren’t allowed, sometimes they are, sometimes they have a particular ordering property too

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

Balanced vs. unbalanced tree

A

Balanced != exactly perfect, but balanced enough for O(log n) insertion and find

Examples of balanced: red-black trees, AVL trees

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

Connected graph

A

If there’s a path between every single pair of vertices

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

2 ways to represent a graph & which is better

A

Adjacency lists
Adjacency matrices

Which is better? Adjacency lists generally; graph algorithms like BFS done on matrix may be less efficient because you can’t easily reach node neighbours without going through the whole thing

When are matrices better? When edges are weighted, just replace the 1s in the matrix with weighting

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

2 most common ways of doing graph search

A

Breadth First Search (BFS)

Depth First Search (DFS)

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

Breadth first search (BFS)

A

Start at root / given node and traverse each neighbour before going to any children

Go wide before deep

Use: find shortest path / any path between 2 nodes

17
Q

Depth first search (BFS)

A

Start at root / given node and traverse each branch completely before moving to the next branch

Go deep before wide

Use: visit every node in graph

18
Q

Bidirectional search

A

Find shortest path between search & destination node by running 2 simultaneous BFS from each node, finding the path when they collide