Give a linear (O(n)) time algorithm sorting n values in range 0..(n^3) − 1.
(Hint: represent a value x as (i, j, k) where x = i · (n^2) + j · n + k.)
#include<iostream>
using namespace std;
int main()
{
int n,p,i,j;
cout<<"Enter the value of n : ";
cin>>n;
cout<<"Enter the number of values you want to
enter : ";
cin>>p;
int arr[n*n*n]={0};
cout<<"Enter the value one by one : ";
for(i=0;i<p;i++)
{
cin>>j;
arr[j]=1;
}
cout<<"Sorted values are : ";
for(i=0;i<n*n*n;i++)
{
if(arr[i]==1)
cout<<i<<" ";
}
}
Sample Output:-

Give a linear (O(n)) time algorithm sorting n values in range 0..(n^3) − 1. (Hint: represent...
Java Match the sorting algorithm with its time complexity, where n is the number of elements in the collection and k is the range of values. (This is a one-for-one match where an answer can only match one description.) Group of answer choices selection sort [ Choose ] O(n + k) O(n) to O(n^2) O(n log n) O(n^2) bubble sort [ Choose...
Algorithm Analysis: Study the following sorting algorithm. SORT( A[1...n]) bound <- Length(A) -1 for i <- 1 to Length(A) newbound <- 0 for j <- 0 to bound if A[j] > A[j + 1] swap( A[j], A[j + 1] ) newbound = j -1 bound <- newbound (a) Use the longer approach described in lecture 3 week 1 that we used in analyzing Insertion-Sort to compute the running time T(n) of the above SORT algorithm. You may...
When asked to describe an algorithm you are expected to give a
clear pseudo-code description of the algorithm
1. (10 pts) Here is a new sorting algorithm NewSort Suppose the original call made is NewSort(A,0,n-1) where A is an array integers. == void NewSort(int A[], int i, int j){ \\ sorts the subarray Aſi..j] if (j i+1) \\when there are only 2 elements if (A[i] > A[j]) swap(A,i,j) \\swaps A[i] and A[j] else { int k = (j-i+1)/3; NewSort(A,i,j-k); \\...
(V). Given the following algorithm, answer relevant questions. Algorithm 1 An algorithm 1: procedure WHATISTHIS(21,22,...,n: a list of n integers) for i = 2 to n do c= j=i-1 while (j > 0) do if ra; then break end if 4j+1 = a; j= j-1 end while j+1 = 1 end for 14: return 0.02. 1, 15: end procedure Answer the following questions: (1) Run the algorithm with input (41, 02, 03, 04) = (3, 0, 1,6). Record the values...
2. (10) Given a ”black-box” worst-case linear-time median subroutine, give a simple, linear-time algorithm that solves the selection problem for any given k, where 1 ≤ k ≤ n. Once again, an algorithm should be presented first, followed by its analysis.
Algorithm ComparisonCountingSorting(A[0..n-1], S[0..n-1] ) //Input: Array A[0..n-1] of orderable values //Output: Array S[0..n-1] of A's values in ascending order for i ← 0 to n – 1 do Count[i] ← 0 for i ← 0 to n – 2 do for j ← i + 1 to n – 1 do if A[i] < A[j] Count[j] ← Count[j] + 1 // increment counter of larger else Count[i] ← Count[i] + 1 for i ← 0 to n –...
3) How much time does the following “algorithm” require as a function of n? l=0 for i=1 to n do for j=1 to i do for k=j to n do l = l + 1
In Java, Bucket sort is a sorting algorithm that has O(n) performance on average. I want you to write a function to perform bucket sort on a list of strings. I also want you to test your function to see if it really work in linear time on average. This code will need to be tested. Finally, I want you to compare the performance of your function with Javasort method for lists.
Given the following code, find their big(O) for I in range of n: for j in range of n: for k in range of 10000: print(“test”) If an algorithm takes n3+1000n2+1000n2+9999 time, what is the Big O for this algorithm? Proof: O(nK) < O (2n), need to do some research on polynomial time and exponential time.
1(5 pts): For each code fragment below, give the complexity of the algorithm (O or Θ). Give the tightest possible upper bound as the input size variable increases. The input size variable in these questions is exclusively n. Complexity Code public static int recursiveFunction (int n)f f( n <= 0 ) return 0; return recursiveFunction (n - 1) 1; for(int i 0i <n; i+) j=0; for ( int j k=0; i; k < < j++) for (int j; m <...