Graphs, trees, hash tables(1.4.2 b) Flashcards

1
Q

What are the three parts of trees?

A

root nodes
nodes
edges/pointers

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

How many ways in a tree to get from root to subnodes?

A

one way

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

Tree diagram

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

How many children do binary trees have?

A

only two

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

Binary tree

A

all other regular trees apply
every node having two children we terminate the tree at a leaf node

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

Binary tree

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

Uses of binary trees

A

searching algorithms
sorting algorithms
compression algorithms

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

What are the two parts of graphs?

A

nodes
edges/pointers

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

Graphs

A

edges can be weighted, be directed, create cycles
doesn’t have a root node
when using graphs we must define where to start traversing from

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

How does a traversal differ from a search?

A

returns all values in the tree

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

What does a search return?

A

only value searching for or not found

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

Breath first traversal

A

goes from root node and goes down line by line
will print out on order starting at root node and reading nodes from left to right top to bottom

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

Breath first traversal diagram

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

Depth first traversal

A

start at root node and go left to next node until leaf node then goes back up to next unexplored node

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

Depth first pre order search

A

reads nodes as first hits its

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

Depth first pre order search diagram

17
Q

Depth first in order search

A

returns node after all left tree explored

18
Q

Depth first in order search diagram

19
Q

Depth first post order search

A

return node after all children have been explored
always ends with root

20
Q

Depth first post order search diagram

21
Q

What is hash?

A

refers to a hashing algorithm an irreversible process

22
Q

Hashing

A

irreversible
used for hashtables and cryptography
maps arbitary data to a fixed size output
similar inputs provide a very different output

23
Q

What is collsion in hashing?

A

sometimes different inputs can result in the same output

24
Q

How hashtables work

A

each key value is hashed by going in a hashing algorithm
the result of the hash algorithm turns into the list index of the relevant value

25
Q

Hashtable diagram

26
Q

Why do we use hashtables

A

no need to search through the array (as arrays get bigger searching takes a lot longer)
however we trade time for memory usage (unused space)

27
Q

Hashtable collisions

A

biggest difficulty dealing with hashtables

28
Q

Linear probing

A

put the data in the next available space
when we are searching for a value that has collided we search down the table until we find the value we’re looking for

29
Q

Chaining

A

each item in the hashtable is part of a linked list
we traverse the linked list until we find what we’re looking for

30
Q

Overflow table

A

if we detect a collision we search an overflow table
place/find the item in the first available space of the overflow table

31
Q

Choice of hash algorithm

A

poor hashing algorithm = lots of collision
if have lots of collisions we must spend precious time searching for the actual value
good hash algorithms take more computation time (and usually have many more possible outputs meaning hashtable is bigger)