1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Arada [10]
3 years ago
11

The ArrayList class contains a trim method that resizes the internal array to exactly the capacity. The trim method is intended

to be used after all the items have been added the ArrayList, in order to avoid wasting space. Suppose, however, the novice programmer invokes trim after each add. In that case, what is the running time of building an N-item ArrayList? Write a program that performs 100,000 adds to an ArrayList and illustrates the novice’s error.
Computers and Technology
1 answer:
andreev551 [17]3 years ago
5 0

Answer:

public void trimToSize() {

modCount++;

if (size < elementData.length) {

elementData = (size == 0)

? EMPTY_ELEMENTDATA

: Arrays.copyOf(elementData, size);

}

}

Now, the running time for copyOf() function is O(N) where N is the size/capacity of the ArrayList. Hence, the time complexity of trimToSize() function is O(N).

Hence, the running time of building an N-item ArrayList is O(N^2).

Please find the sample code below.

CODE

==================

import java.util.ArrayList;

public class Driver {

  public static void main(String[] args) throws Exception{

      int N = 100000;

      ArrayList<Integer> arr = new ArrayList<>(N);

     

      long startTime = System.currentTimeMillis();

      for(int i=0; i<N; i++) {

          arr.add(i);

          arr.trimToSize();

      }

      long endTime = System.currentTimeMillis();

      double time = (endTime - startTime)/1000;

      System.out.println("Total time taken = " + time + " seconds.");

  }

}

Explanation:

You might be interested in
ASAP PLS HELP: I’ll give brainliest if you u answer them all correctly!!
ra1l [238]

Answer:

1 c

2 a

3 c

4 b

5 c

6 b

7 d

8 a

9 d

10 b

6 0
3 years ago
Read 2 more answers
________ is used to install and update software, backup, and restore mobile devices, wipe employer software and data from device
erastovalidia [21]

Answer: MDM softwares

Explanation:

Here MDM refers to mobile device management software which provides people with the facilities of updating, installing creating backup of various mobile devices within an organisation. Moreover these software's provides tools for proper monitoring and to report their usage across various independent mobile device users. MDM is often used or interconnected with the term BYOD(Bring your own device), whereby employees of an organisation bring their own mobile devices and they are being managed by a MDM software centrally.

8 0
3 years ago
4
kupik [55]

Answer:

the answer is D Smart Object

5 0
3 years ago
Read 2 more answers
A _____ is usually a smaller version of a data warehouse
Strike441 [17]
A ( micro ) is usually a smaller version of a data warehouse
4 0
3 years ago
PLEASE HELP I WILL MARK BRAINIST!!!!!!!!!<br><br><br> What is a rolodex?
Mariana [72]
Its a gadget that helps organize cards/ a rotating file device.
5 0
3 years ago
Other questions:
  • Why is driving a privilege?
    15·2 answers
  • Generally speaking, mobile sites are good for acquiring new customers and inspiring new relationships while mobile apps are good
    6·1 answer
  • A typeface in which each character has the same width and is often used to display programming code is _
    8·1 answer
  • How much electricity is in the human brain? ​
    8·2 answers
  • Which button, when pressed, allows light from the subject to fall on the sensor?
    8·1 answer
  • If you need assistance with your I-20 which phone number at UC would you call?
    10·1 answer
  • What can you think of as a box or container that holds a value and has a label?
    11·2 answers
  • can you guys plz answeer this i need help rrly bad and plz no viruses or links or answers that have nun to do with this
    5·1 answer
  • Write a method to add/subtract two matrices. The header of the method is as follows:
    9·1 answer
  • Josh is learning about hackers known for causing damage and altering functions of websites. Which type of hacker is he learning
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!