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]
4 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]4 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
Savings accounts typically offer more interest than what
Serga [27]
The answer to this is B
8 0
3 years ago
Por favor alguem poderia me falar qual PC e melhor: Computador Gamer Fox PC FPS Intel Core i5 8GB (GeForce GTX 1050Ti 4GB GDDR5)
Ivanshal [37]

Eu acredito no primeiro como ele tem uma GTX 1050ti, i5 e 2tb.

3 0
3 years ago
Write a program to assign and display a string value to any variable of your choice
vazorg [7]

Answer:

How to create a string and assign it to a variable. To create a string, put the sequence of characters inside either single quotes, double quotes, or triple quotes and then assign it to a variable.

6 0
3 years ago
If an ARQ algorithm is running over a 40-km point-to-point fiber optic link then:
Dennis_Churaev [7]

Answer and Explanation:

Given data:

Distance (D) = 40 KM

Speed of light in the fiber =Distance/ speed of light in the fiber

a) Delay (P) = Distance/ speed of light in the fiber

= (40,000 Meters/2×108 m/s)

=( 40×103 Meters/2×108 m/s)

Propagation delay (P) = 0.0002 seconds or 200 microseconds

b)

if propagation delay is 0.0002 Seconds roundup trip time (RTT) will be 0.0004 Seconds or 400 micro Seconds

Essentially since transmission times and returning ACKs are insignificant all we really need is a value slightly greater than 0.0004 seconds for our timeout value.

c)

The obvious reasons would be if the data frame was lost, or if the ACK was lost. Other possibilities include extremely slow processing on the receive side (late ACK).

Or Extremely Slow Processing of the ACK after it is received back at the send side.

4 0
3 years ago
Question 5 of 10
Ostrovityanka [42]
Hello!

Answer:
B. Analyze data from the car’s external cameras.

I hope that this helps you!
3 0
3 years ago
Other questions:
  • To arrange data in alphabetical order quickly, you can _____ the data.
    7·2 answers
  • A person painting his house dumps the unused paint on the ground. Which of the following resources will this most likely pollute
    14·1 answer
  • . How is a form used?
    10·1 answer
  • The interaction between information technology and organizations is influenced___________.A) solely by the decision making of mi
    12·1 answer
  • You start up your laptop while getting a coffee across the room. You hear the usual chimes and doinks as it starts up. When you
    14·2 answers
  • An online service allows users to integrate their phonebook with their social media profiles and stores it on the cloud. The pho
    12·1 answer
  • PLEASE HELP ASAP<br> Which technology encrypts traffic between a web browser and a website?
    10·2 answers
  • Why media is far from government​
    6·2 answers
  • Draw a conceptual sketch of your laptop. Identify the keyboard, screen, power source, and storage device and etc. using arrows a
    8·1 answer
  • Part of the operating system core is responsible for controlling security, managing the file system, and providing a platform fo
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!