Assembly Line SchedulingProblem statementThis is one of the popular problems which can be solved using a dynamic programming approach. The Assembly line is the mechanism used by industries to manufacture products with less human power and faster speed. In the assembly line, raw material is put on the line, and after a few steps, some operations are done on the raw material. In this problem, we have two assembly lines, and each line has N stations. N stations have their functionality like painting, shapemaking etc. Both the lines are identical in terms of work except for the time used. There are e1 and e2 as the entry time requires entering into assembly line 1 and assembly line 2, respectively. There are also x1 and x2 as exit times for the respective lines. If we are at any particular station, we will add the time of that specific station, and we will move to the next station. We have two options for the next station, either we can go to the next station of the same line, or we can go to the next station of another line. If we choose to go to the next station of another line, we will have to add the transition time to move from the assembly line. In the end, we have to calculate the minimum time required to exit a product from the assembly line. For example: We have two assembly lines, and let's suppose we decided to choose the highlighted path. The time taken will be: 8+12+5+4+3+2+10+12+8+9+2 = 75 units. We have to choose the path which will have the minimum time. Method1We will use a recursive approach to solve the problem. Since at each station, we have two possibilities either we can go to the next station of the same line or go to the next station of another line. Java code: Output: Explanation In the above code, we have two 2d arrays. one array is for the time on each station of both lines, and another 2d array is for the transition time. We can start either from line 1 or line 2. We have two choices, so we took a minimum of both options and started the recursive call. At each station, we took two recursive calls and returned the minimum of both the results. For the base case, if we are at the last station, we will add the time of that station and the exit time of that line and return that value. Since at each successive step, we have two recursion choices so Time complexity: O(2^{n}), where n is the number of stations. Space complexity: O(n) used by recursion. Method2Since there are overlapping recursive calls, we will use a dynamic programming approach to solve this. We will use a tabulation method for this problem, and we will go from bottom to up in the table to get the result. Java code: Output: Time complexity: O(nx2) Space complexity: O(nx2) We can reduce the time complexity to the constant because, in the table, we need just two entries of the next iteration, which has already been solved. Method3Java code: Output: Explanation In the above code, we have used just four variables instead of an array, which is independent of the number of stations, so it is in constant time. Time complexity: (nx2) Space complexity: O(1)
Next TopicBreadth First Search or BFS for a Graph
