Problem 1

Untitled

a) The bug is in line 2. To fix it, change the compare sign ‘<=’ to ‘<’

b)

list num_to_find list_length
new int[]{1, 2} 1 2

c) It is not possible for this to happen, because the moment the loop iterates to the point of list length, it will call list[list_length], at this point the call will return out of bounds and there is no error handling. Therefore, the program will terminate due to a failure when it executes the bug.

Problem 2

Untitled

Untitled

Untitled

a)

i) (pancakeSort, i, 10)→ (findFlipSpot, i, 26)

ii) (pancakeSort, pancakes, 10) → (findFlipSpot, pancakes, 27)

iii) (pancakeSort, pancakes, 1) → (findFlipSpot, pancakes, 27)

b) Program dependency graph

Inter-procedural: system-dependance graph (SDG) can be used to track such dependencies. This is because SDG allows us to track the dependencies across multiple functions in the program. In this problem, the private function findFlipSpot will only be called by pancakeSort function, and the local variables used in findFlipSpot (pancakes and i) are both input arguments that are passed from pancakeSort , which indicates a dependency across different functions. This is why we should use SDG to trace such dependencies.