Full Binary Heap Bypass

I'm not sure how to navigate the tree structure below so that the nodes are always in ascending order. The heapifying array [9 8 7 6 5 4 3 2 1 0]leads to an array [0 1 3 2 5 4 7 9 6 8]that seems to fit this view:

heap drawing

The desire to keep the array as it is (because I want to do efficient inserts later), how can I efficiently move it in ascending order? (This is a site visit in that order [0 1 2 3 4 5 6 7 8 9])

+4
source share
3 answers

. - - , .

+2

nofollow " > self-balancing ( BST) :

(BST)... node, :

  • node node.
  • node , node.
  • .
  • .

BST ( ), .

BST O (log n) O (n).

, - O (1) O (n log n), - , , BST, .


, , ( , , , , , , , - ).

- , , , , .. - , , - , .

, , .

, :

  • ()
  • :
    • , ,

O (n log n) O (n) ( , BST O (log n)), .

+1

, BST. @Dukeling , BST , - . , O (1) .

, .

  • , "" .
  • i- n-i, ( ).
  • .

O (n log n). - O (n).

If you don’t need to completely move around, you can stop at any time and “fix” the array by performing the O (n) heapify operation. See pseudo code here , for example.

+1
source

Source: https://habr.com/ru/post/1530033/


All Articles