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
Alinara [238K]
4 years ago
13

Consider the problem of finding the distance between the two closest numbers in an array of n numbers. (The distance between two

numbers `x `and `y` is computed as $|x - y|$.) Design a presorting-based algorithm in **pseudo code** for solving this problem and determine its efficiency class.
Computers and Technology
1 answer:
Nataliya [291]4 years ago
5 0

Answer:

The minimum distance between two closest number in an array is |$x-$y|

Algorithm: Pseudo code

minimum_distance(arr[0..n-1])

merge_sort(arr[0..n-1])

min_dist←∞

for i=0 to i=n-2 do

if (|arr[i+1]-arr[i])| < min_dist do

min_dist = |arr[i+1]-arr[i])|

return min_dist

Efficiency class:

The running time for worst case of merge sort is O(n logn) and for traversing the array is O(n) so total time will be:

T (n) = O(n logn) + O(n)

the term O(n logn) is dominating in above equation so the total running time will be T (n) = O(n logn)

Explanation:

minimum_distance(arr[0..n-1])

merge_sort(arr[0..n-1])   //merge sort is used to sort the array

min_dist←∞

for i=0 to i=n-2 do  

if (|arr[i+1]-arr[i])| < min_dist do

min_dist = |arr[i+1]-arr[i])|

return min_dist

// above loop calculates the least distance between the two elements of pre-sorted array  then keeps the track of the all possible least distances at different position where the elements available and then return the least distance

You might be interested in
For which tasks is Layout view most helpful? Check all that apply.
Solnce55 [7]

The task where the Layout view most helpful is showing how a report will look when printed.

<h3>What is the Layout view?</h3>

The Layout view is known to be a view that is said to be more of visually-oriented when compared to the Design view.

Note that the Layout view is one where each control often shows real data and as such, The task where the Layout view most helpful is showing how a report will look when printed.

Learn more about  Layout view  from

brainly.com/question/1327497

#SPJ1

6 0
2 years ago
For which programming task would you use a for loop?
kicyunya [14]

Answer:

A. Computing the average of a list of integers of unknown length

6 0
3 years ago
Write the definition of a function named quadratic that receives three double parameters a, b, c. If the value of a is 0 then th
podryga [215]

Answer:

Following are the program in the C++ Programming Language.

#include <iostream> //header file

#include <cmath> //header file

using namespace std; //namespace

//define function

void quadratic (double a, double b, double c)

{

 double x,y; //set double type variables

 //check a==0

 if (a==0)

 { //then print message

   cout << "no solution for a=0";

 }

 //check if solution is less than 0

 else if ((b*b - 4*a*c) < 0)

 { //print message

   cout << "no real solutions";

 }

 //otherwise

 else

 {//solve the following quadratic equation

   x = (-b + sqrt( b*b - 4*a*c)) /(2*a);//in term of x

   y = (-b - sqrt(b*b - 4*a*c)) / (2*a);//in term of y

   //check x is greater than y

   if (x > y){

     cout<<x; //print the value of x

   }

   //otherwise

   else{

     cout<<y;//print the value of y

   }

 }

}

//define main method

int main() {

 //set double type variables and assign their value

 double x=10, y=50, z=-205;

 //call the function

 quadratic(x,y,z);

}

<u>Output</u>:

2.67204

Explanation:

Here, we define a function "quadratic" and pass three double data type variables i.e., "a", "b" and, "c" inside the function.

  • Set two double type variable i.e., "x", "y".
  • Set the if conditional statement and check the conditions is the variable a is equal to the 0 then, print the message or check another condition is the solution of the equation "b*b - 4*a*c" is less than 0, then print the message.
  • Otherwise, solve the quadratic equation in terms of the variable x or the variable y.
  • Again check the condition inside the else part is the variable x is greater than the variable y then, print the value of x otherwise print the value of y.

Finally, we define the main function inside it we set three double type variables i.e., "x", "y" and, "z" and initialize value 10, 50 and, -250 then, call the function and pass the variables x y z in its parameter.

6 0
4 years ago
The files in James's computer were found spreading within the device without any human action. As an engineer, you were requeste
krok68 [10]

This type of infection is this a characteristic of a computer worm

For better understanding, lets explain what computer Worms means.

  • Computer Worm are commonly referred to as an independent program that often replicates or double itself by copying a fraction of itself onto another computer. They often exit in two forms. They are:

  1. Network Worm is a type of computer worm that replicates or copies different fraction of itself to computers linked together in known network.
  2. Host Worm is a type of computer worm that replicates or copies itself to another computer in a network and later on remove or deletes itself completely from the previous computer in which it was in.
  • Computer worm are capable of replicating themselves without human intervention.

Learn more about computer worm from

brainly.com/question/19631265

4 0
3 years ago
What role does Dan Carson play at Hornall Anderson Design Works?
ANEK [815]
<span>Head of Design 

Hope this helps ;)</span>
8 0
3 years ago
Other questions:
  • All wireless networks have their own name, referred to as the ________, which is used to identify the network.
    11·1 answer
  • In Microsoft Access, what happens when you save a query once and run it but then add more to the query? What will happen? a)erro
    12·1 answer
  • What are some effects of the holocaust? She walked along the river until a policeman stopped her. It was one o'clock, he said. N
    8·1 answer
  • TCP connections are established through sequence numbers. Someone can guess a client's next sequence number and then impersonate
    11·1 answer
  • What is output? x = 10 if (x &gt; 10): print(1) elif (x = 10): print(3) else: print(4)
    11·1 answer
  • Which statement about digital certificates is​ FALSE? A. The CA verifies a digital certificate​ user's identity online. B. Digit
    7·1 answer
  • In QBasic, create a number guessing challenge. Your program should generate a random number from 1-
    9·1 answer
  • Question 7<br> What is the description of The Ribbon?
    14·1 answer
  • Task queues, which allow for asynchronous performance, are an important part of modern processing architectures. Information abo
    13·1 answer
  • Someone put malware on your computer that records all of your keystrokes. what aspect of security was primarily attacked? choose
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!