Re: !! Help !! Finding an open range within a range of numbers



"Justin" <j.a.dorus@xxxxxxxxx> wrote in message
news:1124914502.138611.260810@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

> I have a range of numbers (1-10000). These numbers correspond as record
> numbers in a table. I am looking for some sort of algorithm or
> pseudocode that can find a variable amount of consecutive open values.
> Say for instance...I need 13 consecutive un-occupied numbers starting
> with the lowest available.
>
> I understand that if I find the lowest, and check the next value all
> the way up until the variant (13 in this case) it should go to the next
> available and try counting from there, but for some reason...I'm just
> drawing a blank with the best way to code this.

Just start with _any_ way to code it. Ten thousand isn't much anymore;
the most naive algorithm possible is probably good enough. You have the
idea, and it is sound. Just loop over all your data and keep a counter
for the length of the range of free cells you're currently in. In every
cell, either increment it or reset it to zero. (_Don't_ look if it was
zero already.) When it reaches N, break. When you reach the end of the
input, fail. You're probably not seeing the simplicity because you want
to look for holes. Just look at all cells in turn; seeing holes comes
on top of that.

This is of course an extremely well researched problem. All disk and
memory allocation comes back to it. Most algorithms require a "free
list" or construct it every time. Standard algorithms include first
fit, best fit, worst fit (a better contender than it might sound) and
the usual champion circular first fit. You don't say if you ever get
ranges back; if so, you may want to merge adjacent free blocks.

An alternative is to not require a single free block, but to have
some indexing scheme. FATs, inodes, sector chaining...

Groetjes,
Maarten Wiltink


.



Relevant Pages

  • Re: Looking for a formula
    ... What i was looking for is that formula or algorithm. ... fit it into my cells and such but a generic one to start off with so that i ... The simplest would be the algorithm that you use to compute price given area ...
    (microsoft.public.excel.programming)
  • Re: How much requirement documentation up front?
    ... provide a best fit for a particular product. ... where there is no historical data or products where consumer habits ... fitting analysis again and selects a new algorithm. ... The fact that the software product itself makes it very convenient to ...
    (comp.object)
  • Re: MetaCollider update
    ... There are two algorithm types: labyrinths and cells. ... Matter labyrinths are closely connected ...
    (rec.games.roguelike.development)
  • Re: Field of view algorithm implementation problems
    ... recursive shadow casting algorithm to mark some cells as visible. ...
    (rec.games.roguelike.development)
  • Re: Field of view algorithm implementation problems
    ... If I understand, you mark all cells as 'not visible', then use the ... recursive shadow casting algorithm to mark some cells as visible. ...
    (rec.games.roguelike.development)