0% found this document useful (0 votes)
14 views2 pages

Lab Sheet 1 (4)

The document outlines a series of programming tasks focused on iterative algorithms, including finding the smallest and largest elements in arrays, searching for elements, and checking for prime numbers. Each task requires the implementation of specific algorithms without using built-in functions, along with analysis of time complexity and loop execution counts. Additionally, it includes submissions for online coding problems and proofs of acceptance.

Uploaded by

Ad K
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)
14 views2 pages

Lab Sheet 1 (4)

The document outlines a series of programming tasks focused on iterative algorithms, including finding the smallest and largest elements in arrays, searching for elements, and checking for prime numbers. Each task requires the implementation of specific algorithms without using built-in functions, along with analysis of time complexity and loop execution counts. Additionally, it includes submissions for online coding problems and proofs of acceptance.

Uploaded by

Ad K
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/ 2

Lab Sheet 1

Revisiting basic iterative programs

1. Write a program to find the smallest element of an unsorted array of size N.


Don’t use any built-in functions/ methods like min() supported by certain programming
languages.
a. How many times does your loop execute?
b. As the elements in the array changes (the size of the array remains same), will there be
any change in the number of times the loop executes? What is the minimum and
maximum number of times the loop executes?
c. What is the time complexity of your program?

2. Write a program to find the smallest and the largest element in a sorted array.
a. Do we need any loops in this program?
b. What is the time complexity of your program?

3. Write a program to search an element ‘k’ in an unsorted array of size N.


a. As the elements in the array changes (the size of the array remains same), will there
be any change in the number of times the loop executes? What is the minimum and
maximum number of times the loop executes?
b. What is the time complexity of your program?

4. We need to search an element ‘k’ in a sorted array of size N.


a. Will your program for Qn. No 3 work for this case?
b. Is the program for Qn. No 3 the most efficient one for this? (Hint: There exists a
Binary search algorithm)
c. Write an iterative program to implement Binary search.
d. As the elements in the array changes (the size of the array remains same), will there
be any change in the number of times the loop executes? What is the minimum and
maximum number of times the loop executes?
e. What is the time complexity of your program?

5. Write an efficient program to find an element in an array which neither the smallest nor
the largest. (Hint: you can do this without a loop.)
a. What is the time complexity of your program?

6. Write an efficient program to check if a given number is prime or not.


a. What is the time complexity of the algorithm?
b. Show that the problem can be solved in root(n) time.

7. Write an efficient program to find the GCD (also called HCF) of two given numbers.
a. What is the time complexity of the algorithm?
b. Find an input that requires maximum number of iterations to solve.
8. You are given a sorted array A of size n. Write an iterative program to remove the
duplicates from the array. For example, if A[] = {2, 7, 7, 11, 24, 24, 24, 29, 36, 36}, your
output should be B[] = {2, 7, 11, 24, 29, 36}.
a. Count the operations to get the closed-form equation of running time (worst case).
b. Submit the program for the problem https://leetcode.com/problems/remove-
duplicates-from-sorted-array/ and submit the snapshot of acceptance as proof.
c. What is the time complexity?

9. Consider an array A of size n. Split A[] into the two arrays Low[] and High[] such that
Low[] contains all elements < A[0] and High[] contains all elements >= A[0].
a. Write an iterative algorithm and implement it.
b. What is the time complexity?

10. Given two sorted lists A[1..n] and B[1..n], write an algorithm to merge them into a single
sorted list C[1..2n]. For example, if A[] = {1,3,6,7} and B[] = {2,4,5,8}, then C[] =
{1,2,3,4,5,6,7,8}.
a. Find the complexity
b. Submit the program for the problem https://leetcode.com/problems/merge-two-
sorted-lists/ and submit the snapshot of acceptance as proof

11. You are given an array coordinates, cord[i] = [x, y], where [x, y] represents the coordinate
of a point. Check if these points make a straight line in the XY plane.
a. Find the time complexity of the algorithm.
b. Submit the program for the problem https://leetcode.com/problems/check-if-it-is-a-
straight-line/ and submit the snapshot of acceptance as proof.

12. There is a class with m students and n exams. You are given a 0-indexed m x n integer
matrix called score, where score[i][j] denotes the score the ith student got in the jth exam.
The matrix score contains distinct integers only. You are also given an integer k. Sort the
students (i.e., the rows of the matrix) by their scores in the kth (0-indexed) exam from the
highest to the lowest. Return the matrix after sorting it.
a. Find the time complexity
b. Submit the program for the problem https://leetcode.com/problems/sort-the-
students-by-their-kth-score/ and submit the snapshot of acceptance as proof.

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