You are designing an airline terminal with a hallway & moving walkways. The hall
ID: 3696932 • Letter: Y
Question
You are designing an airline terminal with a hallway & moving walkways. The hallway is N feet long, and we will view it as stretching from point 0 to point N along the interval [0, N]. You can’t install moving walkways on top of each other or next to each other, so at any location on this hallway, there can be at most one moving walkway.
You are given N and a set of m pairs { (s1, t1),(s2, t2), . . . ,(sm, tm) } indicating all the places it would be possible to install the walkways.
Pair (si , ti) indicates that it would be possible to install a walkway going from point si to point ti. Assume that si < ti in all pairs (si , ti). Important: Also, assume that the pairs are sorted in increasing order of ti, so ti ti+1.
We want to minimize the distance that people will have to walk (by themselves, not on a walkway) when they need to travel from one end of the hallway to another.
QUESTION PART 1:
Design an algorithm that calculates the minimum distance people would have to walk, under the best selection of walkways. For example, suppose N = 10 and the installation pairs are {(1, 4),(3, 8),(5, 9),(8.5, 10)}.
Example: Installing the walkways corresponding to (1, 4) and (5, 9) would result in people having to walk a distance of 3 feet, the minimum distance possible. So your algorithm should return the value “3 feet” on this example.
Note: The values si and ti might not be integers and the running time of your algorithm should NOT depend on N.
-----------------------------------
ALSO, WHEN DEFINING THE ALGORITHM, PLEASE DO THE FOLLOWING: (CHECKLIST)
1. Define a quantity A[k] that you will compute and store in a table. Describe in English what this quantity represents.
2. Give a reccurence for A[k], as well as the base case. Also, describe the order in which the table should be filled in.
3. Give the pseudocode & running time of the algorithm.
Explanation / Answer
import java.applet.*; import java.awt.*; import java.awt.event.*; import java.net.*; //import javax.swing.*; /* */ public class loggedin extends Applet implements ItemListener, ActionListener, KeyListener{ Panel p1,p2,p3; CheckboxGroup c; Checkbox c1,c2; Button b,logout; public void init(){ setBackground(Color.GRAY); p1=new Panel(); p2=new Panel(); p3=new Panel(); p1.setLayout(new FlowLayout(FlowLayout.LEFT)); p2.setLayout(new FlowLayout(FlowLayout.LEFT)); p3.setLayout(new FlowLayout(FlowLayout.RIGHT)); c=new CheckboxGroup(); c1=new Checkbox("Search for Flights",c,true); c2=new Checkbox("Manage booking",c,false); b=new Button("Proceed"); logout=new Button("Logout"); c1.addItemListener(this); c2.addItemListener(this); b.addActionListener(this); logout.addActionListener(this); p1.add(c1); p2.add(c2); p3.add(b); p3.add(logout); add(p1); addHorizontalLine(Color.GRAY); add(p2); addHorizontalLine(Color.GRAY); add(p3); c1.addKeyListener(this); c2.addKeyListener(this); b.addKeyListener(this); } public void keyReleased(KeyEvent ke){} public void keyTyped(KeyEvent ke){} public void keyPressed(KeyEvent ke){ int key=ke.getKeyCode(); if(key==KeyEvent.VK_ENTER) transfer(c.getSelectedCheckbox().getLabel()); } //keyPressed close public void start(){ } public void itemStateChanged(ItemEvent ie){ repaint();} public void actionPerformed(ActionEvent ae){ if(ae.getActionCommand().equals("Logout")){ AppletContext ac=getAppletContext(); URL url=getCodeBase(); try{ ac.showDocument(new URL(url+ "login.html")); System.out.println(url.toString()); //showStatus(url+"book.html"); } catch(MalformedURLException e){ showStatus("Database is down.");} } else{ transfer(c.getSelectedCheckbox().getLabel());} } public void transfer(String s){ if(s.equals("Search for Flights")){ AppletContext ac=getAppletContext(); URL url=getCodeBase(); try{ ac.showDocument(new URL(url+ "book.html")); System.out.println(url.toString()); showStatus(url+"book.html"); } catch(MalformedURLException e){ showStatus("Database is down.");} } else{ AppletContext ac=getAppletContext(); URL url=getCodeBase(); try{ ac.showDocument(new URL(url+ "manage.html")); System.out.println(url.toString()); showStatus(url+"manage.html"); } catch(MalformedURLException e){ showStatus("Database is down.");} } } public void addHorizontalLine(Color c) { // Add a Canvas 10000 pixels wide but // only 1 pixel high, which acts as // a horizontal line. Canvas line = new Canvas( ); line.setSize(1000, 3); line.setBackground(c); add(line); } public void paint(Graphics g){ } }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.