Top Banner
Exam review CS 261 Lab #10
144

Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Mar 20, 2018

Download

Documents

vankhanh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Exam reviewCS 261 Lab #10

Page 2: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

The exam will be comprehensive(so don’t forget to review the midterm slides!)

Similar style as midterm (multiple choice, matching, true/false, code)

This review will focus on trees, heaps, hash tables, and graphs

Page 3: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Draw a complete binary search tree that contains the following letters:

A, B, C, D, E, F, G, H, I, J, K

Page 4: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Draw a complete binary search tree that contains the following letters:

A, B, C, D, E, F, G, H, I, J, K

Page 5: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Draw a complete binary search tree that contains the following letters:

A, B, C, D, E, F, G, H, I, J, K

A

Page 6: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Draw a complete binary search tree that contains the following letters:

A, B, C, D, E, F, G, H, I, J, K

A

B

Page 7: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Draw a complete binary search tree that contains the following letters:

A, B, C, D, E, F, G, H, I, J, K

A

B

C

Page 8: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Draw a complete binary search tree that contains the following letters:

A, B, C, D, E, F, G, H, I, J, K

A

B

C

D

Page 9: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Draw a complete binary search tree that contains the following letters:

A, B, C, D, E, F, G, H, I, J, K

A

B

C

D

E

Page 10: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Draw a complete binary search tree that contains the following letters:

A, B, C, D, E, F, G, H, I, J, K

A

B

C

D

F

E

Page 11: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Draw a complete binary search tree that contains the following letters:

A, B, C, D, E, F, G, H, I, J, K

A

B

C

D

F

E G

Page 12: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Draw a complete binary search tree that contains the following letters:

A, B, C, D, E, F, G, H, I, J, K

A

B

C

D

F

H

E G

Page 13: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Draw a complete binary search tree that contains the following letters:

A, B, C, D, E, F, G, H, I, J, K

A

B

C

D

F

H

E G

I

Page 14: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Draw a complete binary search tree that contains the following letters:

A, B, C, D, E, F, G, H, I, J, K

A

B

C

D

F

H

E G

J

I

Page 15: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Draw a complete binary search tree that contains the following letters:

A, B, C, D, E, F, G, H, I, J, K

A

B

C

D

F

H

E G

J

I K

Page 16: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Tree traversals

10

5

7

34

1

6

6040

568

Page 17: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Tree traversals

10

5

7

34

1

6

6040

568

Pre-order

Page 18: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Tree traversals

10

5

7

34

1

6

6040

568

Pre-order10, 5, 1, 8, 7, 6, 34, 56, 40, 60

Page 19: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Tree traversals

10

5

7

34

1

6

6040

568

Pre-order10, 5, 1, 8, 7, 6, 34, 56, 40, 60

In-order

Page 20: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Tree traversals

10

5

7

34

1

6

6040

568

Pre-order10, 5, 1, 8, 7, 6, 34, 56, 40, 60

In-order1, 5, 6, 7, 8, 10, 34, 40, 56, 60

Page 21: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Tree traversals

10

5

7

34

1

6

6040

568

Pre-order10, 5, 1, 8, 7, 6, 34, 56, 40, 60

In-order1, 5, 6, 7, 8, 10, 34, 40, 56, 60

Post-order

Page 22: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Tree traversals

10

5

7

34

1

6

6040

568

Pre-order10, 5, 1, 8, 7, 6, 34, 56, 40, 60

In-order1, 5, 6, 7, 8, 10, 34, 40, 56, 60

Post-order1, 6, 7, 8, 5, 40, 60, 56, 34, 10

Page 23: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

10

5

7

34

1

6

6040

568

How would we add 13?

Page 24: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

10

5

7

34

1

6

6040

568

How would we add 13?

Larger values go to the right, smaller values go to the left

Page 25: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

10

5

7

34

1

6

6040

568

How would we add 13?

13

Larger values go to the right, smaller values go to the left

Page 26: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

10

5

7

34

1

6

6040

568

How would we remove 10?

Page 27: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

10

5

7

34

1

6

6040

568

How would we remove 10?

Replace with the left-most item of the right-subtree!

Page 28: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

10

5

7

34

1

6

6040

568

How would we remove 10?

Replace with the left-most item of the right-subtree!

Page 29: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

10

5

7

34

1

6

6040

568

How would we remove 10?

Replace with the left-most item of the right-subtree!

5

7

34

1

6

6040

56

8

