Question: In question 4 , you will build a class CourseRegistry that store all the courses in a school. The class will use hash table (
In question you will build a class CourseRegistry that store all the courses in a school. The class will use hash table backed by Python list with separate chaining. Python builtin function hash is used to calculate hash code of a course using the course code as key. The calculated hash code will then map to corresponding index position of the hash table using a modulo operator. The constructor is provided in the Assignment Template.
a Method insert is used to add a course into course registry. Complete the method with the specifications below:
Take one input course type Course Validate its type. Raise an error and stop the program if the input type is invalid.
Create a LLNode object with course.code as key and course as value the class LLNode is provided in the Assignment Template; do not change the code of the LLNode class and do not use other implementations of linked lists
Determine the hash table index by calling hashcoursecode self.capacity and insert the LLNode object to the front of the linked list.
Increment the size attribute by
b Method search is used to find and return a course from the course registry. Complete the
method with the specifications below:
Take one input code type str Validate its type. Raise an error and stop the program if the input type is invalid.
Determine the hash table index by calling hashcode self.capacity.
Search along the linked list to see if any matching LLNode with key equals to the inputted code. If found, return the value attribute of the LLNode. Otherwise, return
None.
c Run the testing code provided in the Assignment Template. It should produce the following
outputs excluding the line numbers Do not alter the testing code.
None
Data Structures
Register Chan TM A successful.
Register CHOW MP A successful.
Register LAM CS A successful.
Register LEUNG WA A successful.
Register LI CC A successful.
Course full. Put LIU MK A in waiting queue.
Course full. Put NG KY A in waiting queue.
Course full. Put SHEK CL A in waiting queue.
Course full. Put TSE David A in waiting queue.
Course full. Put WONG KM A in waiting queue.
Remove CHOW MP A successful.
Register LIU MK A successful.
Course code: SEHH
Course title: Data Structures
Course size:
Registered students:
A Name: LEUNG WA ID: A
A Name: LIU MK ID: A
A Name: Chan TM ID: A
A Name: LAM CS ID: A
A Name: LI CC ID: A
Students in queue:
Queue size:
Name: NG KY ID: A
Name: SHEK CL ID: A
Name: TSE David, ID: A
Name: WONG KM ID: A
###### Question ###### do not change this line
class CourseRegistryobject: # do not change this line
def initself capacity: # do not change this function
self.capacity capacity
self.hashtable None capacity
self.size
def insertself course: # do not change this line
#################################################################
# Question a
#################################################################
# Start of your code
# End of your code
#################################################################
pass # do not change this line
def searchself code: # do not change this line
#################################################################
# Question b
#################################################################
# Start of your code
# End of your code
#################################################################
pass # do not change this line
registry CourseRegistry
# Insert dummy courses to the registry to populate the hash table
for code in range:
course CoursefHKCCcode:d "DUMMY",
registry.insertcourse
course CourseSEHH "Data Structures",
course CourseBHMH "Advertising and Promotion",
registry.insertcourse
registry.insertcourse
printregistrysearchSEHH
sehh registry.searchSEHH
printsehhtitle
print
slist StudentChan TMA StudentCHOW MPA StudentLAM CSA
StudentLEUNG WAA StudentLI CCA StudentLIU MKA
StudentNG KYA StudentSHEK CLA StudentTSE David',A
StudentWONG KMA
for e in slist:
sehhaddStudente
print
sehhremoveStudentslist
print
sehhPrintCourse
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
