Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9289465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:11:11+00:00 2026-06-18T20:11:11+00:00

Suppose there is an array containing unsorted data and I need to choose either

  • 0

Suppose there is an array containing unsorted data and I need to choose either linear search or binary search for searching. Then which option should I choose? The time complexity for linear search is O(n) and for binary search is O(log n). But, the fastest sorting algorithm gives the time complexity of O(n * log n). Now, I don’t know how to “add” complexities of two algorithms (if that’s the right word) and hence, I am asking this question.

So my question is if sorting then binary searching is better than simply linear searching or is it the other way?

Plus, how do I prove whatever the case maybe using big O notation ( I mean “adding” and “comparing” the time complexities) ?

Thank you so much for reading!!! It means a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T20:11:13+00:00Added an answer on June 18, 2026 at 8:11 pm

    You don’t really “add” the complexities. Sorting is, as you say, O(n * log n), and searching is O(log n). If you were to do “normal math” on them, then it would be (n+1)*log n, which is still n*log n.

    When you’re performing multiple steps like that, you typically take the highest complexity and call it that. After all, when n is sufficiently large, n*log n dwarfs log n.

    Think of it this way: when n is 1,000,000, n*log n is 20 million. log n is 20. So what’s the difference between 20,000,000 and 20,000,020? The (log n) term is irrelevant. So (n log n) + (log n) is, for all intents and purposes, equal to (n log n). Even when n is 100, log n is 7. The (log n) term just won’t make a difference when n is even moderately large.

    In your particular case, if you only need to search the list one time, then sequential search is the way to go. If you need to search it multiple times, then you have to weigh the cost of m searches O(m * n) against the cost of sorting and then searching. If you’re interested in the minimum time and you know how many times you’ll be searching the list, then you’d use sequential search if (m*n) is less than (n * log n). Otherwise use the sort and then binary search.

    But that’s not the only consideration. Binary search on a sorted list gives you very quick response time, whereas linear search can take a very long time for a single item. If you can afford to sort the list during program startup then that’s probably the best way to go because items will be found (or not found) much faster once the program is operating. Sorting the list gives you better response time. It’s better to pay the price of sorting during startup than to experience very unpredictable response times during operation. Or to find out that you need to do more searches than you thought. . .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have an array with indices 0..n-1. Is there a way to choose
Suppose there is a fully populated array of data String[n][3] myData. I want to
Suppose there is a unsorted array A, and it contains an element x (x
suppose there is a string of characters in an array of d[20] . How
Suppose there is an image_url column in database. I want the user to choose
Suppose there is a table A which has a column AccessRights which is multivalued(
Suppose there is a System A which gives some output. This output is used
Suppose I have an array age=[16 17 25 18 32 89 43 55] which
Suppose there is a string of type NSSTring NSString *string; There is array called
So suppose I have a JavaScript array containing a bunch of elements, but these

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.