Exam 2 Review. Teams Dan C, Z, Hugh, Zane, Alexis Mark, Jamie, Ryan, Alex H, Andrew Katie, Emily,...

Post on 27-Dec-2015

215 views 0 download

Transcript of Exam 2 Review. Teams Dan C, Z, Hugh, Zane, Alexis Mark, Jamie, Ryan, Alex H, Andrew Katie, Emily,...

Exam 2 Review

Teams

• Dan C, Z, Hugh, Zane, Alexis• Mark, Jamie, Ryan, Alex H, Andrew• Katie, Emily, Riley, Rohan, Alex D• Dawn, Patrick, Jacapo, Catharine, Lisa• Marshall, Lawrence, Dan B, Colby, Michelle• Zack, Ben, Jerry, Alex Z, Matt

1.

Suppose a heap has 6 nodes. What is the height of the heap? (Remember the root is at height 0).

2.

• Suppose you have a binary search tree with 6 nodes. What is the range of what the height of the tree may be?

3.

Suppose that a hash table has 50 slots and only 10 keys. What is its load factor?

4.

Give one pro of an array over a linked list and vice versa.

5.

• When would you prefer to use a heap rather than a binary search tree?

6.

• What data structure is implemented using a heap?

7.

• What is the main operation supported by a heap?

8.

• What is the main operation supported by a BST?

9.

Could this be a heap? Why or why not?

18

3

89

1012

10.

I’m going to empty a binary search tree by successively finding the smallest element, printing it, and then deleting it until the tree is empty.

What’s the best case running time?

11.

• What are the two schemes for storing edges?

12.

• What is the running time of depth-first search?

13.

• When would I prefer to use breadth-first rather than depth-first search?

14.

• Dijkstra’s algorithm is O((V+E)(lgV)). Where does the lgV term come from?

15.

• How do you perform a topological sort?

16.

• How can you tell if a graph is connected?

17.

• A connected, acyclic graph is called …

18.

• The two algorithms that compute MSTs are

19.

• When is Dijkstra’s not used for computing shortest paths?

20.

• What does “linear probing” refer to?

21.

• Consider the adjacency matrix:

• Is the graph directed?• Weighted?• Dense or sparse?

1 4 3 8

3 6 3 23

0 2 4 13

21 3 5 0

22.

• When would you prefer to use an adjacency list rather than an adjacency matrix?

23.

• What properties of a graph are necessary for a topological sort?

24.

• What makes an algorithm “greedy”? Give an example.

25.

• What is the running time of Kruskal’s?

26.

• What properties of a graph are necessary for running Prim’s algorithm?

27.

• What operations should be supported by a hash table?

28.

• What is the running time for inserting or deleting from a hash table if there is a good hash function?

29.

• What are the 2 types of hash tables?

30.

• When would you prefer to use a chaining table rather than an open-address table?

All-Play

• Run Depth-First on the following graph and classify each edge:

B

EG H

C

F

D

A

All-Play

• Use both Kruskal’s and Prim’s to calculate MSTs. Use alphabetical order for Prim’s.

A

E F

B

G

C

H

D1

1

86

6 21

44

32

5 1

All-Play

• Use Dijkstra’s to compute shortest paths from A.

A

E F

B

G

C

H

D1

1

86

6 21

44

32

5 1

Design an algorithm that takes as input a connected, undirected graph and computes whether or not there exists an edge in the graph that can be removed and still leave the graph connected. Tell the running time of your algorithm. Feel free to call any algorithm we’ve discussed (you don’t have to re-write the algorithm).

boolean REMOVE-BUT-CONNECTED(G)

• Write an algorithm that decreases the value of an element in a heap. Use known heap functions. What is the running time?

DECREASE_KEY(Heap H, KeyIndex K, Integer Amt):

• Write an algorithm that computes the number of nodes in a BST. left(N) gives the left node of N and right(N) gives the right.

int SIZE(BST N):