Suppose I have a constant (once built doesn't change) balance tree with N nodes, every internal node having p children. Obviously the worse case scenario for accessing a node is logp(N). But what about the amortized cost for accessing r nodes? what if we access them in ascending order (having a search tree)? is it just (logp(N))/r?
Asked
Active
Viewed 159 times
1
-
The cost for 2 nodes can for sure not be lower than the cost for 1 node. I can't be logp(N)/r – bruce_ricard Mar 12 '13 at 00:15
-
Well as I understand it, amortized analysis does some kind of average. – user1377000 Mar 12 '13 at 00:16
-
Is this a **search tree**? Another way of putting this, is there an order imposed on the way links to the children are stored in the parent node? How many values are stored in each node? I am worried that if the answer to the last question is **one** then you will have to touch the children in a linear search to determine which child path to explore in a search. Otherwise, see [B-tree](http://en.wikipedia.org/wiki/Btree) – angelatlarge Mar 12 '13 at 17:56
1 Answers
0
You can certainly compute the amortized cost of accessing every element in a balanced search tree. What you will discover, though, is that "almost all" of the nodes are at the bottom of the tree. (More precisely, for a complete p
-ary tree, 1/p
of the nodes are not leaves). Consequently, the average cost for all accesses will be (roughly) the cost of a leaf access ( logpn
), which is the same as the worst-case cost.

rici
- 234,347
- 28
- 237
- 341
-
-
@user1377000: that's what I'm talking about. Most of the elements are leaves, so the amortized average is very similar to the worst-case. – rici Mar 12 '13 at 00:33
-
@user1377000: you can walk a tree in O(1) time per element, certainly, if that's what you mean. That's a different algorithm from searching. – rici Mar 12 '13 at 01:34
-
Yes but the _amortized_ cost for searching all elements is O(1), isn't it? – user1377000 Mar 12 '13 at 08:25
-
@user1377000, No, the amortized cost is the total cost for searching all elements divided by the number of elements, which will be O(log n) because it is dominated by the cost of searching the leaves. As I said in the answer. – rici Mar 12 '13 at 17:03