Wednesday 15 August 2012

algorithm - amortized analysis on min-heap? -


If we are doing n on the empty pile, insert arbitrary and remove operation (given Delete in the heap with the location) Why amortized analysis to insert O (1) and delete O (log n) ?

  a) Insert o (log o (1) b) o (1) delete, remove o (log n), delete o (log n) c) insert o (( 1), o (1)  

Can any person make it clear to me? Based on your question and comments on the basis of

I am going to take a binary pile.

First of all, the worst case for logging the worst case and the removal is the smallest object o (log n). This stack tree structure Occurs from. It is that, for the pile of N objects, the tree has the log (N) level.

Inclusion is included (rational) to add items as the lowest right-most node in the tree, and then to "bubbling" to the required level, if the new item is smaller than the root, then on top it All the way to bubble - all the logs (n) levels so if you put numbers 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 in a minimum heap, Will hit the worst case.

Removal is the substitute of the smallest item (root) with the last item of the smallest item, and then the item can take up the log (N) operation "again" under "appropriate location"

This is the worst case, the average case is very different.

Remember that in a binary pile, half nodes are leaves - they have some Not a child So if you are going to put items in random order, then half time item you join It is going to be at the lowest level and there is no "bubble up" to do this, so your inserting operation is half time (o). From the other half, half of the those second level And so on.Only once you actually work on log (n) entry, that item occurs when the item you are adding is smaller than the current root item. It is quite possible, therefore, The observed time behavior is that the insertion is (1) In fact, this behavior will be if you insert a sorted array into a small stack, that is, if you have 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 values ​​in that order Were involved.

When the minimum item is the minimum stack, you take the last thing from the stack and sprinkle it from top to top. The "half time" rule plays again, but this time it is working against you, the last thing that you had taken from the heap, probably comes down to low level. You have to filter it all the way back, which takes the log (n) operation half time you have to do all logs (n) for the rest of the rest you have to do all that, but One of them etc., and in fact the minimum levels you will have to bow down, will depend on the depth of the tree. For example, if you have more than three items in your heap, then you know that the removal of the smallest item will require at least one down-down operation because the next-minimum item will always be The tree is at the second level.

It has been found that, in the average case, entry into a binary heap takes much less from the time of log (log n). This is probably close to o (1). And the removal from the binary pile is close to the worst case of O (log n).


No comments:

Post a Comment