in reply to finding min and max of array recursivly
I'm taking a data structures and algorithms class -- if I'm correct, I believe your recursive code is O(n log n), whereas mine is O(n).sub min_max (\@) { my $min = my $max = $_[0][0]; for (@{ $_[0] }[1 .. $#{ $_} ]) { $_ < $min and $min = $_, next; $_ > $max and $max = $_; } return ($min,$max); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: finding min and max of array recursivly
by mbond (Beadle) on Sep 28, 2000 at 17:53 UTC | |
by japhy (Canon) on Sep 28, 2000 at 19:32 UTC | |
by Anonymous Monk on Sep 28, 2000 at 20:08 UTC | |
by japhy (Canon) on Sep 28, 2000 at 21:19 UTC |