11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Sec. 2.9 Exercises 47(c) For nonzero r<strong>at</strong>ional numbers a <strong>and</strong> b, a ≡ b if <strong>and</strong> only if a × b > 0.(d) For nonzero r<strong>at</strong>ional numbers a <strong>and</strong> b, a ≡ b if <strong>and</strong> only if a/b is aninteger.(e) For r<strong>at</strong>ional numbers a <strong>and</strong> b, a ≡ b if <strong>and</strong> only if a − b is an integer.(f) For r<strong>at</strong>ional numbers a <strong>and</strong> b, a ≡ b if <strong>and</strong> only if |a − b| ≤ 2.2.3 St<strong>at</strong>e whether each of the following rel<strong>at</strong>ions is a partial ordering, <strong>and</strong> explainwhy or why not.(a) “isF<strong>at</strong>herOf” on the set of people.(b) “isAncestorOf” on the set of people.(c) “isOlderThan” on the set of people.(d) “isSisterOf” on the set of people.(e) {〈a, b〉, 〈a, a〉, 〈b, a〉} on the set {a, b}.(f) {〈2, 1〉, 〈1, 3〉, 〈2, 3〉} on the set {1, 2, 3}.2.4 How many total orderings can be defined on a set with n elements? Explainyour answer.2.5 Define an ADT for a set of integers (remember th<strong>at</strong> a set has no concept ofduplic<strong>at</strong>e elements, <strong>and</strong> has no concept of order). Your ADT should consistof the functions th<strong>at</strong> can be performed on a set to control its membership,check the size, check if a given element is in the set, <strong>and</strong> so on. Each functionshould be defined in terms of its input <strong>and</strong> output.2.6 Define an ADT for a bag of integers (remember th<strong>at</strong> a bag may contain duplic<strong>at</strong>es,<strong>and</strong> has no concept of order). Your ADT should consist of the functionsth<strong>at</strong> can be performed on a bag to control its membership, check thesize, check if a given element is in the set, <strong>and</strong> so on. Each function shouldbe defined in terms of its input <strong>and</strong> output.2.7 Define an ADT for a sequence of integers (remember th<strong>at</strong> a sequence maycontain duplic<strong>at</strong>es, <strong>and</strong> supports the concept of position for its elements).Your ADT should consist of the functions th<strong>at</strong> can be performed on a sequenceto control its membership, check the size, check if a given element isin the set, <strong>and</strong> so on. Each function should be defined in terms of its input<strong>and</strong> output.2.8 An investor places $30,000 into a stock fund. 10 years l<strong>at</strong>er the account hasa value of $69,000. Using logarithms <strong>and</strong> anti-logarithms, present a formulafor calcul<strong>at</strong>ing the average annual r<strong>at</strong>e of increase. Then use your formula todetermine the average annual growth r<strong>at</strong>e for this fund.2.9 Rewrite the factorial function of Section 2.5 without using recursion.2.10 Rewrite the for loop for the r<strong>and</strong>om permut<strong>at</strong>ion gener<strong>at</strong>or of Section 2.2as a recursive function.2.11 Here is a simple recursive function to compute the Fibonacci sequence:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!