Answer:
Following are the algorithm to this question:
y = 0 // initialize variable y that assigns the value 0
p = 1 // initialize value 1 in the variable p which also known as starting position
init num = 1//define variable num that assign value 1
for j = 1 to n: //defining loop
y = m[j] - m[p]
if (y > 10) //defining if block
num++; //increment num variable
p=i; //holding loop value in p variable
y= 0//assign value 0 in y variable
Step-by-step explanation:
Following are the runtime analysis of the above-given algorithm:
The above-provided algorithm is greedy, but if it doesn't exceed the scope, it operates by greedily choosing its next object. Therefore the algorithm selects the fewest number of pens.
Running time:
This algorithm merely iterates once over all the points. The run-time is therefore O(n).