0% found this document useful (0 votes)
17 views

Assignment 2

Algorithms Assignment 2

Uploaded by

Hermain Qadir
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Assignment 2

Algorithms Assignment 2

Uploaded by

Hermain Qadir
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Due Date: 31th Oct 2021

20% penalty for 1 day late CS2009: Design and Analysis of Algorithms (Fall 2021)
40% penalty for 2 days late Assignment 2
Submission not allowed afterwards Total Marks: 100

1. You are given an unsorted array of 100 elements. All elements are between 1-100 in
value and all are distinct except one element that repeats two times.
Design O(n2 ) time algorithm to find the duplicate element in the array.
Design O(n) time algorithm to find duplicate element in array. [5+10 = 15 points]

2. You are given an array of positive integers in unsorted arrangement. You need to
arrange the array in a zig-zag value of magnitudes such that a[1] > a[2] < a[3] >
a[4] < a[5] > a[6] and so on.
Design a O(nlogn) algorithm for this problem where n is the length of array.
Design O(n) time algorithm or better for this problem. [5+10 = 15 points]

3. Suppose you want to calculate square of a given number x with out using multiplication
*, division / and pow() function.
Design algorithm for this problem in O(n) time
Design algorithm for this in O(logn) time [5+10 = 15 points]

4. You know that divide and conquer algorithm exists to find maximum subarray sum
of any given array in O(nlogn) time. Design algorithm for this problem that takes no
longer than O(n) time. [15 points]

5. (a) You have studied binary search algorithm to search any number in an array. There
is another technique of searching known as Jump Search. Learn about Jump search
algorithm from this link https://www.geeksforgeeks.org/jump-search/. Take any input
sorted array (atleast of size 8) and search a number present at the end of array using
both binary search and Jump search. Show each iteration of both algorithms. Discuss
pros and cons of both techniques in different circumstances.
(b) Learn about how interpolation and exponential search works from this link https :
//www.geeksf orgeeks.org/searching − algorithms/
Write working of both searching algorithms (interpolation and exponential) in your
own words. [15+5 = 20 points]

6. HeapSort is a sorting technique that takes O(nlogn) time. You may watch this
video to understand working of heap sort. https : //www.youtube.com/watch?v =
M tQLl l5KhQ
Suppose array A contains 4,1,3,2,16,9,10,14,8,7. Sort it using heap sort along with
showing each iteration. [20 points]

1 of 1

You might also like