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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:00:29+00:00 2026-06-17T06:00:29+00:00

I understand Linked List complexities for the most part. Accessing an item is O(n)

  • 0

I understand Linked List complexities for the most part. Accessing an item is O(n) in worst case because it may be at the end or not exist. Adding is O(1) to an unsorted Linked List because you can just add it as the head.

But for arrays, I’m confused. I’ve read a lot about how accessing is efficient (O(1)) but addition isn’t necessarily, neither is deletion. Why is this?

Is it because addition isn’t always at the end? There it would be O(1), right? But if it’s at another point, you’d have to shift the items, which would be O(n)? And this is happening “behind the scenes” so to speak in a high-level language, right? It’s moving memory locations and that’s where the complexity kicks in?

Deletion causes there to be a gap I gather? And it has to fill it in?

Basically if I have an array with 10 items in it, and I go to add an item at the 5th index point, would it have to copy all the items from index 5 and higher to a one-higher index point, causing the operation to be O(n)?

Any clarification would be greatly appreciated.

  • 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-17T06:00:31+00:00Added an answer on June 17, 2026 at 6:00 am

    Inserting (into the middle of the array, say) is O(n) because, as you state, you need to move all the subsequent elements to the right. So if you insert at the first position, you’ll have to move all n of the existing elements over to make room, giving you a worst-case cost of n. On average, assuming you insert at a random position, you’re moving (n/2) elements.

    Appending (to the end of the array) is also O(n) because it my require a re-allocation. If your array exists in a chunk of memory that’s been allocated to be bigger than the current size of the array this isn’t a problem; you just do a (constant time) write to the next location in memory. But eventually you are going to run out of room. Then you need to allocate a new hunk of memory that’s bigger and copy all of the existing elements into it. So your worst-case net cost is n+1 (n copies, plus 1 append) which gives you your O(n). (There’s also whatever behind-the-scenes cost you incur for allocating memory.) To avoid this cost, many languages and libraries give you the option of pre-allocating space in an array to cover the maximum number of elements you expect to see in your application; this ensures there won’t be any re-allocation unless you end up adding more than the expected number of elements.

    Deletion is O(n) because (as you say) you need to move everything after the deleted element back one space to the left. If you delete from the first position, you’ll have to move all n-1 remaining elements over, giving you O(n) for your worst case. (If you delete from the last position, that just takes constant time.)

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

Sidebar

Related Questions

I do not quite understand why deleting at the end of a single linked
I am trying to understand Linux Kernel implementation of linked list and hash table.
Visual Studio 2008 C What I can't understand about this linked list is the
As I understand it, a unique_ptr signifies exclusive ownership. A singly linked list seems
I know it is a minute code. I can't understand why my linked list
I understand that some hash tables use buckets, which is a linked list of
I need to understand how a linked list works in this C++ code. I
I understand what a linked list is, but my question is what is an
I'm trying to understand the Linux kernel linked list API. According to Linux Kernel
So I am trying to program in C++ a linked list but I'm not

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.