Programming language: C++ Implement a main function that profiles the performance of insert (See below the code) and outputs a table showing the average time per insert as the length of the array increases. Make sure your source code is well-commented, consistently formatted, uses no magic numbers/values,

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Programming language: C++

Implement a main function that profiles the performance of insert (See below the code) and outputs a table showing the average time per insert as the length of the array increases. Make sure your source code is well-commented, consistently formatted, uses no magic numbers/values, follows programming best-practices, and is ANSI-compliant. It is expected to have the program output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Bint* insert(int* array, int length, int index, int value)
{
8
18
#include <iostream>
using namespace std;
8
if (length == 0)
{
int* newArray = new int [1];
newArray [0] = value;
return newArray;
}
else
{
int* newArray = new int[length + 1];
//Copying the array from 0 to index
for (int i = 0; i < index; i++)
{
newArray[i]
array[i];
=
newArray[index] = value;
//Copying the array from index to length
int j = index + 1;
for (int i = index; i < length; i++)
{
newArray[j] = array[i];
delete[] array;
return newArray;
Transcribed Image Text:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 Bint* insert(int* array, int length, int index, int value) { 8 18 #include <iostream> using namespace std; 8 if (length == 0) { int* newArray = new int [1]; newArray [0] = value; return newArray; } else { int* newArray = new int[length + 1]; //Copying the array from 0 to index for (int i = 0; i < index; i++) { newArray[i] array[i]; = newArray[index] = value; //Copying the array from index to length int j = index + 1; for (int i = index; i < length; i++) { newArray[j] = array[i]; delete[] array; return newArray;
Pseudocode:
main ()
/* Setting to allow fine-tuning the granularity of the readings */
Let INSERTS_PER_READING = 1000
/* Start with an empty array */
Let array = empty array (i.e. NULL)
Let length = 0
/* Take 60 readings */
Loop 60 times
/* Each reading will be taken after INSERTS_PER_READING inserts */
Let startTime = current time
Loop INSERTS_PER_READING times.
Let index = random integer in range [0, length]
Let value = random integer value
Let array = insert (array, length, index, value)
Let length = length + 1
End Loop
Let stopTime = current time
Let time PerInsert
=
(stopTime startTime) / INSERTS_PER_READING
/* Output reading in tabular format */
Output array length and timePerInsert
End Loop
/* Free the old array */
Free array
Transcribed Image Text:Pseudocode: main () /* Setting to allow fine-tuning the granularity of the readings */ Let INSERTS_PER_READING = 1000 /* Start with an empty array */ Let array = empty array (i.e. NULL) Let length = 0 /* Take 60 readings */ Loop 60 times /* Each reading will be taken after INSERTS_PER_READING inserts */ Let startTime = current time Loop INSERTS_PER_READING times. Let index = random integer in range [0, length] Let value = random integer value Let array = insert (array, length, index, value) Let length = length + 1 End Loop Let stopTime = current time Let time PerInsert = (stopTime startTime) / INSERTS_PER_READING /* Output reading in tabular format */ Output array length and timePerInsert End Loop /* Free the old array */ Free array
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education