Explain the terms Best case
Ans
Best case: O(n)
The best case is that the data comes
to us already sorted. Assuming that you have a smart implementation (which you
should, because it's easy) which stops itself once a pass makes no changes,
then we only need to do n comparisons over a single pass: O(n)
The term best-case performance is
used in computer science to describe the way of an algorithm behaves under
optimal conditions. For example, the best case for a simple linear search on a
list occurs when the desired element is the first element of the list.
According to this
definition, the best case running time for BST insertion should be O(1)[consider
that we are inserting to the root node]. But different resources says different
things, some claim that it is O(logn) [perfect balanced
tree] and some others claim that it isO(1) which one should I
believe?
No comments:
Post a Comment