Insert into a binary tree

Which of the following represents the time complexity of inserting an element into a binary search tree of n n nodes, with the tightest upper bound?

O ( n log n ) O(n\log n) O ( n ) O(n) O ( log n ) O(\log n) O ( 1 ) O(1)

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Christopher Boo
May 15, 2016

We know that the time complexity of inserting an element into a binary search tree depends on its height. If the tree forms a chain (a vertical line, with only one leaf), then worst case is you need to traverse the entire chain until the leaf to insert an element. There are n n nodes in the chain, hence O ( n ) O(n) .

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...