Graphs, trees, hash tables(1.4.2 b) Flashcards

(48 cards)

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

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

Depth first in order search

A

returns node after all left tree explored

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

Depth first in order search diagram

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

Depth first post order search

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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 collision 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
Hashtable diagram
26
Why do we use hashtables
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
Hashtable collisions
biggest difficulty dealing with hashtables
28
Linear probing
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
Chaining
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
Overflow table
if we detect a collision we search an overflow table place/find the item in the first available space of the overflow table
31
Choice of hash algorithm
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)
32
What are linked lists made up of?
nodes each node has two parts data and pointers pointers identify the next node in the list
33
What is contiguous data?
data stored together in memory
34
Linked lists stored
not stored in contiguously more efficient as it means that items from the list can be stored wherever they fit rather than waiting for a contiguous block of memory to become available
35
Linked list example
location | 1 | 2 | 3 | 4 | 5 node | (a, 1) | (b, 4) | (e, null) | (c, 4) | (d, 2)
36
Doubly linked list
pointers for both next and previous items in the list
37
Circular linked list
last item points to the first item
38
Circular doubly linked list
last item points next to the first item and the first item points previous to the last item
39
Adding to linked list
check that there is enough room in memory to create a new item if not return a error message create a new node containing the data to be added in the next available space traverse the list from the start pointers until the point where the item is to be inserted adjust the pointers so that the previous node points to the new node and the new node points to the next node
40
Removing from a linked list
check the lost is not empty if it is return an error message traverse the linked list until the node to be deleted is found if the required node is not found return an error message adjust the pointer of the previous node to be the new node and the pointer of the deleted node to be null set the first free space pointer to the item to be deleted this indicates that it can be overwritten
41
What is a stack?
a form of linked list that is only accessible at one end at the top
42
Stack
each element in the stack has next pointer to the element below it needs a top pointer (point to the item at the top or the first free space before that item) FILO/LIFO (first in last out/last in first out)
43
What is pushing - stack?
adding to the top of the stack
44
What is popping - stack?
removing items from the top of the stack
45
What is a queue?
a form of linked list that is only accessible of tow locations front and back
46
Queue
each item has a next pointer pointing to the item after it/behind it needs two pointers a front pointer which points to the first node/element and a back pointer which points to ither the last node or the next free space
47
What is enqueue - queue?
can only add items to the back
48
What is dequeue - queue?
can only remove items from the front