Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In a particular school, each course can only have 1 pre-requisite course. * * These pre-req courses are represented by a map, for example: *

In a particular school, each course can only have 1 pre-requisite course.

*

* These pre-req courses are represented by a map, for example:

*

* {"CS120"="","CS220"="CS120","CS230"="CS220","MA100"="MA102","MA102"="MA100"}

*

* Note that if a course has no pre-req, it is represented by the empty string ""

*

* So in this example, CS120 has no pre-req course.

* CS220 has a pre-req of 120

* CS230 has a pre-req of 220

* MA100 has a pre-req of MA102

* MA102 has a pre-req of MA100

*

* Your job is to write a function that determines how many courses must be taken to take a specific course.

*

* So your function should return 0 for "CS120"

* your function should return 1 for "CS220"

* your function should return 2 for "CS230"

* your function should return -1 for "MA102" or "MA100". They are in a pre-req loop, so it is impossible to take any of the courses.

*

Language is Java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

3. Are our bosses always right? If not, what should we do?

Answered: 1 week ago