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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:19:26+00:00 2026-06-09T23:19:26+00:00

Since LinkedList is a nightmare in terms of memory overhead and also slower when

  • 0

Since LinkedList is a nightmare in terms of memory overhead and also slower when iterating elements, I would like to have something like int poiter data structure.

So I have a list of ints and I form it by inserting elements at the beginning-middle. When the list is ready, I iterate it in a one-by-one fashion from the left. That is my problem constraint.

  • 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-09T23:19:28+00:00Added an answer on June 9, 2026 at 11:19 pm

    I would profile and try different data structures.

    That being said, why not try to use ArrayList; it’s fast to iterate and even insert, while in O(n), is fast because moving consecutive data in a cache is lightning fast. (If you also reverse the list while inserting it will be even faster!)


    Update, since my fellow programmers doesn’t understands why I recommend ArrayList for this perticular problem:

    The problem isn’t inserting elements. In that case the linked list wins direcly (O(1) against the O(n) for the array list). The problem is to find the place to insert them. In this case the LinkedList is really slow. There is a huge overhead to find the place to insert since it doesn’t allocate the memory in a “good matter”. Lots of cache misses!

    OP hasn’t posted any code so we only know what OP wants but here is an algorithm analysis for the two cases (where C* are constants):

    LinkedList, for each element to insert:

    • Iterating O(C1 * n)
    • Inserting O(1)

    ArrayList, for each element to insert:

    • Iterating O(C2 * n)
    • Inserting O(C3 * n)

    So, both algorithms are in O(n) but looking closely at the constants: C1 is really big (explained above). C2 and C3 on the other hand are small because iterating and moving within the cache is fast.

    So, if you have enough memory try an ArrayList!

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

Sidebar

Related Questions

In a game I have a list of players, let's say like this: LinkedList<String>
I have a short (12 elements) LinkedList of short strings (7 characters each). I
Since now I have only used plugin for editing and the way I use
Since I have no errors I don't know if this is the right place
It's been two years since I last coded something in Java so my coding
I have code that looks like this: public class Polynomial { List<Term> term =
i would like to develop a binary tree structure such that every single node
I have a LinkedList that I am using to track consecutive numbers that are
Is there a pre-implemented linked list out there that would have been implemented using
I have a LinkedList of nodes each storing a LinkedList of edges. I wanted

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.