baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:
i'm not sure if i'm on the right place too ask this question , but from some previous posts i see people are explaining their reasons for doing something through complexity.
so my question is the following:
let say i have one big table in ascii format(csv) and the 5 smaller ones. what i wish to do is search the big table with each and every small one. so when i import all those tables into sql db and make i query that takes each and every small data set and selects those data from the big table, in my understanding what i'm actually doing is :
but if i hash all the small tables in a way:N = 5 - number of small tables H = 100 rows -size of the small tables K = 10000 rows - size of the big table for(1..5){ # of those smaller ones for(1..100){ # number of steps i do when iterating through the smal + table for(1..10000){ # number of steps i do when iterating through big t +able //select a row } } } so \theta(NHK) is the complexity for that algorithm(?)
my key is the value from the the small tables and its values are pointing to from which table did i take the value. so what can i do now is to while loop through the big table and for every row evaluate directly to which group does my data belongs to. example: if a hit the row that holds the str101 i now that that data belongs to the second small table.value table ----- ----- %hash = (str1 => 1, str2 => 1, ... str100 => 1, str101 => 2, str102 => 2, ...);
so my question now is: is this just a faster implementation (because it runs much more faster than with db engine) or did i change the complexity to
so the problem is how to treat hashed data.for (1..5){ # hash tha data from smalo tables } while(1..10000){ # crosscheck with hash } so what i got is \theta(NH+K)
thank you
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how do hashes work - complexity question
by zwon (Abbot) on Jul 11, 2009 at 08:27 UTC | |
by holli (Abbot) on Jul 11, 2009 at 09:19 UTC | |
by zwon (Abbot) on Jul 11, 2009 at 11:51 UTC | |
by baxy77bax (Deacon) on Jul 11, 2009 at 09:28 UTC | |
by zwon (Abbot) on Jul 11, 2009 at 11:37 UTC | |
by Anonymous Monk on Jul 11, 2009 at 10:06 UTC |