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

  • Home
  • SEARCH
  • 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 8463597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:29:58+00:00 2026-06-10T14:29:58+00:00

Generally, what is better: insert N elements in some collection and then sort it,

  • 0

Generally, what is better: insert N elements in some collection and then sort it, or find out the correct place for the element before insert and insert it exactly in that place (repeat N times)?

  • 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-10T14:30:00+00:00Added an answer on June 10, 2026 at 2:30 pm

    It is very dependent on the data structure and application in use.

    Note that inserting an element in an array requires shifting all the following elements to the right, which results in O(n) insertion.

    A Binary Search Tree however, allows insertion in O(logn), but is less cache efficient then an array – and thus slower.

    On the other hand, inserting and then sorting results in high latency after the last element was inserted [The O(nlogn) sort].

    Also – if you are going to query very often – but add elements seldom – you want to avoid sorting too often – and keeping elements in order is an easy way to achieve this.

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

Sidebar

Related Questions

Is it generally better/faster to do: if (condition) return a else if (condition2) return
Is it generally better practice (and why) to validate attributes in the model or
Generally, I had thought it was always better to store images in the filesystem
Generally speaking, for combining a lot of data is it better to use a
I've been struggling with this for some time now and I just can't find
I understand that C++ is generally considered better than Java for games (at least
Is it generally better to run functions on the webserver, or in the database?
Before I dive into my question, I wanted to point out that I am
Which technique has better rendering times and is generally better? File i'm working on
I would like to better understand the interns of e.g. Data.Map. When I insert

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.