comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Inefficient algorithms
Date: Sat, 11 Sep 2010 11:20:33 +0200
Date: 2010-09-11T11:20:33+02:00	[thread overview]
Message-ID: <87lj78ab6m.fsf@ludovic-brenta.org> (raw)
In-Reply-To: 8f0o4uFct8U1@mid.individual.net

Niklas Holsti <niklas.holsti@tidorum.invalid> writes:
> Niklas Holsti wrote:
>> Rick wrote:
>>> I am working on a class in algorithmic efficiency and, to make a
>>> point, need an algorithm that runs O(2^n) - a factoring algorithm
>>> perhaps.  All I can find is 'C' code I can't decipher.  Can someone
>>> please help with an Ada example.
>>
>> Perhaps the canonical example is this: you are given a Boolean
>> formula containing n Boolean variables. Find a valuation (a value,
>> True or False, for each variable) that makes the formula True.
>
> Replying to myself, since I realize that I probably misunderstood your
> need: what you want is an inefficient O(2^n) solution to an easy
> (non-exponential) problem. The problem I suggested is not, of course,
> an easy one. But it has easy variants. For example, require that the
> Boolean formula uses at most 10 of the n variables, where this limit
> (10) is considered a fixed number independent of the total number (n)
> of variables.

Actually I do think that the problem is trivial and that you can solve
it without recursion.  If you see your array of Booleans as a number in
binary representation:

procedure Inefficient (N : in Natural) is

   subtype Valuation is Natural range 1 .. 2**N;

   -- We assume the solution is Valuation'Last but it could be any value.
   Solution : constant Valuation := Valuation'Last;
begin
   for K in Valuation'Range loop
      exit when K = Solution;
   end loop;
end Inefficient;

-- 
Ludovic Brenta.



  parent reply	other threads:[~2010-09-11  9:20 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 [this message]
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
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