Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, we will compare the performance of three similar data structures in Java : arrays, ArrayList and LinkedList. For these three data structures,

In this assignment, we will compare the performance of three similar data structures in Java: arrays, ArrayList and LinkedList. For these three data structures, we will measure the time it takes to create and initialize an object with one million Integer values. To measure execution time of a code block, you can call the method System.nanoTime() before and after the code block and the difference between the returned values is the time taken to complete the code block. The following code snippet shows how to measure the execution time of a for loop:

image text in transcribed

Create a class with name CompareTimes. For each data structure, create a method that returns the time it takes to create an object from that data structure and initializing it with the numbers from 0 to 99999. Then, display the results similar to the below sample output:

Array: 54952999

ArrayList: 82641648

LinkedList: 127078910

long start Time = System.nanoTime(); for (int iter= 0; iter 10000; iter++) { long endTime = System. nanoTime(); long exeTime = endTime- startTime ; System.out.println( Execution Time:" + exeTime)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

How does communication shape cultures and social communities?

Answered: 1 week ago