Monday 15 July 2013

big o - time complexity for binary search trees -



big o - time complexity for binary search trees -

if utilize insert() function bst, time complexity can bad o(n) , o(log n). i'm assumng if had balanced tree, time complexity log n because able ignore half of tree every time go downwards "branch". , if tree unbalanced o(n). right thinking this?

yes, correct, see e.g. wikipedia, http://en.wikipedia.org/wiki/binary_search_tree#searching.

if utilize e.g. c++ stl std::map or std::set, red-black, balanced tree. worth noting these stl info structures, performance 100% of time, can of import in e.g. hard real-time systems. hash tables faster, not fast 100% of time red-black trees.

big-o time-complexity

No comments:

Post a Comment