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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:39:10+00:00 2026-06-12T02:39:10+00:00

For a programming class a while ago we were given a relatively simple task,

  • 0

For a programming class a while ago we were given a relatively simple task, the essence of which can be boiled down to:

Store an array (not a List) of n Strings where n is always <= m, allowing new strings to be added and old ones to be removed. (In this instance, m was 50)

When discussing this with my friends afterwards, we realised that all three of us had solved it in a different way. My question (out of mere curiosity) is which one of us had the best answer (all things being equal) and why.

Friend A went for implementing what was essentially an ArrayList; creating a new array with a different size and putting all the elements from the original array into the new one with a for loop(plus or minus the one he was adding/removing).

Friend B simply created an array of length m, removing elements by setting their value to null (e.g. array[13] = null), and adding elements by scrubbing forward from index 0 until an empty spot was found (this was a for loop).

Friend C [Me] also created an array of length m, but shifted every following value forward (i.e. reduced their index by 1 with a for loop) when a string was removed so that n-1 was always the index of the last value (when n > 0), and n was also the index to add new values at (eliminating the for loop for adding strings).

It’s a fairly basic class and they don’t care how we did it as long as we did, but we’re curious.

edit: I just realised that I left out something which may be important. The problem specified removing strings by value (e.g. removeString("someString")) rather than index, which made finding the value (and its index) a requirement as well.

  • 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-12T02:39:11+00:00Added an answer on June 12, 2026 at 2:39 am

    There might not be correct answer, because the arrays you create are in the end going the implemented for a system. So it depends on the system requirements. But generally considering efficiency:

    • Friend A’s solution, seems nasty to me. Creating a new array, for
      adding/removing an element is waste of memory and cpu cycles. And
      also I believe that is not how the ArrayList is implemented in Java.

    • Friend B’s solution, has the same worst case time complexity as
      friend C’s however, it may possibly perform much better. Since the
      ordering of strings is not important, this looks the best.

    • Friend C’s
      solution, is actually quite efficient as well. As for adding a
      elemnt, you already have the index i.e. n. Hence it should perform
      well as well.

    However as I said before it actually depends upon the system one is implementing.
    But just to wrap it up I should say A < B = C.

    Digvijay

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

Sidebar

Related Questions

I am working on an assignment for my GUI programming class, in which we
While programming over an existent class, I've noticed that someone has written something like
This is a little external js script for my web programming class, which is
I've been programming in C++ a while and I've used both methods: class Stuff
I'm working on my first homework project in a web programming class, which is
From the android development perspective , while you are programming which way do you
So for my programming class we have had a project to create a virtual
I'm in a mobile programming class right now and we have to make a
Disclaimer: This is for a programming class, but it is not the answer or
So I'm creating an application for my mobile programming class and I'm running into

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.