Question
________________________________________________________________________ the code should work on the following inputs and the result should be printed as the output ________________________________________________________________________ input1: 5 3 // n=5 number
________________________________________________________________________
the code should work on the following inputs and the result should be printed as the output
________________________________________________________________________
input1: 5 3 // n=5 number of steps, m=3 number of workers 3 1 2 5 // 1st worker steps => 3 is number of steps then 1 2 5 steps can handle 3 1 3 5 // 2nd worker steps => 3 is number of steps then 1 3 5 steps can handle 3 2 3 4 // 3rd worker steps => 3 is number of steps then 2 3 4 steps can handle
output1: 1 1 3 3 2 with 2 switches or 1 3 3 3 1 with 2 switches
input2: 5 4 // n=5 number of steps, m=4 number of workers 1 1 // 1st worker steps => 1 is number of steps then 1 step can handle 3 2 3 5 // 2nd worker steps => 3 is number of steps then 2 3 5 steps can handle 2 3 4 // 3rd worker steps => 2 is number of steps then 3 4 steps can handle 4 2 3 4 5 // 4th worker steps => 4 is the number of steps then 2 3 4 5 steps can handle
output2: 1 4 4 4 4 with 1 switches
2. Assume there are a special task sonsisting of n crucial steps and m workers such that each of them only knows how to deal with a subset of steps. The task switches hands from one worker to another. Devise a greedy algorithm that takes an integer n together with m subsets A1, ..., An (each subset A; contains all the steps that the worker i can handle) as input, and outputs an optimal scheduling that minimizes the number of switches, as an array of n assignments together with an integer indicating the number of switches. All the inputs given to the algorithm are assumed to be legitimate, i.e. the users are assumed to provide only integers. = Assume n = 5, m = 3, and A1 = {1,2,5}, A2 = {1,3,5}, Az = {2,3,4}. Possible schedulings will be as follows :X = [1,1,2,3,1] with 3 switches (from 1 to 2, from 2 to 3, from 3 to 1) X = [1,1,3,3,2] with 2 switches (from 1 to 3, from 3 to 2) X = (1,3,3,3,1) with 2 switches (from 1 to 3, from 3 to 1)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started