Let A[1, . . . , n] be an array of n distinct numbers. If i...
Let A[1, . . . , n] be an array of n distinct numbers. If i <
j and A[i] > A[j], then the pair (i, j) is
called an inversion of A.
1.
Which arrays with distinct elements from the set {1, 2, . . . ,
n} have the smallest
and the largest number of inversions and why? State the
expressions exactly in terms of n.
2.
For any 0 < a < 1/2, construct an array for...
First, understand the Selection-sort algorithm below:
Selection-sort(A:
Array [1..n] of numbers)
1
for i=n down to...
First, understand the Selection-sort algorithm below:
Selection-sort(A:
Array [1..n] of numbers)
1
for i=n down to 2
2
position=i
3
for j=1 to (i–1)
4
if A[j]>A[position] then position=j
5
if position ≠ i then
6
temp=A[i]
7
A[i]=A[position]
8
A[position]=temp
(4 points) If input A=[12,5,11,6,10,7,9,8], what will A be after
the 3rd iteration of the outermost for
loop of the Selection-sort algorithm completes? A=[__, __,
__, __, __, __, __, __]
(8 points) Modify the algorithm to solve the...
Suppose an array A stores n integers, each of which is in {0, 1,
2, ...,...
Suppose an array A stores n integers, each of which is in {0, 1,
2, ..., 99}. Which of the following sorting algorithms can sort A
in O(n) time in the worst case?
Question 16 options:
A)
merge sort
B)
counting sort
C)
quicksort
D)
None of these options is correct.
E)
insertion sort
We are given an array A of size n containing n positive and
negative integers (the...
We are given an array A of size n containing n positive and
negative integers (the array is indexed starting from 0).
Our goal is to find two indices i and j such that 0 ≤ i ≤ j ≤ n
and Pk=j k=i A[k] is maximized.
Input sequence: [2, -4, 1, 9, -6, 7, -3]
Output: [1, 9, -6, 7] or i = 2 and j = 5
Input sequence: [1, 2, 3, 4, 5, 6, -3]
Output: [1,...
int i,sum=0;
int
array[8]={//You decide
this};
int *a,*b,*c;
a = array;
b =
&array[3];
c =...
int i,sum=0;
int
array[8]={//You decide
this};
int *a,*b,*c;
a = array;
b =
&array[3];
c =
&array[5];
c[-1] = 2;
array[1] =
b[1]-1;
*(c+1) = (b[-1]=5) +
2;
sum += *(a+2) + *(b+2) +
*(c+2);
printf("%d %d %d
%d\n",
sum, array[b-a], array[c-a],
*a-*b);
array[8]={ ?? };
what is array[8]?
Hello, I feel like I am super close but I can not figure out why
my...
Hello, I feel like I am super close but I can not figure out why
my C++ code it not displaying the proper medium. Thank you!
Here is an example of the output:
Input : a[] = {1, 3, 4, 2, 6, 5, 8, 7}
Output : Mean = 4.5
Median = 4.5
Code so far:
#include <iostream>
using namespace std;
int main()
{
int a[100];
int n,i,sum=0;
float mean, medium;
//read array size
// read array
cout<<"Enter array size:...
Here are two relations:
R(A,B): {(0, 1), (2,3), (0, 1), (2,4), (3,4)}
S(B, C): {(0, 1),...
Here are two relations:
R(A,B): {(0, 1), (2,3), (0, 1), (2,4), (3,4)}
S(B, C): {(0, 1), (2, 4), (2, 5), (3, 4), (0, 2), (3, 4)}
Compute the following: a) 11'A+B.A2,B2(R); b) 71'B+l,C-l(S); c)
TB,A(R); d) TB,c(S); e) J(R); f) J(S); g) /A, SUM(Bj(R); h)
IB.AVG(C)(S'); ! i) !A(R); ! j) IA,MAX(C)(R t:><1 S); k) R ~L
S; I) R ~H S; m) R ~ S; n) R ~R.B<S.B S.
I want to know the solution for j to m