Page 30: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Write a treeSort function that takes an array of elements and returns those elements in sorted order. Assume you do not have an iterator (your approach must be recursive). You will need a helper function.

Page 31: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Write a treeSort function that takes an array of elements and returns those elements in sorted order. Assume you do not have an iterator (your approach must be recursive). You will need a helper function.

struct AVLTree* newAVLTree(); void addAVLTree(struct AVLTree *tree, TYPE val);

void treeSort (TYPE data[], int n) { // WRITE ME }

void _treeSortHelper(AVLNode *cur, TYPE *data, int *count) { // WRITE ME }

Page 32: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

void treeSort(TYPE data[], int size){ int i; int sortIdx = 0;

}

Page 33: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

void treeSort(TYPE data[], int size){ int i; int sortIdx = 0;

}

/* declare an AVL tree */ struct AVLTree *tree = newAVLtree(); assert(data != NULL && size > 0);

Page 34: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

void treeSort(TYPE data[], int size){ int i; int sortIdx = 0;

}

/* declare an AVL tree */ struct AVLTree *tree = newAVLtree(); assert(data != NULL && size > 0);

/* add elements to the tree */ for (i = 0; i < size; i++) addAVLTree(tree, data[i]);

Page 35: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

void treeSort(TYPE data[], int size){ int i; int sortIdx = 0;

}

/* declare an AVL tree */ struct AVLTree *tree = newAVLtree(); assert(data != NULL && size > 0);

/* add elements to the tree */ for (i = 0; i < size; i++) addAVLTree(tree, data[i]);

/* call the helper function on the root */ _treeSortHelper(tree->root, data, &sortIdx);

Page 36: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

/* *index goes from 0 to size-1 */

void _treeSortHelper(AVLNode *cur, TYPE *data, int *index){

}

Page 37: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

/* *index goes from 0 to size-1 */

void _treeSortHelper(AVLNode *cur, TYPE *data, int *index){

}

/* In-order traversal: get the left subtree, then this node, then the right subtree */ if (cur != NULL) { _treeSortHelper(cur->left, data, index); data[*index] = cur->val; (*index)++; _treeSortHelper(cur->right, data, index); }

Page 38: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Is the height of any binary search tree with n nodes always O(log n)?

Page 39: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Is the height of any binary search tree with n nodes always O(log n)?

No, unbalanced trees may have height n

Page 40: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Is the height of any binary search tree with n nodes always O(log n)?

Does inserting into an AVL tree with n nodes require looking at O(log n) nodes?

No, unbalanced trees may have height n

Page 41: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Is the height of any binary search tree with n nodes always O(log n)?

Does inserting into an AVL tree with n nodes require looking at O(log n) nodes?

No, unbalanced trees may have height n

Yes, because AVL trees are balanced

Page 42: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Is the height of any binary search tree with n nodes always O(log n)?

Does inserting into an AVL tree with n nodes require O(log n) rotations?

Does inserting into an AVL tree with n nodes require looking at O(log n) nodes?

No, unbalanced trees may have height n

Yes, because AVL trees are balanced

Page 43: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Is the height of any binary search tree with n nodes always O(log n)?

Does inserting into an AVL tree with n nodes require O(log n) rotations?

Does inserting into an AVL tree with n nodes require looking at O(log n) nodes?

No, unbalanced trees may have height n

Yes, because AVL trees are balanced

No, we need at most 2 rotations

Page 44: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Add 12 to this AVL tree

7

5 14

3

11

10 176

Page 45: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Add 12 to this AVL tree

7

5 14

3

11

10 176

12

Page 46: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Add 12 to this AVL tree

7

5 14

3

11

10 176

12

Now 10 is unbalanced on right,

need to rotate left

Page 47: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Add 12 to this AVL tree

7

5 14

3

11

10 176

12

7

5 14

3

12

11 176

10Now 10 is

unbalanced on right, need to rotate left

Page 48: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Remove 3

7

5 14

3 11 176

10 12

Page 49: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Remove 3

7

5 14

3 11 176

10 12

Page 50: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Remove 3

7

5 14

3 11 176

Still balanced, no rotations needed

10 12

Page 51: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Remove 3

7

5 14

3 11 176

Still balanced, no rotations needed

10 12

7

5 14

11 176

10 12

Page 52: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Remove 5

7

5 14

11 176

10 12

Page 53: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Remove 5

7

5 14

11 176

10 12

Page 54: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Remove 5

7

5 14

11 176

10 12

7

6 14

11 17

10 12

Page 55: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Remove 5

7

5 14

11 176

10 12

7

6 14

11 17

10 12Now 7 is heavier on the right (14), which is heavier on the left.

Need a double rotation...

Page 56: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Remove 5 (continued)

7

6 14

11 17

10 12

So we rotate 14 right...

Page 57: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Remove 5 (continued)

7

6 14

11 17

10 12

So we rotate 14 right...

Page 58: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Remove 5 (continued)

7

6 14

11 17

10 12

So we rotate 14 right...

7

6 11

17

1410

12

Page 59: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Remove 5 (continued)

… and then rotate 7 left!

7

6 11

17

1410

12

Page 60: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Remove 5 (continued)

… and then rotate 7 left!

7

6 11

17

1410

12

Page 61: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Remove 5 (continued)

… and then rotate 7 left!

7

6 11

17

1410

12

7

6

11

17

14

10 12

Page 62: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

When do we need to do a double rotation?

Page 63: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

When do we need to do a double rotation?

1) The node is unbalanced and

Page 64: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

When do we need to do a double rotation?

1) The node is unbalanced and

