Question-56

Question-56

Which statement best describes an algorithm that takes as input a list of  n  integers and produces as output the smallest difference obtained by subtracting an integer in the list from the one following it

 

Solution

Set the answer to be \infty . For  i going from 1 through   n – 1 , complete the value of the ( i + 1)st  element in the list minus the ith element in the list. If this is smaller then the answer, reset the answer to be this value.

 

Leave a Reply