0% found this document useful (0 votes)
13 views5 pages

Assignments AOA SE15

The document contains assignments related to analysis of algorithms including examining code for optimization opportunities, estimating time complexities of matrix operations, determining properties of different complexity functions, implementing sorting algorithms and analyzing their performance, and solving problems like reversing linked lists, binary search trees, Fibonacci series, merging sorted arrays, and Tower of Hanoi.

Uploaded by

Prabhakar TS
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)
13 views5 pages

Assignments AOA SE15

The document contains assignments related to analysis of algorithms including examining code for optimization opportunities, estimating time complexities of matrix operations, determining properties of different complexity functions, implementing sorting algorithms and analyzing their performance, and solving problems like reversing linked lists, binary search trees, Fibonacci series, merging sorted arrays, and Tower of Hanoi.

Uploaded by

Prabhakar TS
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/ 5

Education and Research Department

Assignments for Analysis of Algorithms


July 2004

Document No. Authorized By Ver. Revision Signature / Date


ER/CORP/CRS/SE1 Ravindra M. P Ver.1.1
5/004

COMPANY CONFIDENTIAL
Infosys Document Revision History

Document Revision History

Ver.
Date Author(s) Reviewer(s) Description
Revision
1.1 Jul 2004 Sivasubramanyam Y. Ramesh Babu S., Assignments in new
R M Bharadwaj format, in accordance
with the CDM

ER/CORP/CRS/SE15/004 Version No. 1.1 -I-


Infosys Table of Contents

Contents

Document Revision History ................................................................................................I


Contents............................................................................................................................. II
Assignment Chapter 1 - 3................................................................................................... 1
Assignment Chapter 4 - 5................................................................................................... 2

ER/CORP/CRS/SE15/004 Version No. 1.1 - II -


Infosys Assignment for Analysis of Algorithms

Assignment Chapter 1 - 3
1. Examine the code you have written for the Programming Fundamentals
project for code-tuning opportunities.

2. Consider a function that reads a matrix of numbers and outputs the sum of all
the entries. What do you think could be the worst-case complexity (running
time) of this program?
3. Make guesstimates of average-case complexity when the matrix represents the
consumption of various vegetables for each month of the year.

4. For the case when the matrix represents the number of days of the year for
which an Infoscion reports to another Infoscion directly. Did you need to
make any assumptions about internal data structures?

5. Which of the following statements is/are true?

a. A square matrix algorithm that is O(n2), where n is the “height” of the


matrix is O(m) where m is the total number of elements in the matrix
b. An O(n2) algorithm is an O(n3) algorithm is an O(n4) algorithm
c. An O(1034n) algorithm is an O(n) algorithm
d. An O(log2n) algorithm is an O(logen) algorithm is an O(log10n)
algorithm
e. Beyond a threshold problem size, an O(n2) algorithm always performs
better than an O(n3) one
f. Beyond a threshold problem size, an O(nk) algorithm always performs
better than an O(2n) one
g. Beyond a threshold problem size, an O(n2) algorithm always performs
better than an O(n3) one
h. Beyond a threshold problem size, an O(n2) algorithm always performs
better than an O(n3) one

ER/CORP/CRS/SE15/004 Version No. 1.1 -1-


Infosys Assignment for Analysis of Algorithms

Assignment Chapter 4 - 5
1. A list of employee records sometimes needs to be accessed in increasing order
of salary, and sometimes in the reverse order. What is the complexity of
reversing a linked list? A doubly linked list?

2. What is the worst-case complexity of finding a given element in a binary


search tree?

3. Compute the worst-case complexity of Euclid’s algorithm for computing the


greatest common divisor. (Note: The algorithm works by continually
computing remainders until 0 is reached. For example, if numbers given are
2340 and 1761, then the sequence of remainders is 579, 24, 3, and 0. Thus, 3
is the greatest common divisor)

4. Plot the actual running time of your implementation of bubble sort, insertion
and selection sort. Take an array size of 100 for the following kinds of input:
90% sorted array given, 90% reverse sorted array given, array with elements
alternating (10, 5, 8, 6, 20, 14,…), and array with randomly generated
elements

5. Implement Fibonacci Series using Iteration and Recursion. Identify the


drawbacks, if any, of either of these implementations.

6. Given two sorted arrays A and B and an auxiliary array C, find an O(n)
algorithm (where n is the number of elements in A and B) for merging the
contents of A and B into C such that the elements in C are sorted

7. Tower of Hanoi Problem: We are given n disks of different sizes and three
poles. Initially all these n disks are mounted on the first pole in order of size,
the largest at the bottom and the smallest at the top. The problem is to move
these disks to the third pole using the second pole as an auxiliary. At any
given time we can move only disk with a constraint that a larger disk cannot
be placed on top of a smaller disk.

Solve the Tower of Hanoi problem and analyze the complexity of your
algorithm

ER/CORP/CRS/SE15/004 Version No. 1.1 -2-

You might also like