Purchase Solution

Using a Linear Search to Find the Smallest Element in a List

Not what you're looking for?

Ask Custom Question

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

Purchase this Solution

Solution Summary

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.

Solution Preview

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 ...

Purchase this Solution


Free BrainMass Quizzes
Javscript Basics

Quiz on basics of javascript programming language.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.