Rearrange the code, all necessary code is already listed

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Rearrange the code, all necessary code is already listed

Given a particular list of prerequisite requirements, the function
wiz_study_length(prereq_list, final='WIZ90001') is
intended to calculate the minimum number of semesters it will take
Sandy to graduate. The arguments are:
• prereq_list, a list of (subject, prerequisite) tuples specifying
that prerequisite must be completed before enrolling in
subject. Note that a subject may have more than one
prerequisite.
• final, the target subject to complete, with a default value of
"WIZ90001'.
Any subject that appears as a prerequisite in a prereq_list tuple
but does not appear as a subject can be assumed to have no
prerequisites. Furthermore, we assume that Sandy has capacity to
take as many subjects as required each semester, as long as they
have completed their prerequisites.
For example:
>>> wiz_study_length([ ('WIZ90001', 'WIZ40027'), ('WIZ9E
2
Here, both WIZ40027 and WIZ20003 are prerequisites of
WIZ90001, and so must be completed before studying WIZ90001.
Neither of these two subjects have any prerequisites. Therefore it
will take two semesters of study for Sandy to graduate.
>>> wiz_study_length([('WIZ90001', 'WIZ40027'), ('WIZ9E
('WIZ40027', 'WIZ30015'), ('WIZ2E
('WIZ20003', 'WIZ10015'), ('WIZ26
In this case, it will take 4 semesters for Sandy graduate, due to the
prerequisite chain: WIZ10001 -> WIZ20001 -> WIZ20003 ->
WIZ90001.
Transcribed Image Text:Given a particular list of prerequisite requirements, the function wiz_study_length(prereq_list, final='WIZ90001') is intended to calculate the minimum number of semesters it will take Sandy to graduate. The arguments are: • prereq_list, a list of (subject, prerequisite) tuples specifying that prerequisite must be completed before enrolling in subject. Note that a subject may have more than one prerequisite. • final, the target subject to complete, with a default value of "WIZ90001'. Any subject that appears as a prerequisite in a prereq_list tuple but does not appear as a subject can be assumed to have no prerequisites. Furthermore, we assume that Sandy has capacity to take as many subjects as required each semester, as long as they have completed their prerequisites. For example: >>> wiz_study_length([ ('WIZ90001', 'WIZ40027'), ('WIZ9E 2 Here, both WIZ40027 and WIZ20003 are prerequisites of WIZ90001, and so must be completed before studying WIZ90001. Neither of these two subjects have any prerequisites. Therefore it will take two semesters of study for Sandy to graduate. >>> wiz_study_length([('WIZ90001', 'WIZ40027'), ('WIZ9E ('WIZ40027', 'WIZ30015'), ('WIZ2E ('WIZ20003', 'WIZ10015'), ('WIZ26 In this case, it will take 4 semesters for Sandy graduate, due to the prerequisite chain: WIZ10001 -> WIZ20001 -> WIZ20003 -> WIZ90001.
while cur prereqs:
prereqs [subject[0]].append (subject[1])
semesters = 0; cur_prereqs = [final]
for subject in prereq_list:
from collections import defaultdict
return semesters
def wiz_study_length (prereq_list, final='WIZ90001'):
new_prereqs = ()
for subject in cur_prereqs:
if subject in prereqs:
prereqs = defaultdict(list)
new_prereqs += prereqs(subject]
cur prereqs = new_prereqs; semesters += 1
Transcribed Image Text:while cur prereqs: prereqs [subject[0]].append (subject[1]) semesters = 0; cur_prereqs = [final] for subject in prereq_list: from collections import defaultdict return semesters def wiz_study_length (prereq_list, final='WIZ90001'): new_prereqs = () for subject in cur_prereqs: if subject in prereqs: prereqs = defaultdict(list) new_prereqs += prereqs(subject] cur prereqs = new_prereqs; semesters += 1
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
C-string
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education