Professional Documents
Culture Documents
22aie212 Lab1 22102
22aie212 Lab1 22102
AM.EN.U4AIE22102
AM.EN.U4AIE22102
1.
2.
a. No, we don't need any loops in this program because we can directly access the first and
last elements of the sorted array to find the smallest and largest elements, respec vely.
b. b. The me complexity of the program is O(1), which means it runs in constant me.
3.
AKSHAI D PILLAI
AM.EN.U4AIE22102
a. As the elements in the array change (but the size remains the same), the number of
mes the loop executes may change
b. The me complexity of the program is O(N), where N is the size of the array.
4.
a. No, the program for ques on 3 won't work efficiently for searching in a sorted array
because it doesn't take advantage of the fact that the array is sorted.
b. No, the program for ques on 3 is not the most efficient one for searching in a sorted
array.
c.
d. As the elements in the array change (but the size remains the same), the number of
mes the loop executes may change.
e. The me complexity of the binary search algorithm is O(log N), where N is the size of the
array.
AKSHAI D PILLAI
AM.EN.U4AIE22102
5.
a. The me complexity of this program is O(N), where N is the size of the array.
6.
7.
a. The me complexity of Euclid's algorithm for finding the GCD is O(log(min(a, b))).
b. To find an input that requires the maximum number of itera ons to solve, we need to
find two numbers 'a' and 'b' such that their GCD is 1 (indica ng they are coprime) and 'a'
is significantly larger than 'b'.