does anyone know how to:
Write the code to determine and display the smallest and largest values contained in a 99 element floating point array named w
14 2067
Yes, I could figure it out.
can you post an example?
Is this a homework question?
yes.. i need it asap
I can't do your homework for you, that would be cheating. Why don't you tell me what you have done so far and maybe I can help guide you in the right direction.
EDIT: Changed thread name to better describe what the question was that was asked.
Well, basically without giving away the answer (because it's a hw question) you would just go through each element of the array and check to see if its smaller than the minimum or larger than the maximum....Us telling you the answer won't help you learn it.
There are many ways to do this. I think the hint that was posted above me is the simplest way to do it.
There are many ways to do this. I think the hint that was posted above me is the simplest way to do it.
Another good hint would be to sort the array, then you know easily which is the lowest and which is the highest.
IMHO it is easier to write efficient sorting algorithms then searching algorithms.
Another good hint would be to sort the array, then you know easily which is the lowest and which is the highest.
IMHO it is easier to write efficient sorting algorithms then searching algorithms.
That's what I was thinking. But if he's asking help for this then he's probably still a beginner. Even though there are some sorting algorithms all over the place, they may be hard to implement.
But yes, if it's a numerical array, make a habit of sorting it before you start manipulating. Most of the time it'll make your life much easier, but in this case, it's not extremely crucial.
That's what I was thinking. But if he's asking help for this then he's probably still a beginner. Even though there are some sorting algorithms all over the place, they may be hard to implement.
But yes, if it's a numerical array, make a habit of sorting it before you start manipulating. Most of the time it'll make your life much easier, but in this case, it's not extremely crucial.
Or even better, sort while you insert then you are guaranteed O(n) sort algorithm.
Or even better, sort while you insert then you are guaranteed O(n) sort algorithm.
Insertion sort? Isn't that O(n**2)? There are n operations (one for each number being inserted), and for each insertion you will traverse approximately n / 2 of the numbers to find the correct insertion place, giving you n * (n / 2) = n**2 / 2 = O(n**2).
Not to mention the extra time necessary to push back the numbers into a new array when the insertion is in the middle.
Assuming the array is in random, unsorted order, the fastest way would be to traverse the array once looking for the highest and lowest values - this will be O(n) time. Any sorting will be greater than O(n).
Insertion sort? Isn't that O(n**2)?
If O(n**2) means O(n^2) then yes...(not sure what **2 means). Insertion sort, bubble sort and selection sort are all O(n^2).
The best sorts would be Heap sort or Merge sort (both O(n log n))
Like Ganon11 said, the best way would be to loop through it once and just check it against a max / min value (this would produce O(n) which is the best you can get with this sort of algorithm )
Insertion sort? Isn't that O(n**2)? There are n operations (one for each number being inserted), and for each insertion you will traverse approximately n / 2 of the numbers to find the correct insertion place, giving you n * (n / 2) = n**2 / 2 = O(n**2).
Not to mention the extra time necessary to push back the numbers into a new array when the insertion is in the middle.
Assuming the array is in random, unsorted order, the fastest way would be to traverse the array once looking for the highest and lowest values - this will be O(n) time. Any sorting will be greater than O(n).
Yes insertion sort is O(n**2). But sorting while you insert gives you an almost sorted array all the time, so at most you would need to traverse all the elements in it once to find the right spot to insert your new element.
does anyone know how to:
Write the code to determine and display the smallest and largest values contained in a 99 element floating point array named w
Getting back to this, I would suggest sorting the array elements which was suggested by RedSon and ahammad earlier and is explained beautifully by Ganon11 here
After you have your elements sorted in this order
Index: 0 1 2 3 4
Array: 1 2 3 5 8
then the very first number (the 0th element of the array) is the smallest value and ofcourse the last number(the nth element, in your case 99th) is the largest value
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Paul Kirby |
last post by:
Hello All
I am trying to update me code to use arrays to store a group of information
and I have come up with a problem sorting the multiple array :(
Array trying to sort: (7 arrays put into...
|
by: Kakarot |
last post by:
I'm gona be very honest here, I suck at programming, *especially* at
C++. It's funny because I actually like the idea of programming ...
normally what I like I'm atleast decent at. But C++ is a...
|
by: Federico G. Babelis |
last post by:
Hi All:
I have this line of code, but the syntax check in VB.NET 2003 and also in
VB.NET 2005 Beta 2 shows as unknown:
Dim local4 As Byte
Fixed(local4 = AddressOf dest(offset))
...
|
by: Karin Jensen |
last post by:
Hi
I am running a PHP program that connects to an Access 2000 database
via ODBC:
$results = odbc_exec($connection_id, $sql_select);
Is it possible to sort the contents of $results? I wish to...
|
by: yatindran |
last post by:
hai
this is my 2d array.
int a = {
{5,2,20,1,30,10},
{23,15,7,9,11,3},
{40,50,34,24,14,4},
{9,10,11,12,13,14},
{31,4,18,8,27,17},
{44,32,13,19,41,19},
{1,2,3,4,5,6},
|
by: Roy Gourgi |
last post by:
Hi,
How would I sort an array?
TIA
Roy
|
by: Kuku |
last post by:
Hi,
Can anyone please tell me good books/sites for sorting and searching.
Finding it a little hard to understand
|
by: SneakyElf |
last post by:
i am very green with c++ so i get stuck on very simple things
anyway, i need to write a program that would
read data from file (containing names of tv shows and their networks)
one line at a time...
|
by: KevinADC |
last post by:
If you are entirely unfamiliar with using Perl to sort data, read the "Sorting Data with Perl - Part One and Two" articles before reading this article. Beginning Perl coders may find this article...
|
by: lemlimlee |
last post by:
hello,
this is the task i need to do:
For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |