🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #1244

Re: CASE structures

#1244
From: Preston Briggs
Date: Sun, 14 Oct 1990 16:13
33 lines
1573 bytes
In article <344.2716D868@puddle.fidonet.org> Pat.Terry@p101.f4.n494.z5.fidonet.org (Pat Terry) writes:
>
>In Message-ID: <39707@eerie.acsu.Buffalo.EDU> Brian McNamara writes
>
> >I am using the latest FST compiler. I was attempting to write a program 
>...
> >ocurence sampling tables from a text book. What I ended up with was a case
> >construct with 26 possibilities but the range f possibilities was from
> >1 to 10000.

>
>IF a = 1 THEN one
>  ELSIF a = 34 THEN two
>  ELSIF a = 98 THEN three
>  .....
>  ELSIF a = 26 THEN twentysix?
>
>may be clumsy.  If you arrange in a clever order matching on probability
>of occurrence it won't be too bad.

Could also arrange a binary decision tree.
Or, at some cost in space, build an array 1000 long, and fill in the answers.

The multiple IF thing will have cost O(n), where n is the number of
possible value for a.  A binary decision tree (or a compact array
that's binary searched) will cost O(log n), and the big array will
be constant time.

Normally, I'd pick one of the binary search options.

-- 
Preston Briggs				looking for the great leap forward
preston@titan.rice.edu
Technical Details
Message-ID: <1990Oct14.161354.25560@rice.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!rice!titan.rice.edu!preston
References: <344.2716D868@puddle.fidonet.org>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!rice!titan.rice.edu!preston
From: preston@titan.rice.edu (Preston Briggs)
Newsgroups: comp.lang.modula2
Subject: Re: CASE structures
Message-ID: <1990Oct14.161354.25560@rice.edu>
Date: 14 Oct 90 16:13:54 GMT
References: <344.2716D868@puddle.fidonet.org>
Sender: news@rice.edu (News)
Organization: Rice University, Houston
Lines: 33