Please help with the following problem.
I am having trouble figuring out how to determine the last element of the print statement. For array A(N) and input element ARG, what kind of algorithm is needed to determine which element of A(N) is closest to but not greater than ARG? I've gotten this far but can't find anything in my course manual that describes this situation.
If A(1) < ARG > A(N) then
CODE = 2
Print ARG, CODE, A(N) that is closest to but not greater than ARG
In order to find the element in the array with the closest, but not greater than, value to ARG you will have to go through the entire array. Going through an array one element at a time requires some sort of loop statement. So we will have something like this:
I = 0;
WHILE (I < N)
// do ...
In this solution, I demonstrate how to search a list of numbers for the largest value less than a given argument. I start with a simple solution and then add the extra logic necessary for the more complex condition.
Detailed Comparision of Linear and Binary Searches on a List
Suppose that you have a dictionary whose words are not sorted in alphabetical order. As a function of the number, n of words, what is the efficiency of searching for a particular word in this dictionary ?
Do the same for dictionary whose words are sorted alphabetically. Compare results.View Full Posting Details