Data Structures Flashcards

1
Q

Linked List

(def., positioning, what are they used for, how to invoke)

A

a collection of nodes where each node contains a data field and a reference (link) to the next node in the list

unlike normal list (arrays) elements do not have objective positions in the list, instead they have a relational postition based on surrounding nodes

used to create graphs and trees, data strucutres that require frequent addition/deletion

invoked in python by creating a Node class

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

Hash Table

(def, use case)

(object in js, dictionary in python)

A

data structure of key(index), value pairs

lookup up values by the key, not their location in the data structure

good for optimizing a problem, nested loop

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

Big O for Arrays (List)

A

lookup: O(1)

push: O(1)

pop: O(1)

insert: O(n) - iterate through

delete: O(n) - iterate through

prepend: O(n) - iterate through

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

Pros & Cons of Array (List)

A

Pros

  • fast lookup
  • fast push/pop
  • ordered

Cons

  • slow insert, delete, append at beginning
  • static arrays: fixed size
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Big O for Hash Table (Dictionary)

A

insert: O(1)

lookup: O(1) : sometimes O(n) when collision occurs

delete: O(1) : not ordered so no shifting

search: O(1)

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

Pros & Cons for Hash Tables

A

Pros

  • fast access O(1), but more memory required O(n)
  • fast lookups and inserts

Cons

  • unordered
  • collision: key has more than one value (data element)
    • slows down insert & delete O(n)
  • for loops, loop the entire memory space
    • arrays only loop through the size of the data strucutre
    • slow key insertion
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Common Approach to Handling Hash Table Collision

what is the big O notation?

A

create a linked list for the additional value (data element)

O(n) insert and delete

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

Big O for Linked List

A

prepend: O(1)

append: O(1)

lookup: O(n)

insert: O(n)

delete: O(n)

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

Doubly Linked List

(definition)

A

pointers to the next a previous nodes

traversal forwards a backwards

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

Pros (4) & Cons (3) Linked List

(Single & Double)

A

Pros

  • inserts and deletes are faster than arrays
  • size is more flexible than an array (arrays double in memory once size hits a certain threshold)
  • although not indexed, items are sorted unlike hash tables
  • can be used to handle hash table collision

Cons

  • iterating through linked list is sometimes slower than arrays becuase nodes are scattered over memory
  • in single linked list, you can only traverse in one direction
  • for doubly linked list, it requires more memory becuase of the two way traversal
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Array (List)

(def., types of data it can hold, memory footprint)

A

most straight forward type of data structure

a data structure that contains a group of elements

can hold almost any type of data

smallest memory footprint

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

Pros (2) & Cons (3) of Doubly Linked List

A

Pros

  • traverse forwards and backwards, unlike single linked list
  • lookup faster

Cons

  • delete and insert, slower than singly linked list
  • requires more memory than singly linked list
  • more complex to implement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Stacks & Queues

(def., ex.)

A

Stacks

LIFO: last item in is the only element you can access

Examples:

  • undo button on phone/ms word
  • function calls: inner most function (last written) first called
  • browser history: backwards to the previous page

Queues

FIFO: first item in is the only elment you can access

Examples:

  • uber ride: first person requesting ride is the first serviced
  • printing: first request, first printed
  • waiting in line: first in line, first serviced
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Big O Stacks & Queues

A

Stack: Big O

lookup: O(n) - available although not often used

pop: O(1)

push: O(1)

peek: O(1) - view top item in the stack

Queue: Big O

lookup: O(n) - available although not often used

enqueue (similar to prepend): O(1)

dequeue (pop from the beginning): O(1)

peek: O(1) - view bottom item in queue

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

Trees

def. & nodes (4)

A
  • hierarchical relational data structure
  • nodes, pointers, & data
  • linked list, except nodes only point to children

nodes

parent: root node

child: descends from parent

sibling: child node belonging to same parent

leaf: ending node that has no children

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

Binary Tree/Binary Search Tree (bst)

(prop. & rules)

A

properties

  • parent can only have two children
  • child can only have one sibling
  • half of all nodes are on the bottom level

bst rules

  • all children to right > in vlaue than parent
  • all children to left < in value than parent
17
Q

Big O BST

A

lookup: O(log N)

insert: O(log N)

delete: O(log N)

18
Q

Pros (4) & Cons (2) of BST

A

Pros

  • preserves relationships unlike hash tables
  • search & lookups are fast
  • balanced tree has good performance: O(log N) all operations
  • flexible size

Cons

  • no O(1) operations, not fastest for any specific operations
  • unbalanced: bst can become linked list if you create children with no siblings, O(n) for some methods
19
Q

Heaps

(def., common use cases, 2 types of binary heaps)

A
  • can be used in any algorithmn when ordering is important
  • created using left to right insertion
  • common uses: priority queue, sorting, data storage

binary heaps: 2 types

max heap: root has largest value and all subsequent children ‘s value is less than their parent

mix heap: root has smallest values and all subsequent children’s values is greater than their parent

20
Q

Big O for Heaps

A

lookup: O(n) - less order compared to bst

insert: O(log N)

delete: O(log N)

find min/max: O(1)

21
Q

Pros for Heaps

Define Priority Queue

A

Pros

  • good for comparative evaluation: ex. find all values greater than some other value
  • least amount of memory possible
  • flexible size

Priority Queue

each data element has a priority compared to others

ex.: line at a night club, VIPs show up late still go in first

22
Q

Tries

(def., what is it optimized for, big O)

A
  • specific type of tree used for searching text data
  • outperforms bst for text searches
  • benefits
    • fast processing
    • small memory space
  • big O
    • O(word length) : O(n)
23
Q

Graphs
(3 points for now)

A
  • non-linear: vertices and edges (nodes and lines)
  • no hierarchical relationship (no root node) - network model
  • loops are allowed in graphs
24
Q

Traversal (Graphs v. Trees)
(might move to algorithm cards)

A

Graph Traversal: breath-first search, depth-first search

Trees: pre-order, in-order, post-order