comp.lang.ada
 help / color / mirror / Atom feed
From: Rick <rickduley@gmail.com>
Subject: Re: Inefficient algorithms
Date: Sat, 11 Sep 2010 18:53:58 -0700 (PDT)
Date: 2010-09-11T18:53:58-07:00	[thread overview]
Message-ID: <48279012-6325-47c7-a8a6-8c1dee19a20a@a4g2000prm.googlegroups.com> (raw)
In-Reply-To: Pine.LNX.4.64.1009111612280.19046@medsec1.medien.uni-weimar.de

Hi Stefan

I have a couple of problems with this algorithm:

> But if you really need (worst-case) exponential time, here is such an
> algorithm for for factoring a number n (or for detecting if n is prime):
>
> function Factor(C: Positive) return (Positive or "is prime") is
>   -- pre C>1
> begin
>   for I in 2 .. C-1 loop
>     if I divides C then
>       return I
>     end if
>   end loop
>   return "is prime"
> end Factor;

1.  This algorithm depends on a single loop.  As I understand loops,
the worst case scenario is C-2 iterations.  That is to say the
algorithm is linear i.e. O(n).

2. How can I write a function which returns a 'choice' of type?  All I
can think of is some trick with discriminate record.



  parent reply	other threads:[~2010-09-12  1:53 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-11  4:24 Inefficient algorithms Rick
2010-09-11  6:51 ` J-P. Rosen
2010-09-13  3:45   ` Robert A Duff
2010-09-11  6:54 ` Niklas Holsti
2010-09-11  7:07   ` Niklas Holsti
2010-09-11  9:07     ` Rick
2010-09-11 15:05       ` Niklas Holsti
2010-09-17  5:26         ` Rick
2010-09-11  9:20     ` Ludovic Brenta
2010-09-11  9:23       ` Ludovic Brenta
2010-09-11 11:20       ` Niklas Holsti
2010-09-11 18:29         ` Peter C. Chapin
2010-09-11 14:28 ` stefan-lucks
2010-09-12  1:04   ` Wilson
2010-09-12  1:53   ` Rick [this message]
2010-09-12  8:35     ` Georg Bauhaus
2010-09-12 11:56     ` stefan-lucks
2010-09-15  1:11 ` BrianG
  -- strict thread matches above, loose matches on Subject: below --
2010-09-15  8:51 Rick
2010-09-15 21:45 ` John B. Matthews
2010-09-16 12:05   ` Chad  R. Meiners
2010-09-16 20:19     ` John B. Matthews
2010-09-17  5:24   ` Rick
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox