Data Structures 7 Flashcards

1
Q

Array: access, search, insert, delete

A

Access: O(1)Search: O(n)Insert: O(n)Delete: O(n)

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

Array: memory

A

Memory: O(n)

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

Array: advantage, disadvantage

A

Advantage: quick insert, quick access if index is knownDisadvantage: slow search, slow delete, fixed size

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

Doubly Linked List: access, search, insert, delete

A

Access: O(n)Search: O(n)Insert: O(1)Delete: O(1)

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

Doubly Linked List: memory

A

Memory: O(3n) (LL: O 2n)

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

Doubly Linked List: advantage, disadvantage

A

Advantage: quick insert, quick deleteDisadvantage: slow search

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

Binary Tree: advantage, disadvantage

A

Advantage: quick search, delete, insertDisadvantage: complex deletion

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

of elements in a binary tree

A

2^(# of rows)

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

Heap: advantage, disadvantage

A

Advantage: quick insert, quick delete, access to largest itemDisadvantage: slow access to all other items

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

Heap Binary Tree: access, search, insert, delete,

A

Access: O(1)Search: O(n)Insert: O (lg n) Best case: sorted arrayDelete: O (lg n)

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

Heap Binary Tree: max-heapify, build-max-heap, heap-sort

A

Max-heapify: O(n)Build-max-heap: O(n)Heap-sort: O(n lgn)

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

Heap Binary Tree: memory

A

Memory: O(n)

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

Heap Binary Tree: definition

A

A binary tree with two additional constraints:Shape - complete treeHeap property - max/min heap

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

Heap Binary Tree: advantage, disadvantage

A

Advantage: fast access, quick insert and deleteDisadvantage: slow search, efficient memory if full

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

Heap-sort: definition

A

Array size doesn’t change, but heap size doesTake off bottom, reshuffle, repeatLess efficient than max-heapify because it sorts from the top instead of the bottom

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

Binary Search Tree: search, insert, delete

A

Search: O(h) / balanced, O(lg n)Insert: O(h) / balanced, O(lg n)Delete: O(h) / balanced, O(lg n)

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

Binary Search Tree: max, min, successor, predecessor

A

Max: O(h)Min: O(h)Successor: O(h)Predecessor: O(h)

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

Binary Search Tree: property

A

value[left[x]] <= value[x]value[right[x] >= value[x]

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

Binary Search Tree: memory

A

Memory: O(n)

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

Binary Search Tree: advantage, disadvantage

A

Advantage: quick search, quick insert and deleteDisadvantage: slower than hash table

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

Height of binary tree

A

number of edges on the longest downward path between the root and a leaflog(n) - complete binary tree

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

Node height

A

number of edges on the longest downward path between node and a leaf

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

Node depth

A

number of edges on the longest downward path between node and the root

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

Tries: advantage, disadvantage, memory

A

Advantage: faster search than a hash table, no collisions, no hash function needed, quick insert and deleteDisadvantage: can take up more space than a hash tableMemory: A LOT - need empty memory for every possibility

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Tries: definition
Key-value storage; a kind of treeKey -not- stored in node, value stored in nodeNode variables : Boolean isNode, String value, array Edges
26
Heap Priority Queue: insert, max, extract max, increase value
Heap-insert: O(lg n)Heap-maximum: O(1)Heap-extract-max: O(lg n)Heap-increase-value: O(lg n)
27
Priority Queue: advantage, disadvantage
Advantage: cheap way to sort priorities, sometimes you want to do things firstDisadvantage: worse at inserting and searching than BST
28
BST Priority Queue: insert, max, extract max, increase valye
BST-insert: O(h)BST-maximum: O(h)BST-extract-max: O(h)BST-increase-value: O(h)
29
Red Black Tree: search, insert, delete
Search: O(lg n)Insert: O(lg n)Delete: O(lg n)
30
Red Black Tree: max, min, successor, predecessory
Max: O(lg n)Min: O(lg n)Successor: O(lg n)Predecessor: O(lg n)
31
Red Black Tree: memory
Memory: O(n)
32
Red Black Tree: height
Height: O(lg n)
33
Red Black Tree: properties
1. Every node is either red or black2. The root is black3. Every leaf (NIL) is black4. If a node is red, then both its children are black5. All simple paths from node to child leaves contain the same # of black nodes
34
Red Black Tree: advantage, disadvantage
Advantage: quick insert, delete, and searchDisadvantage: complex implementation
35
Black height
of black nodes, including nil, on the path from given node to a leaf, not inclusive; any node with height h has black-height >= h/2
36
Dictionary: definition
A data structure that maps keys to values.
37
Direct-access table: definition
An element key k is stored in slot k.
38
Direct-access table: memory
Memory: O(n)
39
Direct-access table: search
Search: O(1)
40
Direct-access table: advantage, disadvantage
Advantage: quick search, quick insert and deleteDisadvantage: lots of wasted memory, keys must be unique, keys should be dense
41
Hash tables: memory
An implementation of a dictionary.Memory: O(n)
42
Hash tables: search, insert, delete
Search: O(1-n)Insert: O(1-n)Delete: O(1-n)
43
Hash collision
two (or more) keys hash to same slot
44
Chaining
make each slot is the head of a linked list
45
ArrayLists: insert
Insert: often O(1), sometimes more
46
ArrayLists: advantages, disadvantages
Advantage: advantages of an array, plus does not run out of spaceDisadvantage: inserting can be slower than an array
47
Stack: definition
Last in, first out.
48
Stack: advantage, disadvantage
Advantage: quick accessDisadvantage: inefficient with an array
49
Graph: definition
Finite set of vertices connected by edges, directed or not.
50
Graph: advantage, disadvantage
Advantage: best models real-world situationsDisadvantage: can be slow and complex
51
Adjacency list: memory
"Memory: O(|V|+|E|) "
52
Adjacency list: add vertex/edge, delete vertex/edge
Add vertex: O(1)Add edge: O(1)Delete vertex: O(|E|)Delete edge: O(|E|)
53
Adjacency list: query for adjacency
Query for adjacency: O(|V|)
54
Adjacency matrix: memory
"Memory: O(|V|^2) "
55
Adjacency matrix: add vertex/edge, delete vertex/edge
Add vertex: O(|V|^2)Add edge: O(1)Delete vertex: O(|V|^2)Delete edge: O(1)
56
Adjacency matrix: query for adjacency
Query for adjacency: O(1)
57
Breadth-first search
Visits the neighbor vertices before visiting the child verticesOften used to find the shortest path from one vertex to another.A queue is usually implemented
58
Depth-first search
Visits the child vertices before visiting the sibling verticesA stack is usually implemented
59
Java stream: definition
a sequence of data
60
Exception handling
When there's an error, the program makes an error object and passes it off to the runtime system, which looks for a method in the call stack to handle it.
61
O(1)
O(1) = happens once
62
O(lg n)
happens for up to the height of a balanced tree
63
O(n)
happens for each element
64
Θ-notation
asymptotically tight bound
65
O-notation
asymptotic upper bound
66
Ω-notation
asymptotic lower bound