
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
thumb_up100%

Transcribed Image Text:We have discussed greedy algorithm during lectures. A greedy algorithm is an
algorithm that recursively construct a set of objects from the smallest possible
constituent parts. At each one of the iterations, the algorithm takes the best that it
can get right now, without regards for future consequences. The algorithm hopes
that by choosing a local optimum at each one of the iterations, it can end up at a
global optimum.
In this assignment, you will write a program to schedule final examination for the
examination department so that no student has two examinations at the same time.
The goal of this assignment is to expose you to the implementation of greedy
algorithms that solves a problem with constraints. You will use a greedy algorithm
to determine an assignment of classes to examination slots (schedules) such that:
1. No student, enrolled in two subjects, is assigned to the same examination
slot (schedule.)
2. Any attempt to combine two slots into one would violate rule 1.
Input to the program will consist of the name of a data file. This file will contain the
following data:
The number of students enrolled in the current semester
• Repeated rows of the following:
o Name of the student and the total number of subjects enrolled
o The subject code the student is enrolled in.
A sample of an input file is as follow:
3
Melissa, 4
CSCI203
CSCI235
CSCI222
CSCI205
Bernard, 4
CSCI213
CSCI222
CSCI204
CSCI203
Terrence, 4
CSCI212
CSCI203
CSCI235
CSCI213

Transcribed Image Text:The output of the program should be a list of time slots with the subjects whose
final examination will be given at that slot and the total number of students taking
the final examination in that slot. One possible output is as follow:
Slot 1: CSCI212, CSCI222
Slot 2: CSC1204, CSCI235
Slot 3: CSCI205, CSCI213
Slot 4: CSCI203
(i)
(ii)
(iii)
(iv)
(v)
3
3
3
3
The algorithm:
• Read the enrolment information from the input file. As the records are read, build
an adjacency matrix representing the relationships among the students and the
subject the students enrol in. You should notice that this adjacency matrix is a
graph representing the relationships. Each node of the graph will be a subject
taken by at least one student in the current semester. An edge between two
nodes will mean there is at least one student taking both subjects. The weight
of an edge could be the number of students enrols with both subjects.
• Your aim in solving this problem is to construct a maximal independent set in
the graph. This can be achieved by finding an examination schedule satisfying
the two constraints mentioned earlier, as follow:
(vi)
(vii)
wwww
Construct a candidate list of subjects.
Order the subjects in descending order by total number of
inconnectivity.
Starting from the subject with the highest number of inconnectivity,
create a slot.
Search for a subject to which it is not connected. If you find one, add
the subject to the same slot and remove it from the candidate list.
Next, try to find another subject that is not connected to any of those
already in the time slot. Similarly, if you find one, add the subject to
the same slot and remove it from the candidate list. Continue to do so
until there is no more un-connected subject can be found.
Accumulate the total number of students enrolled from the adjacency
matrix. (How can you do that? Give it a thought.)
Repeat steps (iii) through (vi) until all the subjects are removed from
the candidate list.
Note that no pair of time slots can be combined without creating a time conflict
with a student. Also note that depending on how you select a subject from the
candidate list, there may be different schedule can be formed. Any schedule
satisfying the two-mentioned constrained will be acceptable.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 5 steps with 1 images

