1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
AfilCa [17]
3 years ago
8

You are given an unsorted array x of elements that implement the Comparable interface. There are no duplicates in this array. Yo

u are also given a variable m of type Comparable. Write the code needed to assign to m a reference to the median value of the array. (You may modify the array x by rearranging its elements.)NOTE: The median of a set of values is the value in the set such that there are as many values that are greater as there are that are less. For purposes of THIS exercise, if the array has an even number of members, the median is the greater of the two middle values.
EXAMPLE 1: Given "bob" "carol" "ted" "alice" "fred" the median is "carol" because there are "bob" and "alice" are less than "carol" and "fred" and "ted" are greater.
EXAMPLE 2: Given "bob" "carol" "ted" "alice" "fred" "sue", the middle two values are "carol" and "fred" and so in THIS exercise we would consider the greater to be the median.
Computers and Technology
1 answer:
Andrei [34K]3 years ago
8 0

Answer:

boolean isEven = false;

if (x.length % 2 == 0)

isEven = true;

Comparable currentMax;

int currentMaxIndex;

for (int i = x.length - 1; i >= 1; i--)

{

currentMax = x[i];

currentMaxIndex = i;

for (int j = i - 1; j >= 0; j--)

{

if (((Comparable)currentMax).compareTo(x[j]) < 0)

{

currentMax = x[j];

currentMaxIndex = j;

}

}

x[currentMaxIndex] = x[i];

x[i] = currentMax;

}

Comparable a = null;

Comparable b = null;

if (isEven == true)

{

a = x[x.length/2];

b = x[(x.length/2) - 1];

if ((a).compareTo(b) > 0)

m = a;

else

m = b;

}

else

m = x[x.length/2];

You might be interested in
Look act the picture
VLD [36.1K]

Answer:

the answer is b

Explanation:

3 0
3 years ago
What is output by the following line of code?
astraxan [27]

Answer:int x = 5;

if(x < 5)

cout << "line 1 ";

cout << "line 2";

A. line 1 line 2 B. line 1 C. line 2

D. line 1 E. line 1line 2

line 2

2. What would be output by the following code? _______

int x = 0;

while(x < 5)

{

cout << x << " ";

x++;

}

A. 0 1 2 3 4 5 B. 1 2 3 4 5 C. 0 1 2 3 4

D. 0 E. 0 0 0 0 0

3. After execution of the following code, what will be the value of input_value if the value 3 is entered at the keyboard at run time? ________

cin >> input_value;

if (input_value > 5)

input_value = input_value + 5;

else if (input_value > 2)

input_value = input_value + 10;

else

input_value = input_value + 15;

a. A. 8

b. B. 13

c. C. 18

d. D. 0

e. E. 5

4. What would the user see displayed on the screen after the following lines of code are executed?¬¬________

int i = 6;

if (i == 10)

cout << “value: “ << i;

else

cout << "hmmm";

A. value: i B. value: 10

C. hmmm D. value: ihmmm

E. value: 10

Hmmm

5. What is the output of the following lines of code? ______

for(int i=0; i<4; i++)

cout << (i * 3) << " ";

A. 0 1 2 3 4 B. 0 3 6 9

C. 0 3 6 9 12 D. 0 1 2 3 E. 0 0 0 0

Explanation:

6 0
2 years ago
a. Daily Life Magazine wants an analysis of the demographic characteristics of its readers. The marketing department has collect
kherson [118]

Answer:

uh

Explanation:

7 0
2 years ago
Oxnard Casualty wants to ensure that their e-mail server has 99.98 percent reliability. They will use several independent server
sattari [20]

Answer:

The smallest number of servers required is 3 servers

<em />

Explanation:

Given

Reliability = 99.98\%

Individual Servers = 95\%

Required

Minimum number of servers needed

Let p represent the probability that a server is reliable and the probability that it wont be reliable be represented with q

Such that

p = 95\%\\

It should be noted that probabilities always add up to 1;

So,

p + q = 1'

Subtract p from both sides

p - p + q = 1 - p

q = 1 - p

Substitute p = 95\%\\

q = 1 - 95\%

Convert % to fraction

q = 1 - \frac{95}{100}

Convert fraction to decimal

q = 1 - 0.95

q = 0.05

------------------------------------------------------------------------------------------------

<em>To get an expression for one server</em>

The probabilities of 1 servers having 99.98% reliability is as follows;

p = 99.98\%

Recall that probabilities always add up to 1;

So,

p + q = 1

Subtract q from both sides

p + q - q = 1 - q

p = 1 - q

So,

p = 1 - q = 99.98\%

1 - q = 99.98\%

Let the number of servers be represented with n

The above expression becomes

1 - q^n = 99.98\%

Convert percent to fraction

1 - q^n = \frac{9998}{10000}

Convert fraction to decimal

1 - q^n = 0.9998

Add q^n to both sides

1 - q^n + q^n= 0.9998 + q^n

1 = 0.9998 + q^n

Subtract 0.9998 from both sides

1 - 0.9998 = 0.9998 - 0.9998 + q^n

1 - 0.9998 = q^n

0.0002 = q^n

Recall that q = 0.05

So, the expression becomes

0.0002 = 0.05^n

Take Log of both sides

Log(0.0002) = Log(0.05^n)

From laws of logarithm Loga^b = bLoga

So,

Log(0.0002) = Log(0.05^n) becomes

Log(0.0002) = nLog(0.05)

Divide both sides by Log0.05

\frac{Log(0.0002)}{Log(0.05)} = \frac{nLog(0.05)}{Log(0.05)}

\frac{Log(0.0002)}{Log(0.05)} = n

n = \frac{Log(0.0002)}{Log(0.05)}

n = \frac{-3.69897000434}{-1.30102999566}

n = 2.84310893421

n = 3 (Approximated)

<em>Hence, the smallest number of servers required is 3 servers</em>

6 0
3 years ago
How do you fix this windows 7 screen​
tensa zangetsu [6.8K]

Try restarting it. If you can’t restart because the screen is frozen maybe just turn it off and back on. If you already tried restarting and it still didn’t fix the problem, just give it some time. The computer will reset itself eventually which should fix the problem.

6 0
3 years ago
Other questions:
  • Sarah's research shows that business information management professionals also perform the duties of other professionals. Which
    9·1 answer
  • Using ajax technologies and apis, websites and applications can pull information from a variety of sources in order to create __
    8·1 answer
  • How do I take this prodram back off
    15·1 answer
  • If you're unsure of what chart to use for a set of data, what feature does Excel include that will help you to decide?
    7·1 answer
  • How are online sources used? Check all that apply.
    8·2 answers
  • -(-13) P binary using signed. 2's complement representation
    11·1 answer
  • What is the long tube on a microscope called​
    15·1 answer
  • Kyle returns to work the next day and he would like to continue working on the document from yesterday. What should Kyle do?
    7·1 answer
  • What is the value of x after running this code?
    13·2 answers
  • Your friend decides to create a spreadsheet containing vocabulary terms and their definitions to help prepare for the unit test
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!