12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

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

Sec. 2.9 Exercises 51(f) {〈2, 1〉, 〈1, 3〉, 〈2, 3〉} on the set {1, 2, 3}.2.4 How many <strong>to</strong>tal orderings can be defined on a set with n elements? Explainyour answer.2.5 Define an ADT for a set of integers (remember that a set has no concept ofduplicate elements, <strong>and</strong> has no concept of order). Your ADT should consis<strong>to</strong>f the functions that can be performed on a set <strong>to</strong> 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 that a bag may contain duplicates,<strong>and</strong> has no concept of order). Your ADT should consist of the functionsthat can be performed on a bag <strong>to</strong> 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 that a sequence maycontain duplicates, <strong>and</strong> supports the concept of position for its elements).Your ADT should consist of the functions that can be performed on a sequence<strong>to</strong> 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 inves<strong>to</strong>r places $30,000 in<strong>to</strong> a s<strong>to</strong>ck fund. 10 years later the account hasa value of $69,000. Using logarithms <strong>and</strong> anti-logarithms, present a formulafor calculating the average annual rate of increase. Then use your formula <strong>to</strong>determine the average annual growth rate for this fund.2.9 Rewrite the fac<strong>to</strong>rial function of Section 2.5 without using recursion.2.10 Rewrite the for loop for the r<strong>and</strong>om permutation genera<strong>to</strong>r of Section 2.2as a recursive function.2.11 Here is a simple recursive function <strong>to</strong> compute the Fibonacci sequence:// Recursive Fibonacci genera<strong>to</strong>rstatic long fibr(int n) {// fibr(91) is the largest value that fits in a longassert (n > 0) && (n

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

Saved successfully!

Ooh no, something went wrong!