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
Which 3 navigation features are missing in a reports only user view?
san4es73 [151]

Explanation:

when a user changes his or her view to a Report only view when using QuickBooks online they only see a report list page, without having such features as; Navigation panel, Search box or Quick Create (+) icon.

7 0
3 years ago
Read 2 more answers
Does anyone know how to change there Name of the account that shows up? If you do please tell me in a comment and/or Answer.
Alona [7]

Answer:

change your email

Explanation:

award me brainliest

6 0
3 years ago
Read 2 more answers
Will give brainliest to whoever can answer all of these questions correctly.
babymother [125]

false

ppt

chips designed to preform a function

Apologize to the customer for the inconvenience and offer to refund his money or replace the item

OneDrive-CollegeWork-FreshmanYear-NameOfClass

true

Social networking

paragraph

true

complete fill

true


 

7 0
3 years ago
Read 2 more answers
Which of these agencies main goal is the promotion of consumer protection?Immersive Reader
sattari [20]

Answer:

FTC (Federal Trade Commission)

Explanation:

However, it is not just the one government body that works to ensure consumer protection. The FTC is certainly one, however, though the others are the Food and Drug Administration, Financial Protection Bureau and the US Department of Justice. And all these bodies together ensure that the rights of the consumer are protected, through enforcement of various acts, and each of them deals with a certain type of good.

6 0
3 years ago
Which of these is a necessary component of any computer?
Aleonysh [2.5K]

Answer:

Components:

Components:1.Motherboard:

The motherboard is the core of the system. It really is the PC; everything else is connected to it, and it controls everything in the system. 2.Processor:

2.processor:

The processor is often thought of as the "engine" of the computer. It's also called the CPU (central processing unit).

3.Memory (RAM):

The system memory is often called RAM (for random access memory). This is the primary memory, which holds all the programs and data the processor is using at a given time.

4.Case/chassis:

The case is the frame or chassis that houses the motherboard, power supply, disk drives, adapter cards, and any other physical components in the system.

5.Power supply:

The power supply is what feeds electrical power to every single part in the PC.

6.Floppy drive:

The floppy drive is a simple, inexpensive, low-capacity, removable-media, magnetic storage device.

7.Hard drive:

The hard disk is the primary archival storage

memory for the system.

8.CD-ROM/DVD-ROM:

CD-ROM (compact disc read-only) and DVD-ROM (digital versatile disc read-only) drives are relatively high-capacity, removable media, optical drives.

9.Keyboard:

The keyboard is the primary device on a PC that is used by a human to communicate with and control a system.

10.Mouse

Although many types of pointing devices are on the market today, the first and most popular device for this purpose is the mouse.

11.Video card:

The video card controls the information you see on the monitor.

12.Monitor:

Monitor is output device.

13.Sound card:

It enables the PC to generate complex

sounds.

14.Modem:

Most prebuilt PCs ship with a modem (generally an internal modem).

6 0
2 years ago
Other questions:
  • It's inventiveness uncertainty and futuristic ideas typically deals with science and technology ......what is it.
    8·1 answer
  • The chip that controls the radio frequency waves within a device
    9·1 answer
  • Rows within a spreadsheet are identified by:
    8·1 answer
  • Programming Using OOJAVA<br> check this Atterchment and solve Exascies 1, 2, and 3
    10·1 answer
  • Your employer is opening a new location, and the IT director has assigned you the task of calculating the subnet numbers for the
    14·1 answer
  • The acronym pies is used to describe improvised explosive devices (ied) components. pies stands for:
    13·2 answers
  • Wanna song to vibe to? Listen to Streets by Doja cat
    11·1 answer
  • The illustration shows different types of text language.
    5·2 answers
  • What are the tools in creating an animation?
    7·1 answer
  • What are the importance of computer software​
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!