Question

You are writing a program to provide driving directions. You start with the simple case of...

You are writing a program to provide driving directions. You start with the simple case of driving along Interstate 55. You have a list of cities along I55: Chicago, Downers Grove, Bolingbrook, Plainfield, Joliet, Channahon, etc. You know the distance from each city to the next one on the list. You want to be able to determine the distance between any pair of cities. Assuming there is a total of n cities, one way to do this is to have as a data structure an array D where D[k] is the distance from city k to city k+1. The algorithm for finding the distance from city i to city j then adds up the entries from D[i] to D[j-1]. The data structure requires n entries and the algorithm performs, in the worst case, n additions. Another way is to have as a data structure an n x n table T where T[i, j] is the distance from city i to city j. The algorithm for finding the distance between city i to city j simply prints out the value of T[i, j]. The data structure here requires n^2 entries and so n^2 steps to initialize, and the distance algorithm performs a single look-up. Please submit a data structure containing n entries and requiring n steps to initialize and a distance algorithm written in pseudocode performing a constant number of operations to determine the distance between any two cities.

Homework Answers

Answer #1

DATA STRUCTURE

class dataStruct
  
   integer array
   array size
  
   constructor:
       for loop of 0 to array size
           initialize array of length "array size"
  

ALGORITHM

   create dataSTruct
   initialize values

   returning distance till integer array [ some index ]
   create variable distance = 0
   for loop of 0 to (some index - 1)
       distance = distance + array distance on index from 0 to (some index)
   print distance

COMMENT DOWN FOR ANY QUERIES AND,

LEAVE A THUMBS UP IF THIS ANSWER HELPS YOU.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Please post all code in Pseudo code. Please post ORIGINAL answers do not copy from similar...
Please post all code in Pseudo code. Please post ORIGINAL answers do not copy from similar questions. Please post in a format that can be directly copied. Reasoning on answers would be most helpful but not required. Thank you in advance for your help. 2. Consider the following algorithm for finding the distance between the two closest elements in an array of numbers. ALGORITHM MinDistance(A[0..n − 1])//Input: Array A[0..n − 1] of numbers //Output: Minimum distance between two of its...
Please post all code in Pseudo code. Please post ORIGINAL answers do not copy from similar...
Please post all code in Pseudo code. Please post ORIGINAL answers do not copy from similar questions. Please post in a format that can be directly copied. Reasoning on answers would be most helpful but not required. Thank you in advance for your help. 1.Design an algorithm to find all the common elements in two sorted lists of numbers. For example, for the lists 2, 5, 5, 5 and 2, 2, 3, 5, 5, 7, the output should be 2,...
This is C programming assignment. The objective of this homework is to give you practice using...
This is C programming assignment. The objective of this homework is to give you practice using make files to compose an executable file from a set of source files and adding additional functions to an existing set of code. This assignment will give you an appreciation for the ease with which well designed software can be extended. For this assignment, you will use both the static and dynamic assignment versions of the matrix software. Using each version, do the following:...
1. Consider a speaker at some fixed position, emitting sound uniformly in all directions. You are...
1. Consider a speaker at some fixed position, emitting sound uniformly in all directions. You are standing at some distance d from this speaker, holding a sound-intensity measuring device. You then walk 25.0 m in a straight line towards the speaker. At this point you observe that the intensity of the sound has doubled (from the previous location). Determine the distance d. There are no echoes or reflections or interference. 2. You are standing equidistant from four identical jet engines...
In your answers, you should properly show your work by writing down your entries into the...
In your answers, you should properly show your work by writing down your entries into the calculator. For instance, if you use the TVM worksheet of your financial calculator to compute how long it takes to double your account balance given 5% annual interest rate, you should write down your entries as: I/Y=5, PV=-1, PMT=0, FV=2, CPT N=? --- the question mark here stands for your answer to the question. Question 6 – PV, Ordinary Annuity, Compounding [2 points]: Find...
Put these steps in neuromuscular junction synaptic transmission and excitation-contraction coupling in chronological order. (Type the...
Put these steps in neuromuscular junction synaptic transmission and excitation-contraction coupling in chronological order. (Type the letters in the appropriate order with no spaces between them). A. Ryanodine receptors open B. Voltage-gated Na+ channels open in the muscle cell membrane near the neuromuscular junction C. Tropomyosin rotates into the groove of the thin filament (out of the way of the myosin binding site) D. Depolarization of motoneuron axon terminal E. Ca2+ dissociates from troponin F. [Ca2+] rises in the muscle...
1. Provide two examples that you did not find in the book of when to use...
1. Provide two examples that you did not find in the book of when to use a related samples t test. 2. A major university would like to improve its tarnished image following a large on-campus scandal. Its marketing department develops a short television commercial and tests it on a sample of n = 7 subjects. People's attitudes about the university are measured with a short questionnaire both before and after viewing the commercial. The data are as follows: Person...
For the following experiment/question, pick the most appropriate statistical test. You have the following statistical tests...
For the following experiment/question, pick the most appropriate statistical test. You have the following statistical tests as choices: some may be used more than once, others not at all.  Assume homogeneity of variance (where applicable) and the validity of parametric tests (where applicable), unless something is directly stated (e.g., “the data are not at all normal”) or otherwise indicated (viz., by the inspection of the data) which would indicate a strong and obvious violation of an assumption. This means you must...
For the following experiment/question, pick the most appropriate statistical test. You have the following statistical tests...
For the following experiment/question, pick the most appropriate statistical test. You have the following statistical tests as choices: some may be used more than once, others not at all. Assume homogeneity of variance (where applicable) and the validity of parametric tests (where applicable), unless something is directly stated (e.g., “the data are not at all normal”) or otherwise indicated (viz., by the inspection of the data) which would indicate a strong and obvious violation of an assumption. This means you...
For the following experiment/question, pick the most appropriate statistical test. You have the following statistical tests...
For the following experiment/question, pick the most appropriate statistical test. You have the following statistical tests as choices: some may be used more than once, others not at all.  Assume homogeneity of variance (where applicable) and the validity of parametric tests (where applicable), unless something is directly stated (e.g., “the data are not at all normal”) or otherwise indicated (viz., by the inspection of the data) which would indicate a strong and obvious violation of an assumption. This means you must...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT