AOA Assignments

download AOA Assignments

of 5

Transcript of AOA Assignments

  • 8/13/2019 AOA Assignments

    1/5

    COMPANY CONFIDENTIAL

    Education and Research Department

    Assignments for Analysis of Algorithms

    July 2004

    Document No. Authorized By Ver. Revision Signature / Date

    ER/CORP/CRS/SE1

    5/004

    Ravindra M. P Ver.1.1

  • 8/13/2019 AOA Assignments

    2/5

    Infosys Document Revision History

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

    Document Revision History

    Ver.

    Revision Date Author(s) Reviewer(s) Description

    1.1 Jul 2004 Sivasubramanyam Y. Ramesh Babu S.,

    R M Bharadwaj

    Assignments in new

    format, in accordance

    with the CDM

  • 8/13/2019 AOA Assignments

    3/5

    Infosys Table of Contents

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

    Contents

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

    Contents............................................................................................................................. II

    Assignment Chapter 1 - 3................................................................................................... 1

    Assignment Chapter 4 - 5................................................................................................... 2

  • 8/13/2019 AOA Assignments

    4/5

    Infosys Assignment forAnalysis of Algorithms

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

    Assignment Chapter 1 - 31. 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 allthe 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 theconsumption of various vegetables for each month of the year.

    4. For the case when the matrix represents the number of days of the year forwhich 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) algorithmc. An O(1034n) algorithm is an O(n) algorithmd. 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 performsbetter than an O(n

    3) one

    f. Beyond a threshold problem size, an O(nk) algorithm always performsbetter than an O(2n) one

    g. Beyond a threshold problem size, an O(n2) algorithm always performsbetter than an O(n3) one

    h. Beyond a threshold problem size, an O(n2) algorithm always performsbetter than an O(n3) one

  • 8/13/2019 AOA Assignments

    5/5

    Infosys Assignment forAnalysis of Algorithms

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

    Assignment Chapter 4 - 51. 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 binarysearch tree?

    3. Compute the worst-case complexity of Euclids algorithm for computing thegreatest common divisor. (Note:The algorithm works by continuallycomputing 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, insertionand 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 elementsalternating (10, 5, 8, 6, 20, 14,), and array with randomly generated

    elements

    5. Implement Fibonacci Series using Iteration and Recursion. Identify thedrawbacks, 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 threepoles. 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 movethese 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