Re: Extremely easy question about Time to check table look-ups
- From: "Gene" <gene.ressler@xxxxxxxxx>
- Date: 16 Jul 2006 20:11:02 -0700
todaysmulan@xxxxxxxxxxxxx wrote:
I am not sure about this, because making a table like this sounds
really stupid
i create a simple 100x100 table called A, with "switch" statements
***
switch(something){
switch(someotherthing){
switch(otherthng){
....}
....}
....}
***
something really long like that till 100x100 cells are neatly
organized. But each of those cells when processed, again link to
another 100x100 table called B which i also create with "switch"
statements.
if I do a search in that table, I guess (a) my time complexity is O(1),
correct ? (b) I will know there will be other ways to make a table that
would save more memory if you are willing to tell me.Thanks
Not stupid if there is no other way to do it. If you give more
details, maybe you'll get suggestions on cleaner methods.
The answer to your question is trivially O(1) because you know in
advance that there are 100 cases!
I suppose you mean that _if_ then number of branches was a variable N,
would the branch time depend on N? The answer is it's compiler
dependent. If the case values are nearly continguous, most compilers
will generate a simple jump table, so the branch will be just a couple
of instructions. If the cases are spread out in a 32- or 64-bit space,
the simple jump table would would be too big to be practical. Then
there are several options. You'll have to inspect the compiler output.
Partitioned jump tables, hashing schemes, and binary search are all
possibilities.
.
- References:
- Extremely easy question about Time to check table look-ups
- From: todaysmulan
- Extremely easy question about Time to check table look-ups
- Prev by Date: Extremely easy question about Time to check table look-ups
- Next by Date: Re: virus makers and defense systems
- Previous by thread: Extremely easy question about Time to check table look-ups
- Index(es):
Relevant Pages
|