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
What aspect of web design is Gloria following when she uses the same color
tresset_1 [31]
The answer to this is C
4 0
3 years ago
Read 2 more answers
Factors of production are A. inputs into the production process. B. social and political conditions that affect production. C. t
ZanzabumX [31]

Answer:

The right answer is option (A).

Explanation:

There are mostly 4 main factors of production i.e. land, labor, capital, and entrepreneurship. These all can be termed as inputs into the production process.

Hence, the most appropriate answer is option (A).

While the other options are wrong because of the following reasons:

  • Option (B) shows the concept of effect on production by social and political conditions, which is not a factor of production.
  • Option (C) shows the concept of mathematical calculation which is also not the factor of production.
  • Option (D) shows the concept of economic inputs and outputs which play a role in production but it is not one of the factors of production.
5 0
3 years ago
Explain briefly the FIREWALLS
Vlada [557]

Answer:

Think of a firewall as your own personal security guard. The firewall will block unapproved websites from talking to your computer and will stop your computer from talking to unapproved/unnecessary websites. Hope this helps!

Explanation:

7 0
3 years ago
For a string s ∈ {0, 1} let denote the number represented by in the binary * s2 s numeral system. For example 1110 in binary has
Bogdan [553]

4657879790989o689ok,vm vm  vjl478o78o7t8o78o8y;l. ,nmhnjser467iu56uy56uh by

7 0
3 years ago
A half-life is the amount of time it takes for a substance or entity to fall to half its original value. Caffeine has a half-lif
Leokris [45]

Answer:

#include <iostream>

#include<iomanip>

using namespace std;

int main()

{

double caffeineMg;

cin>>caffeineMg;

cout<<"After 6 hours: "<<fixed<<setprecision(2)<<caffeineMg/2.0<<" mg\n";

cout<<"After 12 hours: "<<fixed<<setprecision(2)<<caffeineMg/4.0<<" mg\n";

cout<<"After 24 hours: "<<fixed<<setprecision(2)<<caffeineMg/8.0<<" mg\n";

 

return 0;

}

Explanation:

  • Take the caffeine as input from user.
  • Calculate by dividing this value with relevant half life.
  • Use setprecision(2) to display 2 digits after decimal point.
3 0
3 years ago
Other questions:
  • A ________ is when teachers develop a professional based network of people selected by him/her to pursue learning needs and shar
    12·1 answer
  • Almost all PCs have this type of serial connector
    8·1 answer
  • In an all-integer linear program,
    10·1 answer
  • A college has 2.3 ratio of men to women in its student body you what is the ratio of women to men
    15·1 answer
  • How do you invite someone to a conversation on brainly
    14·1 answer
  • About twice a day my Chromebook blacks out. why does it do that?
    8·2 answers
  • What is an overview of your opinion of Digital Etiquette? Do not look it up bc I will know!
    7·1 answer
  • Write a C console application that will be used to determine if rectangular packages can fit inside one of a set of spheres. You
    5·1 answer
  • Can someone help me with python
    10·1 answer
  • It is a kind of malware (malicious software) that criminals install on your computer so they can lock it from a remote location.
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!