largest no

  • Thread starter bele_harshad2006
  • Start date
J

Joachim Schmitz

how can i pick up largest no from 5 rows by 5 column matrix????
By copmaring the first with the send, then the larted of that comparisn with
the 3rd, the larger of that with the 4th and so on until the 25th

Bye, Jojo
 
M

mark_bluemel

how can i pick up largest no from 5 rows by 5 column matrix????

Step 1. Sort the columns of each row into ascending order.
Step 2. Sort the rows into ascending order using the last column as
the key.
Step 3. Pick the last column of the last row.
 
R

Richard Heathfield

(e-mail address removed) said:
Step 1. Sort the columns of each row into ascending order.
Step 2. Sort the rows into ascending order using the last column as
the key.
Step 3. Pick the last column of the last row.

I'm sure we can do better than O(c log c + r log r). Perhaps we should
specify a particular sort. That can get us right up to O(c^2 + r^2)
without any major effort. But can anyone find an exponential-time
algorithm?
 
M

mark_bluemel

(e-mail address removed) said:



I'm sure we can do better than O(c log c + r log r). Perhaps we should
specify a particular sort. That can get us right up to O(c^2 + r^2)
without any major effort. But can anyone find an exponential-time
algorithm?

There's a big problem here, though - how can we sort anything when we
don't know how to tell whether one thing is larger than another?
 
J

Joachim Schmitz

There's a big problem here, though - how can we sort anything when we
don't know how to tell whether one thing is larger than another?
Hmm, the OP talked abut 'no' wich I assume to mean 'number', so it probably
is some integral or floating point number, which are fairly easy to find the
larger.

Bye, Jojo
 
M

mark_bluemel

Hmm, the OP talked abut 'no' wich I assume to mean 'number', so it probably
is some integral or floating point number, which are fairly easy to find the
larger.

Finding the largest value in some set is a trivial extension of
finding which of two values is the larger - if the OP wanted us to
write code to do the former, it implies they probably can't do the
latter...
 
J

Joachim Schmitz

Hmm, the OP talked abut 'no' wich I assume to mean 'number', so it
probably
is some integral or floating point number, which are fairly easy to find
the
larger.

Finding the largest value in some set is a trivial extension of
finding which of two values is the larger - if the OP wanted us to
write code to do the former, it implies they probably can't do the
latter...[/QUOTE]
To me it sounds like a homework assignment...
 
J

Joachim Schmitz

CBFalconer said:
You apparantly totally missed the humor involved in RH's post.
Me too I must admit. Isn't that what smileys have been invented for?

Bye, Jojo
 
K

Keith Thompson

Richard Heathfield said:
(e-mail address removed) said:

I'm sure we can do better than O(c log c + r log r). Perhaps we should
specify a particular sort. That can get us right up to O(c^2 + r^2)
without any major effort. But can anyone find an exponential-time
algorithm?

Google "permutation sort".
 
T

Tor Rustad

Richard said:
(e-mail address removed) said:
I'm sure we can do better than O(c log c + r log r). Perhaps we should
specify a particular sort. That can get us right up to O(c^2 + r^2)
without any major effort. But can anyone find an exponential-time
algorithm?

Arrgh.. exponential-time??! The worst sorting algorithms I know, are
O(N^2). :-/

I can't remember Knuth or Sedgewick, discussing anything worse than that.

Give a hint please..
 
R

Richard Heathfield

Tor Rustad said:
Arrgh.. exponential-time??! The worst sorting algorithms I know, are
O(N^2). :-/

I can't remember Knuth or Sedgewick, discussing anything worse than
that.

Give a hint please..

Well, let's see now...

while not sorted
exchange two elements at random
endwhile

That would do it, I think.
 
J

Joe Wright

how can i pick up largest no from 5 rows by 5 column matrix????
No matrices in C, sorry. We do have arrays though. Consider..

int arr[5][5];

Does this satisfy your description of a matrix?

The arr array has 25 elements. We can find the largest of them by simply
tripping through the array comparing 'this' one to the previously larger
one. The position of the largest element in the array might also be of
interest. Consider..

int i, j, r, c, max = 0;

for (i = 0; i < 5; ++i)
for (j = 0; j < 5; ++j)
if (arr[j] > max) {
max = arr[j];
r = i, c = j;
}

When this finishes, max will hold the largest int and r and c will tell
you where it is. And very quickly.
 
K

Keith Thompson

Richard Heathfield said:
Tor Rustad said:

Well, let's see now...

while not sorted
exchange two elements at random
endwhile

That would do it, I think.

If the exchanges are truly random, that's not guaranteed to terminate,
so it doesn't qualify as an algorithm.
 
K

Keith Thompson

CBFalconer said:
Yes it is, given sufficient time and a really random generator :)

No, it's not. A truly random generator can generate any possible
sequence, including a sequence that causes the code to repeatedly swap
the first two elements forever. The worst-case behavior is that it
never terminates.

It isn't certain to terminate, but it terminates in some finite time
with probability 1. I *think* that's right. In any case, this
stopped being about C some time ago.
 
C

Clark Cox

Yes it is, given sufficient time and a really random generator :)

No, given a truly random number generator, the probability that it will
terminate *approaches* 100% as time approaches infinity. However you
never have an absolute guarantee that it will terminate as there is a
non-zero chance that , for instance, the sequence of numbers is nothing
but the number 42 repeated an infinite number of times.
 
M

mark_bluemel

I didn't.
Me too I must admit. Isn't that what smileys have been invented for?

As Denis points out, that would ruin the joke. "Dry" humour and irony
(both rather British) should never be sullied with emoticons.
 
M

mark_bluemel

how can i pick up largest no from 5 rows by 5 column matrix????

No matrices in C, sorry. We do have arrays though. Consider..

int arr[5][5];

Does this satisfy your description of a matrix?

The arr array has 25 elements. We can find the largest of them by simply
tripping through the array comparing 'this' one to the previously larger
one. The position of the largest element in the array might also be of
interest. Consider..

int i, j, r, c, max = 0;

Did the problem statement indicate that the numbers were necessarily
positive?
for (i = 0; i < 5; ++i)
for (j = 0; j < 5; ++j)
if (arr[j] > max) {
max = arr[j];
r = i, c = j;
}

When this finishes, max will hold the largest int and r and c will tell
you where it is. And very quickly.


<Identity=OriginalPoster>
Thank you for that solution. I got full marks on the assignment. My
instructor was impressed with my progress.

May I post you the next assignment directly?
</Identity>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top