LetB[1...376] be an input array of length 376, whose elements must be integers in the set{0,1,2}. Consider the following procedure:
1: while true do
2:Find the largest i such that B[i] != 0
3: if no such i exists then return 0
4:B[i]←B[i]−1
5: for j = i + 1 to 376 do
6: B[j]←2
Is there any legal input B that can make the program run indefinitely (i.e., never terminate)?If yes, describe it. If not, provide a justification.
The question can be answer in two different parts what I mean to say is there are two possible solution to this question.
Solution 1:
If any input is not an integer then the program will never terminate it will keep on iterating because of error so it will never terminate. If there exists an (index i) whose that is not equal to 0 then it will never terminate.
Solution 2:
This solution only refers to integers only! The program always will terminate and there's no input that will keep the function iterating the loop will iterate till 376 times . If there an (index i) whose value is equal to 0 then it will terminate.
IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW
PLEASE GIVE A THUMBS UP
Get Answers For Free
Most questions answered within 1 hours.