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 45155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:45:52+00:00 2026-05-10T15:45:52+00:00

More than about LINQ to [insert your favorite provider here], this question is about

  • 0

More than about LINQ to [insert your favorite provider here], this question is about searching or filtering in-memory collections.

I know LINQ (or searching/filtering extension methods) works in objects implementing IEnumerable or IEnumerable<T>. The question is: because of the nature of enumeration, is every query complexity at least O(n)?

For example:

var result = list.FirstOrDefault(o => o.something > n); 

In this case, every algorithm will take at least O(n) unless list is ordered with respect to 'something', in which case the search should take O(log(n)): it should be a binary search. However, If I understand correctly, this query will be resolved through enumeration, so it should take O(n), even in list was previously ordered.

  • Is there something I can do to solve a query in O(log(n))?
  • If I want performance, should I use Array.Sort and Array.BinarySearch?
  • 1 1 Answer
  • 2 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. 2026-05-10T15:45:53+00:00Added an answer on May 10, 2026 at 3:45 pm

    Even with parallelisation, it’s still O(n). The constant factor would be different (depending on your number of cores) but as n varied the total time would still vary linearly.

    Of course, you could write your own implementations of the various LINQ operators over your own data types, but they’d only be appropriate in very specific situations – you’d have to know for sure that the predicate only operated on the optimised aspects of the data. For instance, if you’ve got a list of people that’s ordered by age, it’s not going to help you with a query which tries to find someone with a particular name 🙂

    To examine the predicate, you’d have to use expression trees instead of delegates, and life would become a lot harder.

    I suspect I’d normally add new methods which make it obvious that you’re using the indexed/ordered/whatever nature of the data type, and which will always work appropriately. You couldn’t easily invoke those extra methods from query expressions, of course, but you can still use LINQ with dot notation.

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

Sidebar

Related Questions

This question is more about guidance than actually solving my problem: I need to
This question is more a re-insurance than one directly about how to code. As
EDIT: This question is more about language engineering than C++ itself. I used C++
So this is more of a general question about apps and techniques rather than
I read in more than one website about this method of protecting forms: I
This is more thinker than problem. I have a problem with thinking about how
Where would I go about placing partial files shared by more than one model?
I'm designing a large scale web application with about 30 tables, more than 2/3
I had asked this question in a much more long-winded way a few days
This turned out to be more difficult than I thought. Basically, each day a

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.