Summer final solutions to last three problems
Download
1 / 27

Summer Final Solutions to last three problems - PowerPoint PPT Presentation


  • 74 Views
  • Uploaded on

Summer Final Solutions to last three problems. Bryce Boe CS24 , Fall 2013. Problem 11. Draw the contents of the array that represents the following max-heap after calling dequeue 3 times. The following are the initial contents of the array. 60 40 10 25 0 3 1 4. Problem 11: Suggestions.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Summer Final Solutions to last three problems' - fell


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Summer final solutions to last three problems

Summer FinalSolutions to last three problems

Bryce Boe

CS24, Fall 2013


Problem 11
Problem 11

Draw the contents of the array that represents the following max-heap after calling dequeue 3 times. The following are the initial contents of the array.

60 40 10 25 0 3 1 4


Problem 11 suggestions
Problem 11: Suggestions

  • Convert the array into a tree representation

    • No required, but makes it more likely for you to receive partial credit if you make a mistake

  • Show the resulting tree after each removal

  • Convert the final tree back into the array form







Problem 12
Problem 12

Draw the contents of a hash table of size 8 with a linear probing constant of 3 after inserting the following items. Hash function: h(x) = x % 8

7 2 15 5 12 4


Problem 12 suggestions
Problem 12: Suggestions

  • Again it might be useful to show the complete contents after each insertion in the event you make a mistake.




Problem 12 insert 15
Problem 12: Insert 15

(2) Second position occupied, try again

(1) Initial position occupied, try again


Problem 12 insert 5
Problem 12: Insert 5

(1) Initial position occupied, try again



Problem 12 insert 4
Problem 12: Insert 4

(3) Third position occupied, try again

(1) Initial position occupied, try again

(2) Second position occupied, try again

(5) Fifth position occupied, try again

(4) Fourth position occupied, try again



Problem 13
Problem 13

Assume we have a poorly implemented hash table of size 8 with a linear probing constant of 1 that does not properly record deletions. Beginning with the following filled hash table, which elements (numbers) are no longer accessible after removing both 10 and 14? Hash function: h(x) = x % 8


Problem 13 suggestions
Problem 13: Suggestions

  • Remove elements 10 and 14

  • For each element test if it’s reachable



Problem 13 contains 8
Problem 13: contains(8)?

(1) 8 % 8 == 0

PASS


Problem 13 contains 7
Problem 13: contains(7)?

(2) (7 + 1) % 8 == 0

occupied -- next

7 % 8 == 7

occupied -- next

(3) (0 + 1) % 8 == 1

PASS


Problem 13 contains 1
Problem 13: contains(1)?

(1) 1 % 8 == 1

occupied -- next

(2) (1 + 1) % 8 == 2

unoccupied -- FAIL


Problem 13 contains 12
Problem 13: contains(12)?

(1) 12 % 8 == 4

PASS


Problem 13 contains 2
Problem 13: contains(2)?

(1) 2 % 8 == 2

unoccupied -- FAIL


Problem 13 contains 6
Problem 13: contains(6)?

(1) 6 % 8 == 6

unoccupied -- FAIL


Problem 13 solution
Problem 13: Solution

  • Items 1, 2, and 6 are no longer reachble


ad