1. Bubble Sort - 5,3,4,2,1
1. for i = 0
array =
3,4,2,1,5
2. for i = 1
array =
3,2,1,4,5
3. for i = 2
array =
2,1,3,4,5
4. for i = 3
array =
1,2,3,4,5
2. Selection Sort - 5,3,4,2,1
1. for i = 0
array =
1,3,4,2,5
2. for i = 1
array =
1,2,4,3,5
3. for i = 2
array =
1,2,3,4,5
break;
3. Insertion Sort - 5,3,4,2,1
1. for i = 0
array =
5,3,4,2,1
2. for i = 1
array =
3,5,4,2,1
3. for i = 2
array =
3,4,5,2,1
4. for i = 3
array =
2,3,4,5,1
5. for i = 4
array =
1,2,3,4,5
4. O(n^2) because two nested for loops have been used.
Student Name Student ID CS209 Data Structures and Algorithms - Quiz 1/2e Friday, Feb 22, 2019...
Given a bubble sort and the following array: [10,7,19,5,16] What are the values after the first iteration? Given an insertion sort and the following array: [50,5,35,70,6] What does the array look like after the first insertion: Fill in the missing code for InsertionSort method // Insertion Sort method //sorts an array of Auto objects public static void insertionSort(Auto [] arr) { Auto temp; int j; for (int i=1; i<arr.length; i++) { j=i; temp=arr[i]; while (j!=0 &&(temp.getModel().compareTo(arr[[j-1].getModel())<0)...
Suppose that you are performing a reheapification downward. Write a precise condition (not code) that describes the situation that causes the reheapification to stop. Here is an array of ten integers: 5 3 8 9 1 7 0 2 6 4 What does this array look like after the FIRST iteration of the large loop in a selection sort (sorting from smallest to largest) ? Draw a new heap that is created by removing one item (the root) from the...
C++ 1. A?B?C?D? which one is correct 2. 3A, 3B #include<iostream> using namespace std; void swap0(int* ptri, int* ptr2) { int *temp; temp = ptr1; ptr1 = ptr2; ptr2 = temp; void swap1(int ptri, int ptr2){ int temp; temp = ptri; ptr1 = ptr2; ptr2 = temp; portion void swap2(int *&ptri, int *&ptr2){ int* temp; temp = ptr1; ptr1 = ptr2; ptr2 = temp; void swap3(int &ptri, int &ptr2) { int temp; temp = ptr1; ptr1 = ptr2; ptr2 =...
QUESTION 1 Using the following declarations and a member of the Array class, int [ ] bArray = new int [10]; int location; Using a method in the Array class, write a statement that would change the order of the elements in the bArray array. The contents of the first cell should hold what was in the last cell. The second cell should hold what was in the next to last cell. __________________________ HINT: You must write the full statement...
I want to compare the runtimes and swap operations times among quick Sort, selection Sort and shell Sort here is my code: But when I create a 1000,000 size array, I can't get the result of the operations times and runtime. what's wrong with my code? and I also want to copy the array. Because I want to use same array for three sort. And for the shell Sort, I haven't learn it in my class. Can anyone help me...
Data Structures using C BuildHeap and Heap Sort In preparation: If you have not done so already, you should complete Worksheet 33 to leam more about the heap data structure. In some applications it is useful to void buildHeap (struct dyArray heap) { initialize a Heap with an existing vector int max = dy Array Size(heap); int i; of values. The values are not assumed for (i = max/2-1; i >= 0; i--) to be organized into a heap, and...
#include <stdio.h> // Define other functions here to process the filled array: average, max, min, sort, search // Define computeAvg here // Define findMax here // Define findMin here // Define selectionSort here ( copy from zyBooks 11.6.1 ) // Define binarySearch here int main(void) { // Declare variables FILE* inFile = NULL; // File pointer int singleNum; // Data value read from file int valuesRead; // Number of data values read in by fscanf int counter=0; // Counter of...
Please help. I need a very simple code. For a CS 1 class. Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "printall" - prints all student records (first name, last name, grade). "firstname name" - prints all students with...
Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...
C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...