I've developed a new, super cool sorting algorithm. Here's the procedure:
Until sorted:
List the algorithm's efficiency using Big-O.
Executable code:
//Header files
#include <stdio.h>
#include<stdlib.h>
//main method
int main()
{
//declares the variables
int arrayVal[100], num1, c1, d1, swap;
printf("ENTER NUMBER OF ELEMENTS\n");
scanf("%d", &num1);
printf("Enter %d integers\n", num1);
for (c1 = 0; c1 < num1; c1++)
scanf("%d", &arrayVal[c1]);
//loops which defines the algorithms
for (c1 = 0 ; c1 < ( num1 - 1 ); c1++)
{
for (d1 = 0 ; d1 < num1 - c1 -
1; d1++)
{
//compares the
values
if (arrayVal[d1]
> arrayVal[d1+1])
{
//swaps the values
swap = arrayVal[d1];
arrayVal[d1] = arrayVal[d1+1];
arrayVal[d1+1] = swap;
}
}
}
//printing the results
printf("SORTED ORDER:\n");
for ( c1 = 0 ; c1 < num1 ; c1++ )
printf("%d\n", arrayVal[c1]);
system("pause");
return 0;
}
I've developed a new, super cool sorting algorithm. Here's the procedure: Until sorted: Randomly generate i...
1. Consider the following well-known sorting algorithm, which is studied later in the book, with a counter inserted to count the number of key comparisons. ALGORITHM SortAnalysis(A[0..n − 1]) //Input: An array A[0..n − 1] of n orderable elements //Output: The total number of key comparisons made count ←0 for i ←1 to n − 1 do v ←A[i] j ←i − 1 while j ≥ 0 and A[j ]> v do count ←count + 1 A[j + 1]←A[j ]...
I need the report like this (idea) *Sorting Algorithms: A sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other algorithms (such as search and merge algorithms) which require input data to be in sorted lists; it is also often useful for canonical zing data and for producing human-readable output. More formally, the output must satisfy...
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...
Comparison of Sorting Algorithms You are required to implement all the sorting algorithms (Bubble, Selection, Insertion, Quick, Merge). Take help from lecture slides and welb . You will then create arrays of different sizes as instructed below, test each algorithm on each array and record the execution times of each individual algorithm on each array. . You will report these execution times in a table and then write a report explaining the execution times of the sorting algorithms according to...
2. Here is a sorting algorithm that I like to use. Given an unsorted list of size n, let Xx represent the data in location k of the unsorted list. Compare xi to X2 and switch if necessary so that they are in sorted order, smallest first. Compare Xn-1 and Xn and switch if necessary so that they are in sorted order, smallest first. • Compare x3 with its left neighbors, switching if necessary so that the 3 first entries...
How can i make a counter for the number of exchanges made in the linear algorithm?? The binary counter works but the linear doesn't. Here's my code. #include <iostream> using namespace std; void selectionSort(int[], int, int& ); void showSelection(int[], int); void sortArray(int[], int, int&); void showArray(const int[], int); int main() { int values[25] = { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24...
Hello this is my java sorting algorithm program i need all of my errors corrected so I can run it. thank you!! import java.util.Scanner; public class SortingAlogs { public static void main(String[]args){ int array [] = {9,11,15,34,1}; Scanner KB = new Scanner(System.in); int ch; while (true) { System.out.println("1 Bubble sort\n2 Insertion sort\n3 Selection sort\n"); ch = KB.nextInt(); if (ch==1) bubbleSort(array); if (ch==2) insertion(array); if (ch==3) Selection(array); if (ch==4) break; print(array); System.out.println(); } }...
The goal is to generate some random number and output a sorted list by quicksort. what do I need to add in my main to accomplish that? i also want it to output the run time. thank you #include "pch.h" #include <iostream> using namespace std; /* C implementation QuickSort */ #include<stdio.h> void swap(int* a, int* b) { int t = *a; *a = *b; *b = t; } int partition(int arr[], int low, int high) { ...
What is the time-complexity of the algorithm abc? Procedure abc(n: integer) s := 0 i :=1 while i ≤ n s := s+1 i := 2*i return s consider the following algorithm: Procedure foo(n: integer) m := 1 for i := 1 to n for j :=1 to i2m:=m*1 return m c.) Find a formula that describes the number of operations the algorithm foo takes for every input n? d.)Express the running time complexity of foo using big-O/big-
PLEASE READ CAREFULLY AND ALL THE WAY THROUGH!!! I already asked this question but unfortunately the person who answered it did not read it. There is a sorting algorithm, “Stooge-Sort” which is named after the comedy team, "The Three Stooges." if the input size, n, is 1or 2, then the algorithm sorts the input immediately. Otherwise, it recursively sorts the first 2n/3 elements, then the last 2n/3 elements, and then the first 2n/ 3 elements again. The details are shown...