Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Homework # 1 In this assignment you will implement a program that inserts elements into an array, analyze the Big - O performance of this
Homework #
In this assignment you will implement a program that inserts elements into an array, analyze the
BigO performance of this code, then profile the program to see if the actual performance matches
the predicted performance.
All code implemented in this assignment should be in a class called Homework
points Implement a method named insert. This method should take an array of ints, the
index at which a new value should be inserted, and the new value that should be inserted. The
function should return a new array populated with the contents of the original array with the
given value inserted at the given index. The following sections provide a detailed description of
this function:
Method signature:
static int insertint array, int index, int value
Parameters:
array The original array of ints.
index The location where the value will be inserted.
value The value to be inserted.
Return value:
A new array of ints containing the contents of the original array plus the new value
inserted at the given index.
Pseudocode:
Create new array one larger than original array
Let newArray a newArray with array.length elements
Copy elements up to insert point from original array to new array
Loop to copy array index to newArray index
Place insert value into new array
Set newArrayindex to value
Copy elements after insert point from original array to new array
Loop to copy arrayindex length to newArrayindex length
Return newArray
CSE
points Implement a main method that profiles the performance of insert and outputs a
table showing the average time per insert as the length of the array increases.
Pseudocode:
Setting to allow finetuning the granularity of the readings
Let NUMREADINGS
Let INSERTSPERREADING
Start with an array containing element
Let array new array containing one element having value
Take NUMREADINGS readings
Loop NUMREADINGS times
Each reading will be taken after INSERTSPERREADING inserts
Let startTime current time
Loop INSERTSPERREADING times
Let index random integer in range array.length
Let value random integer value
Let array Homeworkinsertarray index, value
End Loop
Let stopTime current time
Let timePerInsert stopTime startTime INSERTSPERREADING
Output reading in tabular format
Output array length and timePerInsert
End Loop
Report format:
Your program should output a report similar to the format below your values will be
different You should finetune the INSERTSPERREADING constant so that none of
the readings Seconds per insert are zero:
Array length Seconds per insert
CSE
points Plot a scatter graph showing Seconds per insertYaxis vsArray lengthXaxis
using the profiling data that was output by main.
points Provide a linebyline BigO analysis of your implementation of insert. You can do
this by adding a comment next to each line in your source code. What is the overall BigO
performance of insert? What parts of the algorithm contribute most heavily to the overall BigO
performance?
point Based on the graph does the performance of improve, degrade, or stay the same as
the length of the array grows? Does your BigO analysis of match the results of running the
program?
point Make sure your source code is wellcommented, consistently formatted, uses no
magic numbersvalues and follows programming bestpractices.
Turn in all source code, program output, diagrams, and answers to questions in a single PDF
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started