Search code examples
algorithmbinary-searchlinear-search

Which one is run-time efficient and storage efficient in alogarithm?


I'm confused whether linear search or binary search is more efficient in running time and storing.

detalied explaination is really appreciated


Solution

  • @Trophe covered the time complexity, so I'll try to explain the space complexity

    The space requirement has the same complexity

    a linear search is simpler and needs just one variable

    a binary search needs to store a lower and upper bound, so it's more space, but it's not dependent on the size of the list

    So we say they are both O(1) space complexity