2) The node’s balance factor is positive, but its right subtree’s balance factor is negative,

orThe node’s balance factor is negative, but its

left subtree’s balance factor is positive

Page 65: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

When do we need to do a double rotation?

1) The node is unbalanced and

2) The node’s balance factor is positive, but its right subtree’s balance factor is negative,

orThe node’s balance factor is negative, but its

left subtree’s balance factor is positive

Balance factor = height(right subtree) - height(left subtree)

Page 66: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

How do we represent a binary heap?

Page 67: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

How do we represent a binary heap?An array

Page 68: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

How do we represent a binary heap?An array

What are the indices for the children of node i?

Page 69: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

How do we represent a binary heap?An array

What are the indices for the children of node i?2 * i + 1 and 2 * i + 2

Page 70: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

How do we represent a binary heap?An array

What are the indices for the children of node i?2 * i + 1 and 2 * i + 2

What is the index of the parent of node i?

Page 71: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

How do we represent a binary heap?An array

What are the indices for the children of node i?2 * i + 1 and 2 * i + 2

What is the index of the parent of node i?(i - 1) / 2

Page 72: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

How do we represent a binary heap?An array

What are the indices for the children of node i?2 * i + 1 and 2 * i + 2

What is the index of the parent of node i?(i - 1) / 2

How do we add a node to a heap?

Page 73: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

How do we represent a binary heap?An array

What are the indices for the children of node i?2 * i + 1 and 2 * i + 2

What is the index of the parent of node i?(i - 1) / 2

How do we add a node to a heap?Insert it after the last item, then percolate it up

Page 74: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate heap sort on this heap

9

14

3

16

10

12 11

Page 75: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate heap sort on this heap

9

14

3

16

10

12 11

We’ll work this out on the chalk board

Page 76: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using open addressing?

Page 77: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using open addressing?012345678910

Page 78: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using open addressing?012345678910

bucket = hash(x) % 11

Page 79: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using open addressing?012345678910

bucket = hash(x) % 11

If ‘bucket’ is in use, try the next one

Page 80: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using open addressing?012345678910

3bucket = hash(x) % 11

If ‘bucket’ is in use, try the next one

Page 81: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using open addressing?012345678910

3bucket = hash(x) % 11

If ‘bucket’ is in use, try the next one

43

Page 82: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using open addressing?012345678910

3bucket = hash(x) % 11

If ‘bucket’ is in use, try the next one

8

43

Page 83: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using open addressing?012345678910

3bucket = hash(x) % 11

If ‘bucket’ is in use, try the next one

11

8

43

Page 84: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using open addressing?012345678910

3bucket = hash(x) % 11

If ‘bucket’ is in use, try the next one

11

14

8

43

Page 85: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using open addressing?012345678910

3bucket = hash(x) % 11

If ‘bucket’ is in use, try the next one

11

14

8

43

Page 86: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using open addressing?012345678910

3bucket = hash(x) % 11

If ‘bucket’ is in use, try the next one

11

1425

8

43

Page 87: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using open addressing?012345678910

3bucket = hash(x) % 11

If ‘bucket’ is in use, try the next one

11

1425

8

43

Page 88: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using open addressing?012345678910

3bucket = hash(x) % 11

If ‘bucket’ is in use, try the next one

1123

1425

8

43

Page 89: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using open addressing?012345678910

