Skip to document
This is a Premium Document. Some documents on Studocu are Premium. Upgrade to Premium to unlock it.

Quiz-8- -COMP2521-22T1- -Web CMS 3

Yeah so
Subject

Software Design and Development- Unit 4

10 Documents
Students shared 10 documents in this course
DegreeGrade

HSC

12
Academic year: 2015/2016
Uploaded by:
Anonymous Student
This document has been uploaded by a student, just like you, who decided to remain anonymous.
High School - Australia

Comments

Please sign in or register to post comments.

Preview text

Quiz 8

Note: Some of the content this quiz covers will not be taught until the week 9 lectures.

Question 1 (1 mark)

Which of the following trees are valid max heaps? Select all that apply.

(a)

(b)

Deadline N/A

Latest Submission Monday, 25 April 2022 at 3:44PM

Raw Mark 5.50/8 (68%)

Late Penalty N/A

Final Mark 5.50/8 (68%)

(c)

(d)

(e)

 Your response was incorrect. The correct response was: (a) and (e) Mark: max(0 - 0 + 0, 0) = 0.

In a tree representation of a max heap: 1. Each element must be greater than its children 2. The tree must be complete (no gaps in the level order)

(b) is not a valid max heap because it has values which are smaller than their children. (c) is not a valid max heap because it is not complete.

(d) is not a valid max heap because it has a value (6) which is smaller than one of its children.

Question 2 (1 mark)

Question 4 (1 mark)

If we have an initially empty linear-probed hash table with 7 slots, with a hash function

int hash(int n) { return (n % 7); }

what is the final state of the table after the following values:

10 5 7 3 14 12

are inserted in the order given?

Empty entries in the hash table are indicated by a value of '-'.

(a)

(b)

(c)

(d)

(e) None of the above are correct

 Your response was correct. Mark: 1.

Question 5 (1 mark)

Suppose we have a hash table which uses linear probing which is full and needs to be expanded. What is the worst case time complexity of expanding the hash table, assuming that hash functions are O(1)?

(a) O(1)

(b) O(log n)

(c) O(n)

(d) O(n log n)

(e) O(n^2)

 Your response was incorrect. The correct response was: (e) Mark: 0.

Expanding the hash table requires rehashing/re-inserting each element. The worst case time complexity of inserting an element into a hash table is O(n), and therefore the worst case time complexity of expanding the hash table is n x O(n) = O(n^2).

Question 6 (1 mark)

Consider the following hash table which uses double hashing, with primary hash function h(x) = x % 7 and secondary hash function h2(x) = x % 4 + 1.

Give a number between 1 and 50 (inclusive) which would result in two elements of the hash table being inspected if we searched for it.

Note: There are multiple correct numbers - you should only give one of them.

Enter your answer here:

22

 Your response was incorrect. The correct response was: Blank 1: any response matching any of the keywords "17", "26", "43" or "45" (with case sensitive matching) Mark: 0.

A number x which would result in two elements inspected must satisfy one of these: 1. h(x) = 1 and h2(x) = 4 2. h(x) = 3 and h2(x) = 2 3. h(x) = 5 and h2(x) = 3

The only numbers between 1 and 50 which satisfy one of these conditions are: 15 (satisfies condition 1) 43 (satisfies condition 1) 17 (satisfies condition 2) 45 (satisfies condition 2) 26 (satisfies condition 3)

However, searching for 15 would result in only 1 element inspected since it is already in the hash table at the correct index (1), so the possible answers are 17, 26, 43 and 45. One popular incorrect answer was 22. If x = 22, then h(x) = 1 and h2(x) = 3, which means starting at index 1, we check the index and increment by 3 until the index is empty or we find the item. Index 1 contains 15 and index 4 is empty, so only one element is inspected.

Question 7 (1 mark)

What is the trie resulting from inserting the following keys into an initially empty trie, in the order given?

(c)

(d)

(e) None of the above are correct

 Your response was correct. Mark: 1.

Question 8 (1 mark)

Suppose you have 10 distinct words of length 5, and you insert them into an initially-empty trie. What are the minimum and maximum possible number of nodes in the trie after inserting all the words? Do not include the root node in your answer.

Note: a word is defined as a sequence of alphabetic characters.

The minimum possible number of nodes is:

14

The maximum possible number of nodes is:

50

 Your response was correct. Mark: 0 + 0 = 1. The minimum possible number of nodes occurs when all the words have the same four-letter prefix, and they only differ on the last letter. In this case, the total number of nodes is 4 + 10 = 14.

The maximum possible number of nodes occurs when all the words have a different first letter. In this case, none of the words share any nodes, so the total number of nodes is 10 x 5 = 50.

 Submit

Was this document helpful?
This is a Premium Document. Some documents on Studocu are Premium. Upgrade to Premium to unlock it.

Quiz-8- -COMP2521-22T1- -Web CMS 3

Subject: Software Design and Development- Unit 4

10 Documents
Students shared 10 documents in this course
DegreeGrade:

HSC

12
Was this document helpful?

This is a preview

Do you want full access? Go Premium and unlock all 8 pages
  • Access to all documents

  • Get Unlimited Downloads

  • Improve your grades

Upload

Share your documents to unlock

Already Premium?
09/06/2022, 20:17
Quiz 8 | COMP2521 22T1 | WebCMS3
https://webcms3.cse.unsw.edu.au/COMP2521/22T1/activities/quizzes/1907
1/8
Quiz 8
Note: Some of the content this quiz covers will not be taught until the week 9 lectures.
Question 1 (1 mark)
Which of the following trees are valid max heaps? Select all that apply.
(a)
(b)
Deadline N/A
Latest Submission Monday, 25 April 2022 at 3:44PM
Raw Mark 5.50/8.00 (68.75%)
Late Penalty N/A
Final Mark 5.50/8.00 (68.75%)

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.

Why is this page out of focus?

This is a Premium document. Become Premium to read the whole document.