0% found this document useful (0 votes)
23 views4 pages

22aie212 Lab1 22102

This document discusses time complexity analysis of various algorithms. It analyzes algorithms for finding minimum and maximum elements in an array, binary search, and Euclid's algorithm. The time complexities identified include O(N), O(log N), and O(sqrt(N)).

Uploaded by

Krishna Shankar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

22aie212 Lab1 22102

This document discusses time complexity analysis of various algorithms. It analyzes algorithms for finding minimum and maximum elements in an array, binary search, and Euclid's algorithm. The time complexities identified include O(N), O(log N), and O(sqrt(N)).

Uploaded by

Krishna Shankar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

AKSHAI D PILLAI

AM.EN.U4AIE22102

DESIGN AND ANALYSIS OF ALGORITHMS


LABSHEET 1
AKSHAI D PILLAI

AM.EN.U4AIE22102

1.

a. The loop executes (N-1) mes


b. No, the number of mes the loop executes does not change as the elements in the array
change. The minimum and maximum number of mes the loop executes are both N-1,
where N is the size of the array.
c. The me complexity of the program is O(N), where N is the size of the array.

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.

a. The me complexity of this algorithm is O(sqrt(n))


AKSHAI D PILLAI
AM.EN.U4AIE22102

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'.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy