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

373 Assignment 1

This document contains homework problems for an algorithms course. Problem 1 asks to find the time complexity of three nested loops. Problem 2 asks to use the Master's theorem to find the time complexity of several algorithms described by recurrence relations. Problem 3 and 4 ask to write algorithms to find the (n+1)th Fibonacci number iteratively and recursively, and analyze their time complexities.

Uploaded by

Enmusk
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)
163 views2 pages

373 Assignment 1

This document contains homework problems for an algorithms course. Problem 1 asks to find the time complexity of three nested loops. Problem 2 asks to use the Master's theorem to find the time complexity of several algorithms described by recurrence relations. Problem 3 and 4 ask to write algorithms to find the (n+1)th Fibonacci number iteratively and recursively, and analyze their time complexities.

Uploaded by

Enmusk
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

CSE 373 : Design & Analysis of Algorithms

North South University


Homework 1
Section 4, 5 (ABH1) Deadline –
Wednesday, August 8, 2018

1. Find the complexity of the following set loops, where n is given as input:

i  n;
while(i > 0) {
j = I //Be Aware: this DOES NOT Start at 0
while (j < n) {
k  0;
while (k < n) {
k = k + 2;
}
j  j * 2;
}
i i / 2;
}

Express your answer using the asymptotic notation.

2. Master Theorem (Check the basic of solving recurrences of your own): Use The master
theorem applies to algorithms with recurrence relations in the form of

T (n) = aT (n=b) + O(nd)


for some constants a > 0, b > 1, and d >= 0

Find the asymptotic (big-O notation) running time of the following algorithms using
Master theorem if possible. State the runtime recurrence if it's not given, and if Master
theorem is applicable, explicitly state the parameters a, b and d. Otherwise, give a quick
reason that the recurrence relation is not solvable using Master theorem.
(a) An algorithm with the run-time recurrence:
T (n) = 3T (n=4) + O (n)
(b) An algorithm with the run-time recurrence:
T (n) = 8T (n=4) + O (n1:5)
(c) An algorithm solves problems by dividing a problem of size n into 3 sub-problems of
one-fourth the size and recursively solves the smaller sub-problems. It takes constant
time to combine the solutions of the sub-problems.

(d) An algorithm solves problems by dividing a problem of size n into 2n sub-problems of


half the size and recursively solves the smaller sub-problems. It takes linear time to
combine the solutions of the sub-problems.

3.

4.

(a) Write an algorithm to find out the (n+1)th Fibonacci term.

(b) Write an Iterative solution and find out the time complexity from your algorithm

(c) Write a recursive solution and solve using recursion tree and find out the asymptotic
notation.

You might also like