subject

Write a C++ program with the following requirements:
1. Analyze the algorithms by sorting, in ascending order, the BST, AVG, and WST arrays. Each one of these three arrays has 1000 integers where: a. BST has 1000 integers already sorted in ascending order (e. g., 10, 20, 30, ...etc.). b. AVG has 1000 randomly generated integers, where each integer is between 0 and 100,000. C. WST has 1000 integers sorted in descending order (e. g., 1000, 990, 980, ...etc.). Note: Make sure that all algorithms are tested with identical arrays. Therefore, at the beginning of your program, create three identical versions of the BST, AVG, and WST arrays where each algorithm sorts its own version.
2. Define two global integer variables: moves and comps. Initialize these variables to zero before every call to a sorting algorithm. Add any necessary code to the algorithms' implementation to carry out the following: a. moves is incremented with each movement operation of the elements to be sorted in this case they are the integer values in the arrays). Consider that the swap operation requires three movements of two elements. b. comps is incremented with each comparison operation on the elements to be sorted. C. After each call to the sorting algorithms functions (2 algorithms x 3 arrays = 6 calls), write to a text file, sort. txt, the values of moves and comps correspond to each algorithm.
3. After calling an algorithm function to sort an array, verify that the array is sorted. One way to do that is to confirm that every element i in the array has a value less than or equal to the value in element i+1 (write a function for this task and re-check your code if it returns a false verification).
4. After running your program, copy the numbers in the text file, sort. txt, to an excel sheet. Use these numbers to generate two graphs. One graph compares the number of moves needed by the three algorithms for the three cases: best, average, and worst. Another graph does the same but for the number of comparisons performed by the algorithms.

Answer the following:
i. Why does the Insertion sort algorithm result in zero moves when sorting an already sorted array (the best case)?
ii. Why does the Insertion sort algorithm result in 999 comparisons when sorting an already sorted array (the best case)?
iii. From your two excel graphs, comment on the performance of the sort algorithms under different scenarios (best, average, and worst).
The following C++ code creates a text file and writes a text message in it:

#include
#include
#include
using namespace std;
int main() {
ofstream outf;

outf. open("sort. txt");
if (outf. fail()) {
cerr << "Error: Could not open output file\n";
exit(1);}
outf «< "\t\t Hello World \n";
outf. close(); //Close the file at the end of your program.
return 0;

The following C++ code generates 5 random integers. Each integer is between 0 and 100.

#include
int main() {
int A[5];
srand(time(NULL)); //call this only once at the beginning
to
// allow rand() to generate a different
// succession of random values.
for (int i = 0; i < 5; i++)
A[i] = rand() % 100;
return 0;
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 22:30
What are compression artifacts? 1) visible defects in the picture caused by the nature of the compression algorithm. 2) numbers that tell a web server how much to compress a picture for faster transmission. 3) invisible defects in the picture preserved by lossless compression. 4) numbers that tell a photo editing program how much to compress a picture for faster transmission.
Answers: 3
question
Computers and Technology, 24.06.2019 07:00
Why do we mark tlc plates with pencil and not with pen
Answers: 2
question
Computers and Technology, 24.06.2019 07:30
John recently worked on a project about various programming languages. he learned that though procedural language programs are useful, they have disadvantages too. what is a disadvantage of programs written in procedural languages? a. programs do not represent data complexity. b. programs take more time to execute. c. programs are prone to security threats. d. programs do not interface with multiple platforms.
Answers: 3
question
Computers and Technology, 24.06.2019 09:30
Retype the statements, correcting the syntax errors. system.out.println("num: " + songnum); system.out.println(int songnum); system.out.println(songnum " songs"); note: these activities may test code with different test values. this activity will perform two tests: the first with songnum = 5, the second with songnum = 9. see how to use zybooks.
Answers: 1
You know the right answer?
Write a C++ program with the following requirements:
1. Analyze the algorithms by sorting, in...
Questions
question
Mathematics, 25.08.2021 17:50
question
Mathematics, 25.08.2021 17:50
Questions on the website: 13722361