Data Structures Flashcards

1
Q

Linked List

A

Points to first [and last] linked nodes. If a Doubly Linked List, it can iterate in either direction.

Pros:
- insert/remove from start/end/middle—if you have a node reference—is always O(1)

Cons:

  • arrays iterate faster (though not much different in JS since they’re hash tables)
  • random read/writes are O(n) whereas arrays are O(1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Node

A

Simple object that contains data and a reference to the next Node (or null if there isn’t one).

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

Hash Table

A

Arrays & Objects in JS are Hash Tables, so our desire is only to understand their pros/cons:

Pros:

Cons:

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

Queue

A

FIFO.

Operations: Add to the end of a list and extract the first from the list (like a line) w/ O(1) performance. LinkedList are great for this (whereas arrays have shift as O(n))

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

Stack

A

LIFO.

Operations: Add to end of list and extract the last from list w/ O(1) performance. JS Arrays are great for this.

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

Deque

A

Same as Queue but can add/remove from either direction.

Operations: Add to start/end of list and extract from start/end of list w/ O(1) performance. LinkedLists are great for this (whereas arrays have shift/unshift as O(n))

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

Trees & Balanced Trees

A

Unlike linear data structures like Array or LinkedList, Trees allow you to find a value in less steps than iterating a linear data structure. Balanced trees ensure that the max number of steps stays balanced across the tree.

Pros:
- faster searching

Cons:

  • more complex to implement
  • removing is no trivial matter, and can be slower than linked lists
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Graphs

A

Graphs are a set of vertices (points on the graph; singular word is vertex) and edges (connections between vertices). A path on a graph is a chain of vertices connected by edges, equivalent to a route on a map.

By traversing the graph, we can determine the path.

BFS—breadth first search—visits neighbors of each vertex before moving on to the next vertex. This is done using a queue containing the next vertex.

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