# finding maximum - Page 2

•  Subject
• Author
• Posted on

## Re: finding maximum

Or just use ordinary C, sometimes called C-plain
--
Fred K

## Re: finding maximum

wrote:

I've heard it called ANSI-C, but that may be too specific.
We got your C flavor, strawberry, bannana, vanilla, chocolate
and bannana-split C cream pie.

-sln

## Re: finding maximum

You have made my day. Thank you so much.

## Re: finding maximum

[I note that the OP has not yet had any responses that move him
forward technically (nice try, though, Eric!). So the first part of
this response is a token effort in that direction.]

sandeep said:

Use the comparison operator.

Store the first number in the set, making it the "current maximum".
Then use the comparison operator in a loop, updating the current
maximum whenever appropriate.

See above.

Well, personally I wouldn't do it in Perl, but no doubt the fine
folks in comp.lang.perl.misc /would/ do it in Perl, and that is
their right and privilege.

C is expressively powerful, whereas Perl is powerfully expressive.

--
Richard Heathfield <http://www.cpax.org.uk
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999

## Re: finding maximum

wrote:

Pretty lose language. Can you give examples of that?

-sln

## Re: finding maximum

sln@netherlands.com said:

<snip>

That's wonderfully self-referential. Thanks for the smile.

See IOCCC for examples of expressively powerful C. See CPAN for
examples of expressively powerful Perl.

--
Richard Heathfield <http://www.cpax.org.uk
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999

## Re: finding maximum

wrote:

Why don't you 'C' a doctor for examples.

-sln

## Re: finding maximum

wrote:

Form a set containing the two numbers.  Remove the smaller one
from the set.  The one remaining in the set is the maximum.

Divide the set into two subsets.  Find the maximum of each
subset.  Apply the method in step (a) to find the maximum of the
two maximums.

I would post a query in usenet and let real experts answer the
question.

Richard Harter, cri@tiac.net
http://home.tiac.net/~cri , http://www.varinoma.com
If I do not see as far as others, it is because
I stand in the footprints of giants.

## Re: finding maximum

sandeep wrote:

The simple answer is: "Post the problem to the usenet and wait for
others to solve it for you".

--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html

## Re: finding maximum

Josef Moellers wrote:

Well, that doesn't seem to work too well.

--
Bart.

## Re: finding maximum

s> How would you find the maximum of
s> (a) two numbers
s> (b) a set of numbers
s> in idiomatic C? How would you do it in idiomatic Perl?

In any language, you put the numbers in an array, sort the array, and
return the element at the top.  Similarly, to get the average, you sort
the array and then return the middle number (AKA the "median average").

In Perl sorting is even built into the language; in C unfortunately you
have to embed the Perl interpreter to get that kind of simplicity.

s> Use this as a basis for a discussion of the differences in expressive
s> power of the two languages.

We are programmers, sir.  Discussion does not become us.  We are always
right, even when we're wrong.

Ted

## Re: finding maximum

Ted Zlatanov wrote:

That's at best an O(N log N) solution. There's an O(N) solution which
is even simpler; sandeep presented the basic idea for that solution

In C, sorting is built into the standard library: qsort(). It may be
clumsier to use, perhaps, than Perl's sort, but it's still an easier
solution for a C program than embedding the perl interpreter.

## Re: finding maximum

wrote:

j> Ted Zlatanov wrote:

s> How would you find the maximum of
s> (a) two numbers
s> (b) a set of numbers
s> in idiomatic C? How would you do it in idiomatic Perl?

j> That's at best an O(N log N) solution. There's an O(N) solution which
j> is even simpler; sandeep presented the basic idea for that solution

What do you mean, O(N log N)?  Sorting is O(1), it's an OS function!

j> In C, sorting is built into the standard library: qsort(). It may be
j> clumsier to use, perhaps, than Perl's sort, but it's still an easier
j> solution for a C program than embedding the perl interpreter.

You must be joking!

(I was, see the date :)

Ted

## Re: finding maximum

Ted Zlatanov wrote:

...

I hope that statement was a continuation of your joke.

No. I do joke sometimes, but this wasn't an example.

My apologies; not every message posted on that date is a joke, it's
sometimes hard to tell which are which.

## Re: finding maximum

Unless the array might be "large".

Your algorithm is likely O(n log n) when finding the maximum can
be done in only O(n).

Sure we do. We discuss stuff all the time.

But we discuss what interests us.

That is, we do not take direction from random usenauts.

--
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

## Re: finding maximum

s> How would you find the maximum of
s> (a) two numbers
s> (b) a set of numbers
s> in idiomatic C? How would you do it in idiomatic Perl?

TJM> Unless the array might be "large".

TJM> Your algorithm is likely O(n log n) when finding the maximum can
TJM> be done in only O(n).

Sorry, Tad, you got hooked.  Happy April Fools :)

TJM> Sure we do. We discuss stuff all the time.
TJM> But we discuss what interests us.
TJM> That is, we do not take direction from random usenauts.

I was kidding on that one too, I promise ;)

Ted