ices are int fel. nternal? Problem 9 (10 points). Suppose we want to find the fr
ID: 3216432 • Letter: I
Question
ices are int fel. nternal? Problem 9 (10 points). Suppose we want to find the frst pair of consecutive integers that appears in a list of integers of size n22 (a) Construct an algorithm, using pseudocode, that takes as input a list of n integers and fnds the locations of the first pair of consecutive integers in the list, or returns o if there are no consecutive integers in the list. Store n inkes in arrey then retuns (ao), a )) return 0 (b) Trace the algorithm you created in part (a) for the list 1,3, 11,2,8,9. Start with 1, 1-1,1-3 1 11,1-21 for llop.retunn. ,,at h(!),a(u).(? ,z) Perforni a worste-case time coumplexity analysis for the algoritlm you coustructed in (a)Explanation / Answer
The worst case complexity of the problem is O(n^2)
Reason: Assuming there are no consecutive integers, then we iterate the inner loop (j=1 to n) times for each i. So, the time complexity will be n^2. The inner if condition checks for two things, which can be 2 comparison.
Hence the worst case time will be 2n^2 complexity
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.