Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribedimage text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

Find the derivative. f(x) 8 3 4 mix X O 4 x32 4 x32 3 -4x - x2

Answered: 1 week ago

Question

Know the principles of effective service recovery systems.

Answered: 1 week ago

Question

Explain the service recovery paradox.

Answered: 1 week ago