Design and implement an algorithm to simulate car re-organizing of the train at the railway switching junction. You can only use stacks as the data structure to represent the train and the cars in each transit rail.
Task 1: For any given input of car order is c1,c2,...,cn and a number k of transit rails (k≥2), design and implement an algorithm to simulate the car ordering procedure by using stack operations only so that the output of the car order is 1,2,...,n.
Task 2: Analyse efficiency of your algorithm using Big-O notation by counting the number of stack operations used in your algorithm ( worst case analysis).
Task 3: Assume that k=n/2+1. Improve your algorithm so that its complexity is in O(n).
Task 4: Discuss the efficiency of your algorithm in relation to k if k can be any number such that k≥2.