Big O Notation problem
I have the following problem to solve and I can't remember Big O
notation. Can anyone help?
Given the following code:
printSubTree(id){
node = select * from Tree where id = <id>
output node
subNodeIds = select id from Tree where parentId = <id>
for each subNodeId in subNodeIds
printSubTree(subNodeId)
}
Using O() notation, describe how many queries this algorithm makes to
the database for a subtree with n nodes.
The second part of the problem says:
Describe how you would change the algorithm or change the structure of
the tree in the database to reduce the number of queries to the
database from an O() notation standpoint. Be sure to use O() notation
to describe the performance of your new algorithm. (To be clear, we
are looking for an algorithm that gives a smaller O() value, not just
an algorithm that results in fewer queries.)
Any help would be appreciated!
Thanks
Bryan
.
Relevant Pages
- Big O Notation problem
... for each subNodeId in subNodeIds ... Using Onotation, describe how many queries this algorithm makes to ... (comp.programming) - Re: Building Unification Table - tranforming prolog like notation into lisp notation
... If I don't pass my AI intro with Lisp course I won't be able to play ... notation problem comes from tranlating prolog notation into lisp ... basic algorithm is a heavy user of resources. ... A slow growing ... (comp.lang.lisp) - Re: merits of Lisp vs Python
... any algorithm that deals with a fixed-number of elements ... That isn't how Onotation is defined. ... performance parameter), that still expresses an upper bound of some ... regardless of how large N gets: the upper bound is a function of the ... (comp.lang.lisp) - Re: Big Oh Notation
... Notation, but what puzzles me is a question in Sedgewick's algorithm ... Some motorcycles are the traditional ones, ... which get roughly a constant miles/gallon. ... (comp.programming) - Re: which is better, string concatentation or substitution?
... here's a quick tutorial to "big-oh" notation. ... For any algorithm, if you process n things (in the case of the strings ... but it doesn't really matter for small values of n. ... of time no matter how long the string is. ... (comp.lang.python) |
|