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
Problem statement: Using loop, write a program that will ask the user to enter a character for left or right. Then, the user wil
zvonat [6]
Define variables
left is l
right is r

Ask input
left or right

Ask input value

Equate l or r to the input value

Show ladder with steps equal to input value and in the side of input variable
7 0
3 years ago
What type of microscope requires a nonmetal sample to be prepared for viewing by coating it with a thin layer of a conductive ma
zheka24 [161]

The answer is a Scanning Electron Microscope

It is important to obtain and prepare proper samples when using SEM. The sample’s size, state, and shape are things that should be considered before the sample preparation. Some samples need to be coated. Most metals require no preparation since they can easily conduct electricity. Non-metals, however, needs to be coated with a thin layer of gold. Gold is the ideal non-metal and works most of the times.

5 0
4 years ago
Read 2 more answers
You are a cleared employee. You discovered fraud and waste of money related to a classified program within your agency. If you r
Irina-Kira [14]

Answer:

A. True.

Explanation:

In this scenario, you are a cleared employee. You discovered fraud and waste of money related to a classified program within your agency. If you report this fraud and waste through appropriate channels, you may receive protection under the Presidential Policy Directive 19 (PPD-19): Protecting Whistleblowers with Access to Classified Information.

In USA, the Presidential Policy Directive 19 (PPD-19) which was signed by President Barack Obama in October 2012, is an executive order designed to provide significant protection for an employee who have access to classified informations such as fraud, waste of money and abuse or prohibiting any form of retaliation against this cleared employee.

3 0
3 years ago
You are the senior nurse on the unit and you are orienting a new graduate LVN/LPN. One of the subjects you want to cover today i
Margarita [4]

Answer: D. Homans sign

Explanation:

Check for the severity of the swelling, monitor the flow of blood to the tissue, pulses equality, check for homans sign such as pain in the leg around the calve, the calve is meant to be of equal size and warmth. There should not be any reddish colouration or pains around the calve when there is ankle movement as this shows a negative sign of homans.

3 0
3 years ago
What is the cheapest type of printer to buy and run?
myrzilka [38]
It depends solely on how much you will use it. For example, laser printers are more suitable for offices, schools, and environments, where the printer is used almost constantly. If it's used a lot, you're probably looking at a laser printer, since the cartridges have a slightly higher price, but a much higher yield. If you can't afford a laser printer, and you're only going to use it at home, you're probably looking at an inkjet. If you need to print off something for school, ask your teacher, or someone that works at your school. Some secondary/high schools might allow you to use their printers at a lower price
7 0
4 years ago
Read 2 more answers
Other questions:
  • Which of the following is NOT a Boolean Search term used to refine search engine results? A. AND B. With C. OR D. NOT
    14·2 answers
  • What are some causes of the number of bytes on the wire exceeding the number of bytes being captured?
    6·2 answers
  • One is FPGA and other is ASIC. Budget, power consumption, and speed are the common parameters considered for the selection of th
    9·1 answer
  • Which ipv6 header field is known as the priority field?
    10·2 answers
  • 5. The coordinates of triangle ABC are A(-7, 3), B(3, -7) and C(8. 8)
    9·2 answers
  • Which sentence is an example of an I-statement?
    6·1 answer
  • Cine stie repede va rog mult si repede
    9·1 answer
  • Which program will have the output shown below?
    11·2 answers
  • Use the drop-down menus to complete statements about the Quick Steps function.
    5·1 answer
  • What are three coding languages that are used to build websites?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!