3bucket = hash(x) % 11

If ‘bucket’ is in use, try the next one

1123

44

1425

8

43

Page 90: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using open addressing?012345678910

3bucket = hash(x) % 11

If ‘bucket’ is in use, try the next one

112344

1425

8

43

Page 91: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using buckets + chaining?

Page 92: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using buckets + chaining?012345678910

Page 93: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using buckets + chaining?012345678910

bucket = hash(x) % 11

Page 94: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using buckets + chaining?012345678910

bucket = hash(x) % 11

If ‘bucket’ is in use, add the item to the chain

Page 95: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using buckets + chaining?012345678910

bucket = hash(x) % 11

If ‘bucket’ is in use, add the item to the chain

3

Page 96: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using buckets + chaining?012345678910

bucket = hash(x) % 11

If ‘bucket’ is in use, add the item to the chain

3

43

Page 97: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using buckets + chaining?012345678910

bucket = hash(x) % 11

If ‘bucket’ is in use, add the item to the chain

3

43

8

Page 98: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using buckets + chaining?012345678910

bucket = hash(x) % 11

If ‘bucket’ is in use, add the item to the chain

3

43

8

11

Page 99: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using buckets + chaining?012345678910

bucket = hash(x) % 11

If ‘bucket’ is in use, add the item to the chain

3

43

8

11

14

Page 100: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using buckets + chaining?012345678910

bucket = hash(x) % 11

If ‘bucket’ is in use, add the item to the chain

3

43

8

11

14 25

Page 101: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using buckets + chaining?012345678910

bucket = hash(x) % 11

If ‘bucket’ is in use, add the item to the chain

3

43

8

11

14 25

23

Page 102: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using buckets + chaining?012345678910

bucket = hash(x) % 11

If ‘bucket’ is in use, add the item to the chain

3

43

8

11

14 25

2344

Page 103: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using buckets + chaining?012345678910

bucket = hash(x) % 11

If ‘bucket’ is in use, add the item to the chain

3

43

8

11

14 25

2344

What is the table load?

Page 104: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

If we have a hash table with 11 bucketsand the silly hash function hash(x) = x, what will the hash table look like after inserting 3, 43, 8, 11, 14,

25, 23, 44 using buckets + chaining?012345678910

bucket = hash(x) % 11

If ‘bucket’ is in use, add the item to the chain

3

43

8

11

14 25

2344

What is the table load?8 items / 11 buckets

Page 105: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Does every key in a hash table need to be unique?

Page 106: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Does every key in a hash table need to be unique?Yes, that’s the point of storing key/value pairs

Page 107: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Does every key in a hash table need to be unique?

Does each key in a hash table need to hash to a unique value?

Yes, that’s the point of storing key/value pairs

Page 108: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Does every key in a hash table need to be unique?

Does each key in a hash table need to hash to a unique value?

Yes, that’s the point of storing key/value pairs

No, but we should use a hash function with as few collisions as possible

Page 109: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Does every key in a hash table need to be unique?

Does hash table performance increase or decrease as the number of buckets increases?

Does each key in a hash table need to hash to a unique value?

Yes, that’s the point of storing key/value pairs

No, but we should use a hash function with as few collisions as possible

Page 110: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Does every key in a hash table need to be unique?

Does hash table performance increase or decrease as the number of buckets increases?

Does each key in a hash table need to hash to a unique value?

Yes, that’s the point of storing key/value pairs

No, but we should use a hash function with as few collisions as possible

It should increase

Page 111: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate depth-first search on this graph

A B D F

C E

Page 112: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate depth-first search on this graph

A B D F

C EStore vertices in a stack

(last in, first out)

Page 113: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate depth-first search on this graph

A B D F

C EStore vertices in a stack

(last in, first out)

Add nodes in counter-clockwise

order

Page 114: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate depth-first search on this graph

A B D F

C E

Reachable:

Known:

Store vertices in a stack

(last in, first out)

Add nodes in counter-clockwise

order

Page 115: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate depth-first search on this graph

A B D F

C E

Reachable:

Known: A

Store vertices in a stack

(last in, first out)

Add nodes in counter-clockwise

order

Page 116: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate depth-first search on this graph

A B D F

C E

Reachable:

Known:

A

Store vertices in a stack

(last in, first out)

Add nodes in counter-clockwise

order

Page 117: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate depth-first search on this graph

A B D F

C E

Reachable:

Known:

A

B

Store vertices in a stack