Knowledge Booster
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.Similar questions
- Sorting Jojo was given a Math assignment by his teacher. Jojo's task is to sort a number of given then find the closest pair of numbers that has the maximum difference after sorted. Jojo was asked to write down a list of the pairs of numbers. Input FormatThe first line of input is an integer N i.e. the number of numbersThe second line is a series of numbers Ai as many as N Output FormatPairs of numbers separated by spaces Constraints2 ≤ N ≤ 105-107 ≤ Ai ≤ 107 Sample Input 52 -8 3 1 -10 Sample Output-8 1 Sample Input1045 9 3 -6 100 68 -57 23 -11 -25 Sample Output-57 -25 68 100 In the sample above if the input is sorted then:-10 -8 1 2 3 so that the difference between each number in sequence is 2, 9, 1, 1-57 -25 -11 -6 3 9 23 45 68 100 so the difference is 32, 14, 5, 9, 6, 14, 22, 23, 32 NotesEven though it wasn't stated in the problem, by now you should know that the advantages spaces or lines are considered WRONG ANSWER.arrow_forwardThe Fibonacci sequence begins with 0 and then 1 follows. All subsequent values are the sum of the previous two, ex: 0, 1, 1, 2, 3, 5, 8, 13. Complete the fibonacci() function, which has an index n as parameter and returns the nth value in the sequence. Any negative index values should return -1. Ex: If the input is: 7 the output is: fibonacci (7) is 13 Note: Use a for loop and DO NOT use recursion.arrow_forwardThe Tower of Hanoi is a puzzle where n disks of different sizes arestacked in ascending order on one rod and there are two other rods with nodisks on them. The objective is to move all disks from the first rod to thethird, such that:- only one disk is moved at a time- a larger disk can never be placed on top of a smaller oneWrite a recursive function that outputs the sequence of steps needed tosolve the puzzle with n disks.Write a test program in C++ that allows the user to input number of disks andthen uses your function to output the steps needed to solve the puzzle.Hint: If you could move up n−1 of the disks from the first post to thethird post using the second post as a spare, the last disk could be moved fromthe first post to the second post. Then by using the same technique you canmove the n−1 disks from the third post to the second post, using the firstdisk as a spare. There! You have the puzzle solved. You only have to decidewhat the nonrecursive case is, what the recursive…arrow_forward
- Computer sciencearrow_forwardPersonal project Q5. This question is concerned with the design and analysis of recursive algorithms. You are given a problem statement as shown below. This problem is concerned with performing calculations on a sequence A of real numbers. Whilst this could be done using a conventional loop-based approach, your answer must be developed using a recursive algorithm. No marks will be given if your answer uses loops. FindAverageAndProduct(a1, ...., an) such that n > 1 Input: A sequence of real values A = (a1, ...., an) Output:, A 2-tuple (average, product) containing the average (average) of all the values and the product (product) of all the values of the elements in A. Your recursive algorithm should use a single recursive structure to find the average and product values, and should not use two separate instances of a recursive design. You should not employ any global variables. (a) Produce a pseudo code design for a recursive algorithm to solve this problem. (b) Draw a call-stack…arrow_forwardPersonal project Q5. This question is concerned with the design and analysis of recursive algorithms. You are given a problem statement as shown below. This problem is concerned with performing calculations on a sequence ? of real numbers. Whilst this could be done using a conventional loop-based approach, your answer must be developed using a recursive algorithm. No marks will be given if your answer uses loops. FindAverageAndProduct(a1, ...., an) such that n > 1 Input: A sequence of real values A = (a1, ..., an) Output:, A 2-tuple (average, product) containing the average (average) of all the values and the product (product) of all the values of the elements in A. Your recursive algorithm should use a single recursive structure to find the average and product values, and should not use two separate instances of a recursive design. You should not employ any global variables. (a) Produce a pseudo code design for a recursive algorithm to solve this problem. (b) Draw a call-stack…arrow_forward
- We have discussed greedy algorithm during lectures. A greedy algorithm is an algorithm that recursively construct a set of objects from the smallest possible constituent parts. At each one of the iterations, the algorithm takes the best that it can get right now, without regards for future consequences. The algorithm hopes that by choosing a local optimum at each one of the iterations, it can end up at a global optimum. In this assignment, you will write a program to schedule final examination for the examination department so that no student has two examinations at the same time. The goal of this assignment is to expose you to the implementation of greedy algorithms that solves a problem with constraints. You will use a greedy algorithm to determine an assignment of classes to examination slots (schedules) such that: 1. No student, enrolled in two subjects, is assigned to the same examination slot (schedule.) 2. Anyattempttocombinetwoslotsintoonewouldviolaterule1. Input to the program…arrow_forwardMatlab Questionarrow_forwardThe following recursive definition of a set S over {a, b, c, d}. Basis: "", a, b, c E S. Recursive Step: If ax E S, then bax ES and cax E S. If bx € S, then cbx € S. If cx = S, then bax ES and bcx = S. If dx E S, then ddx E S. Closure: SE S only if it is a, b or c or it can be obtained from a, b or c using finitely many operations of the Recursive Step. a) What recursive step can be removed from the above definition and why? b) Derive from the definition of S that bcbc S. c) Explain why baa & S.arrow_forward
- The following code is implementing a Treasure map use the A* algorithm to find the shortest path between two points in a map. It appears that the initial compare looks at the f_cost and decides that we are at the point in the map and exits the routine and prints only the starting point. I'm not sure how to fix it, any help would get appreciated. Example of the output from the following Python program: start place = (0, 0) Treasure location: (29, 86) Path to treasure:(0, 0) Python Code: import heapqimport random class Tile: def __init__(self, x, y): self.x = x self.y = y self.is_obstacle = False self.g_cost = 0 self.h_cost = 0 self.f_cost = 0 self.parent = None # Define comparison methods for Tile objects based on their f_cost def __lt__(self, other): return self.f_cost < other.f_cost def __eq__(self, other): return self.f_cost == other.f_cost class Map: def __init__(self, width, height):…arrow_forward1. A certain computer algorithm executes four times as many operations when it is run with an input of size n as when it is run with an input of size n – 1. Here, n > 1 is an integer. When the algorithm is run with an input of size 1, it executes 12 operations. How many operations does the algorithm execute when it is run with an input of size 5? How many operations does the algorithm execute when it is run with an input of size n?arrow_forwardhelp in pytyhonarrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education