Answered step by step
Verified Expert Solution
Question
1 Approved Answer
8. (bonus 10 points) A train switch is shown in Figure 3. The switch enables you to determine if a train-car, moving from left to
8. (bonus 10 points) A train switch is shown in Figure 3. The switch enables you to determine if a train-car, moving from left to right, will end up on the Left section of the track or on the right Section. A train with n cars arrives to sector-A of the train tracks. See Figure 3. Next to this segment of the tracks there is a switch (See Figure ?? that connects to segments L and R (See Figure 3). Each car in the train has a unique number. Your goal is to rearrange the order of the cars so the cars are in decreasing order of these numbers. The first car has the smallest number, etc. Each car is allowed to pass the switch only O(log n) times. Your pseudo-code could include commands like 'drive a car from segment A to segment R. Do not worry about how cars move - if you want them to, they will. (they each have their own engine). You just need to tell them what to do. Train cars cannot leave the tracks, jump in front of other cars, or any other unrealistic behavior. For more on train switches see this Wikipedia Link. Input: Section L(Left) Section 4 Car, Cary Cars Car3 Section Right) Output: Section LLO) Section 1 Cars Cars Car, Car, Section (Right) Figure 3: An example of the input and output of the algorithm for n = 4: The train comes from the left direction, along section A (blue). You could move cars to section L or R, and/or moving them back to section A. In the top example, the order of the cars is (1, 2, 4, 3), while after applying your algorithm, the order should be (4,3,2,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