(last in, first out)

Add nodes in counter-clockwise

order

Page 118: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate depth-first search on this graph

A B D F

C E

Reachable:

Known:

A B

Store vertices in a stack

(last in, first out)

Add nodes in counter-clockwise

order

Page 119: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate depth-first search on this graph

A B D F

C E

Reachable:

Known:

A B

C

Store vertices in a stack

(last in, first out)

Add nodes in counter-clockwise

order

Page 120: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate depth-first search on this graph

A B D F

C E

Reachable:

Known:

A B

C E

Store vertices in a stack

(last in, first out)

Add nodes in counter-clockwise

order

Page 121: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate depth-first search on this graph

A B D F

C E

Reachable:

Known:

A B

C E D

Store vertices in a stack

(last in, first out)

Add nodes in counter-clockwise

order

Page 122: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate depth-first search on this graph

A B D F

C E

Reachable:

Known:

A B

C E

D

Store vertices in a stack

(last in, first out)

Add nodes in counter-clockwise

order

Page 123: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate depth-first search on this graph

A B D F

C E

Reachable:

Known:

A B

C E

D

F

Store vertices in a stack

(last in, first out)

Add nodes in counter-clockwise

order

Page 124: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate depth-first search on this graph

A B D F

C E

Reachable:

Known:

A B

C E

D F

Store vertices in a stack

(last in, first out)

Add nodes in counter-clockwise

order

Page 125: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate depth-first search on this graph

A B D F

C E

Reachable:

Known:

A B

C

ED F

Store vertices in a stack

(last in, first out)

Add nodes in counter-clockwise

order

Page 126: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate depth-first search on this graph

A B D F

C E

Reachable:

Known:

A B CED F

Store vertices in a stack

(last in, first out)

Add nodes in counter-clockwise

order

Page 127: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C E

Page 128: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C EStore vertices in a queue

(first in, first out)

Page 129: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C EStore vertices in a queue

(first in, first out)

Add nodes in counter-clockwise

order

Page 130: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C E

Reachable:

Known:

Store vertices in a queue

(first in, first out)

Add nodes in counter-clockwise

order

Page 131: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C E

Reachable:

Known: A

Store vertices in a queue

(first in, first out)

Add nodes in counter-clockwise

order

Page 132: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C E

Reachable:

Known:

A

Store vertices in a queue

(first in, first out)

Add nodes in counter-clockwise

order

Page 133: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C E

Reachable:

Known:

A

B

Store vertices in a queue

(first in, first out)

Add nodes in counter-clockwise

order

Page 134: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C E

Reachable:

Known:

A B

Store vertices in a queue

(first in, first out)

Add nodes in counter-clockwise

order

Page 135: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C E

Reachable:

Known:

A B

C

Store vertices in a queue

(first in, first out)

Add nodes in counter-clockwise

order

Page 136: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C E

Reachable:

Known:

A B

C E

Store vertices in a queue

(first in, first out)

Add nodes in counter-clockwise

order

Page 137: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C E

Reachable:

Known:

A B

C E D

Store vertices in a queue

(first in, first out)

Add nodes in counter-clockwise

order

Page 138: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C E

Reachable:

Known:

A B C

E D

Store vertices in a queue

(first in, first out)

Add nodes in counter-clockwise

order

Page 139: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C E

Reachable:

Known:

A B C E

D

Store vertices in a queue

(first in, first out)

Add nodes in counter-clockwise

order

Page 140: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C E

Reachable:

Known:

A B C E

D D

Store vertices in a queue

(first in, first out)

Add nodes in counter-clockwise

order

Page 141: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C E

Reachable:

Known:

A B C E D

D

Store vertices in a queue

(first in, first out)

Add nodes in counter-clockwise

order

Page 142: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C E

Reachable:

Known:

A B C E D

D F

Store vertices in a queue

(first in, first out)

Add nodes in counter-clockwise

order

Page 143: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C E

Reachable:

Known:

A B C E D

F

Store vertices in a queue

(first in, first out)

Add nodes in counter-clockwise

order

Page 144: Exam review - Oregon State Universityclasses.engr.oregonstate.edu/eecs/.../Lab/Lab_10.pdf · The exam will be comprehensive (so don’t forget to review the midterm slides!) Similar

Simulate breadth-first search on this graph

A B D F

C E

Reachable:

Known:

A B C E D F

Store vertices in a queue

(first in, first out)

Add nodes in counter-clockwise

order