Return to main page


Design and Analysis of Algorithms

CMSC 441 - Fall 2021


Homework 1

Due: Monday, September 20th by 11:59:00 PM EDT (on blackboard)

Musical Selection: Symphony No. 1 in C Major — Ludwig van Beethoven

Respond to the questions below with appropriate responses as directed.

  1. (20 points) Consider the searching problem, described as follows:
    Input: An unsorted sequence of n numbers A = { a1, a2, ... an } and a number v.
    Output: An index i such that v = A[i] if v is contained in the sequence A at index i or the special value NIL if v is not contained in A.
    Provide pseudocode for a function Linear-Search which correctly implements a search on the sequence by scanning through the elements of A looking for v. Prove that your implementation is correct by providing a loop invariant and showing its correctness. Show what the worst case running time of this algorithm is.
  2. (15 points) Again, consider the searching problem, but this time with A being a sorted sequence of numbers rather than an unsorted sequence of numbers. How can you optimize searching the sequence for v in this case? Provide pseudocode for this improved implementation and show what the worst-case runtime of the algorithm is.
  3. (15 points) Consider the problem of adding two n-bit binary integers, stored in two n-element bit arrays A and B, with the result being stored in an (n + 1)-element bit array C. Provide a formal statement of the problem's inputs and outputs and provide a pseudocode function Bitarray-Add for adding the two integers.

Last modified Sunday, 03-Oct-2021 14:38:42 EDT