68.9k views
1 vote
Which of the following would have a logarithmic Big O run-time complexity?

O Find all duplicates in a list
O Find the largest value in an unsorted list
O none of these
O Determine if a binary number is even or odd
O Find the shortest route to visit n cities by airplane

User Rostamiani
by
8.9k points

1 Answer

6 votes

Final answer:

None of the tasks listed have a logarithmic Big O run-time complexity. Finding duplicates is generally quadratic, finding the largest number is linear, checking if a binary number is even or odd is constant, and finding the shortest route is an NP-hard problem without a logarithmic solution.

Step-by-step explanation:

The question pertains to Big O notation, which is used to classify algorithms according to how their run time or space requirements grow as the size of the input increases. In the context of the given options, none of the listed tasks would typically have a logarithmic Big O run-time complexity. Here's a quick look at each:


  • Finding all duplicates in a list: This operation generally requires checking each element against all others, leading to a quadratic run-time complexity (O(n^2)) unless a more efficient data structure like a hash set is used, potentially reducing it to linear (O(n)).

  • Finding the largest value in an unsorted list: This can be done with a simple loop through all elements, which has a linear run-time complexity (O(n)), as you only need to compare each element once with the current maximum.

  • Determining if a binary number is even or odd: This operation is very efficient since you can determine this by looking only at the least significant bit, which has a constant time complexity (O(1)).

  • Finding the shortest route to visit n cities by airplane is an example of the Travelling Salesman Problem, which is known to be NP-hard and doesn't have a logarithmic time complexity solution. It typically has an exponential run time complexity in the worst-case scenario.

Therefore, the answer to which task has a logarithmic Big O run-time complexity is none of these.

User Joe Caruso
by
8.0k points