q13FulfilProgramP
solutions.q13FulfilProgramP
Question 13 [PY]
Given \(N\) courses labelled \(\{0,\ldots,N-1\}\) and a list of prerequisites \(R\) such that the courses \(R[i]\equiv\{a_i,b_i,\ldots\}\) are required to be completed before enrolling for \(i\)-th course.
WAP to determine if all the \(N\) courses can be completed successfully by a candidate. If so, also determine one of the feasible ordering of courses.
Examples
- \(N=2\), \(R=[\emptyset,\{0\}]\) means that course \(1\) requires course \(0\) as pre-requisite. Hence, it is possible to complete the courses, in the following order: \([0,1]\).
- \(N=2\), \(R=[\{1\},\{0\}]\). Here, the requirement is \(1\) before \(0\); and also \(0\) before \(1\). This, hence, is impossible.
Functions:
Name | Description |
---|---|
q13FulfilProgramP |
Args: |
q13FulfilProgramP(R)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
R
|
List[List[int]]
|
A list of \(N\) lists of integer values where the \(i\)-th list represents the reprequisites of \(i\). |
required |