/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none} Q16E Suppose a CS curriculum consists... [FREE SOLUTION] | 91影视

91影视

Suppose a CS curriculum consists of n courses, all of them mandatory. The prerequisite graph G has a node for each course, and an edge from course v to course w if and only if v is a prerequisite for w. Find an algorithm that works directly with this graph representation, and computes the minimum number of semesters necessary to complete the curriculum (assume that a student can take any number of courses in one semester). The running time of your algorithm should be linear.

Short Answer

Expert verified

The linear algorithm that computes the minimum number of semesters necessary to complete the curriculum in linear time is as follows:

Input: Graph G

Output: number of required semesters.

Add n vertices that has din=0to the first queue

n=din-1

if din-1=0

add nto the second queue

process second queue

if semester coincides with class schedule

return n

Step by step solution

01

Explain the given information

Consider the CS curriculum consists of n courses. The prerequisite graph G has node for each course and an edge from course v to course w, if and only if v is a prerequisite forw

02

Step 2: Give the linear time algorithm that computes the minimum number of semesters

The linear algorithm that computes the minimum number of semesters necessary to complete the curriculum in linear time is as follows:

Input: Graph G

Output: number of required semesters.

Add n vertices that has dn=0to the first queue

n=dn-1

if dn-1=0

add n to the second queue

process second queue

if semester coincides with class schedule

return n

The above algorithm runs in the linear-time.

Therefore, The linear algorithm that computes the minimum number of semesters necessary to complete the curriculum in linear time has been provided.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with 91影视!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Question:Undirected vs. directed connectivity.

(a) Prove that in any connected undirected graph G =(V , E)there is a vertexvV whose removal leaves G connected. (Hint: Consider the DFS search tree for G.)

(b) Give an example of a strongly connected directed graph G(V ,E)such that, for everyvV, removing v from G leaves a directed graph that is not strongly connected.

(c) In an undirected graph with two connected components it is always possible to make the graph connected by adding only one edge. Give an example of a directed graph with two strongly connected components 0 such that no addition of one edge can make the graph strongly connected.

You are given a tree T=(V,E) (in adjacency list format), along with a designated root node rV. Recall that u is said to be an ancestor of v in the rooted tree if the path from r to v in T passes through u.

You wish to reprocess the tree so that queries of the form 鈥渋s u an ancestor v?鈥 can be answered in constant time. The pre-processing itself should take linear time. How can this be done?

As in the previous problem, you are given a binary tree T=(V,E) with designated root node. In addition, there is an array x[.]with a value for each node in V Define a new array z[.]as follows: for each uV,

z[u]=the maximum of the x-values associated with u鈥檚 descendants.

Give a linear-time algorithm that calculates the entire z-array.

For each node in an undirected graph, let twodegreeube the sum of the degrees of鈥檚 neighbors. Show how to compute the entire array of two degree. values in linear time, given a graph in adjacency list format

You are given tree T=(V,E) along with a designated root node rV. The parent of any node Vr, denoted p(V), is defined to be the node adjacent to v in the path from r to v . By convention, p(r)=r. For k>1, define pk(v)pk-1(pv)andp1(v)=p(v)(so pk(v)is the k th ancestor of v ). Each vertex v of the tree has an associated non-negative integer label l(v). Given a linear-time algorithm to update the labels of all the vertices T according to the following rule: lnew(v)=l(plvv).

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.