Data Structures Flashcards

1
Q

Heap

Adventages:

Build time:

Insert:

Get max:

Extract max:

A

Heap

Adventages: quick access to min/max. Can be used to implement priority queue. Heap sort

Build time: O (n)

Insert: O(logn)

Get max: O (1)

Extract max: O (logn)

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

stack

isEmpty:

Push:

Pop:

A

stack

isEmpty: O(1)

Push:O(1)

Pop:O(1)

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

queue

isEmpty:

enqueue:

dequeue:

A

queue

isEmpty: O(1)

enqueue: O(1)
dequeue: O(1)

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

Binary trees

full:

perfect:

complete:

pre/in/post order:

A

Binary trees

full: every inner vertex has exactly 2 children
perfect: a full tree where all leaves are the same depth
complete: obtained from a perfect tree by removing sequential leaves from the right.

pre/in/post order: root-left-right / left-root-right / left-right-root

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

Binary search Trees

search:

getMin/Max:

insert/remove:

select:

rank:

A

Binary search Trees

search: O(logn)

getMin/Max: O(logn)

insert/remove: O(logn)

select: given a tree and index i, return node x s.t x is the i’th element in size in the tree O(logn)
rank: given a tree and node x, return index i s.t x contains the i’th element in size in the tree O(logn)

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

Hash Tables

advantages:

Insert:

Search:

Delete:

simple uniform hashing -

A

Hash Tables

advantages: allows quick insert/search/delete operations

Insert: O(1) for simple uniform hashing

Search: O(1) for simple uniform hashing

Delete: O(1) for simple uniform hashing

assuming simple uniform hashing - meaning the table size is O(m), m~n, and the probability of each value to fall into any of the cells is uniform.

alpha = n/m is called the load factor and indicates the amount of values per cell.

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

Trie

advantages:

search:

A

Trie

advantages: used to manage a group of strings and allow quick information retrieval. can be used for autocomplete for example.

search : O(dm) where d is the size of the alphabet (generally constant) and m the hight of the trie, i.e the length of the longest word contained in it.

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

maximal number of edges for undirected graph:

maximal number of edges for directed graph:

A

maximal number of edges for undirected graph: n(n-1)/2

maximal number of edges for directed graph: n2

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

adjacency list

list[v] contains list of all of v’s neighbors

size:

is neighbor(u,v):

isEdge(u,v):

Allneighbors(u):

A

adjacency list

size: O(V+E)

is neighbor(u,v): O(deg u)

isEdge(u,v): O(deg u)

Allneighbors(u): O(deg u)

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

adjacency matrix

mat(i,j) = 1 if (i,j) in E, 0 otherwise

Size:

isNeighbor(u,v):

isEdge(u,v):

Allneighbors(u):

A

adjacency matrix

Size: O(V2)

isNeighbor(u,v): O(1)

isEdge(u,v): O(1)

Allneighbors(u): O(V)

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

weighted graph - description and representations

A

G= (V,E,W) is a graph where each edge has a weight associated with it.

it can be represented by an expanded adjacency list/matrix:

list: each edge in the list contains its weight
matrix: instead of containing binary values, the number in each cell contains the weight of the edge (or 0 if it doesnt exist, as before).

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

explain the data structure and implimintations

A

used for storing sets. has a make-set, find-set and union functions. can be implemented using a list (or hashmap) of linked-lists or as a list of trees. each item in the set contains a pointer to that set’s representative.

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