C++ binary search tree implementation, dynamic array or structs/class? -


i'm tasked implementing binary search tree , going usual struct route:

struct node {      int value;     node * left;     node * right;     node( int val ) {      ...     } } 

when thought implementing using dynamic array , using arithmetic figure out left , right nodes. question array implementation change time , space complexity of operations (insert, delete, inorder walk, et al.) better or worse?

i can see how delete operation might issue, reorganize array , keep tree's structure, tree size small, hundred nodes max.

will time , space complexity of operations (insert, delete, inorder walk, et al.) change?

inserting , removing non-leaf nodes in array-based tree require moving elements come after in array. changes complexity o(log n) o(n log n).

will array implementation better use of memory using structs?

yes, without doubt. array based trees friendlier cache , take fewer allocations, plus there's no requirement store pointers per node.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -