arrays - binary search vs binary search tree -


what benefit of binary search tree on sorted array binary search? mathematical analysis not see difference, assume there must difference in low-level implementation overhead. analysis of average case run time shown below.

sorted array binary search
search: o(log(n))
insertion: o(log(n)) (we run binary search find insert element)
deletion: o(log(n)) (we run binary search find element delete)

binary search tree
search: o(log(n))
insertion: o(log(n))
deletion: o(log(n))

binary search trees have worst case of o(n) operations listed above (if tree not balanced), seems worse sorted array binary search.

also, not assuming have sort array beforehand (which cost o(nlog(n)), insert elements 1 one array, binary tree. benefit of bst can see supports other types of traversals inorder, preorder, postorder.

your analysis wrong, both insertion , deletion o(n) sorted array, because have physically move data make space insertion or compress cover deleted item.

oh , worst case unbalanced binary search trees o(n), not o(logn). need brush on big-o notation.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -