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
  • 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. 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

Ask A Question

Stats

  • Questions 79k
  • Answers 79k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Not 100% sure of what you are trying to do… May 11, 2026 at 4:08 pm
  • Editorial Team
    Editorial Team added an answer This should do the trick. <table class="zebra"> <tr> <td>foo</td> <td>bar</td>… May 11, 2026 at 4:08 pm
  • Editorial Team
    Editorial Team added an answer This is an HTML problem. Its rules state that consecutive… May 11, 2026 at 4:08 pm

Related Questions

I recently found LINQ and love it. I find lots of occasions where use
Is there a limit to the rows that IEnumerable.Count() (or IQueryable.Count()) using LINQ to
I know that in most cases it`s more useful to learn more complicated technology/language
my goal is to get lots of rows from a translation table. I use

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.