Tutorial 1 - Algorithm Analysis - v2 - 4eeb58f0b9de020 - 202503152343 - 20740
Tutorial 1 - Algorithm Analysis - v2 - 4eeb58f0b9de020 - 202503152343 - 20740
Tutorial 1
(Data Structures and Algorithms & Mathematical Preliminaries)
1.2 Most programming languages have a built-in integer data type. Normally this representation has a fixed size,
thus placing a limit on how large a value can be stored in an integer variable. Describe a representation for integers
that has no size restriction (other than the limits of the computer’s available main memory), and thus no practical
limit on how large an integer can be stored. Briefly show how your representation can be used to implement the
operations of addition, multiplication, and exponentiation.
1.3 Define an ADT for character strings. Your ADT should consist of typical functions that can be performed on
strings, with each function defined in terms of its input and output. Then define two different physical
representations for strings.
1.11 Consider the design for a spelling checker program meant to run on a home computer. The spelling checker
should be able to handle quickly a document of less than twenty pages. Assume that the spelling checker comes
with a dictionary of about 20,000 words. What primitive operations must be implemented on the dictionary, and
what is a reasonable time constraint for each operation?
1.13 Imagine that you are given an array of records that is sorted with respect to some key field contained in each
record. Give two different algorithms for searching the array to find the record with a specified key value. Which
one do you consider “better” and why?
Chap.02:
Solve the following exercises: 2.6, 2.11, 2.14, 2.19, 2.21, 2.25, 2.26, 2.27, 2.29, 2.32, 2.34
2.6 Define an ADT for a bag of integers (remember that a bag may contain duplicates, and has no concept of
order). Your ADT should consist of the functions that can be performed on a bag to control its membership, check
the size, check if a given element is in the set, and so on. Each function should be defined in terms of its input and
output.
1
This algorithm turns out to be very slow, calling Fibr a total of Fib(n) times.
Contrast this with the following iterative algorithm:
2.25 Find a closed-form solution and prove (using induction) that your solution is
correct for the summation
2
2.26 Prove that the sum of the first n even numbers is n2 + n
(a) by assuming that the sum of the first n odd numbers is n2.
(b) by mathematical induction.
2.32 Prove (using induction) that the recurrence T(n) = T(n − 1) + n; T(1) = 1
has as its closed-form solution T(n) = n(n + 1)/2.
2.34 Expand the following recurrence to help you find a closed-form solution, and
then use induction to prove your answer is correct.
T(n) = T(n − 1) + 3n + 1 for n > 0; T(0) = 1.