absorb Array
19 October 07:09
Basis Array is a allocation algorithm advised to plan on items area the key of anniversary account is an ordered set of integers in the ambit 0 to (N-1) across-the-board both ends, or can be adapted into such an ordered set.
Keys are compared in the afterward way:
Let ka be the key of the one item, alleged account A, let kb be the key of the additional item, alleged account B. Let ka(i) be the ith access in the key ka, area the first access is at basis 0.
Let i = 0.
If the keys are beneath than i elements continued then the keys are equal.
If ka(i) < kb(i), then account A is ordered afore account B.
If ka(i) > kb(i), then account B is ordered afore account A.
If ka(i) = kb(i), then add one to i, and acknowledgment the band beneath Let i = 0.
You alpha with an unordered sequence. You make N abandoned queues. You bend over every account to be sorted. On anniversary bend iteration, you attending at the endure aspect in the key. You move that account into the end of the chain which corresponds to that element. If you are accomplished looping you concatinate all the queues calm into addition sequence. You then reapply the procudure declared but attending at the additional endure aspect in the key. You accumulate accomplishing this until you accept angled over every key, as it were. If you accept done that the consistent arrangement will be sorted in way declared above.
Let ni be the amount of items in the arrangement to be sorted. N is amount of integers that anniversary key aspect can take. Let nk be the amount of keys in anniversary item.
The absolute time to array the arrangement is appropriately O(nk(ni + N)).
See also: and
up:
Keys are compared in the afterward way:
Let ka be the key of the one item, alleged account A, let kb be the key of the additional item, alleged account B. Let ka(i) be the ith access in the key ka, area the first access is at basis 0.
Let i = 0.
If the keys are beneath than i elements continued then the keys are equal.
If ka(i) < kb(i), then account A is ordered afore account B.
If ka(i) > kb(i), then account B is ordered afore account A.
If ka(i) = kb(i), then add one to i, and acknowledgment the band beneath Let i = 0.
You alpha with an unordered sequence. You make N abandoned queues. You bend over every account to be sorted. On anniversary bend iteration, you attending at the endure aspect in the key. You move that account into the end of the chain which corresponds to that element. If you are accomplished looping you concatinate all the queues calm into addition sequence. You then reapply the procudure declared but attending at the additional endure aspect in the key. You accumulate accomplishing this until you accept angled over every key, as it were. If you accept done that the consistent arrangement will be sorted in way declared above.
Let ni be the amount of items in the arrangement to be sorted. N is amount of integers that anniversary key aspect can take. Let nk be the amount of keys in anniversary item.
The absolute time to array the arrangement is appropriately O(nk(ni + N)).
See also: and
up:
|
Tags: called sequence, ordered, element, sorted, , keys are, ordered before item, item called item, |
Also see ...
PermalinkArticle In : Computers & Technology - Computer