Data Str &amp; Algorithm HW Solutions 1

# Data Str & Algorithm HW Solutions 1 - addition, simply...

This preview shows page 1. Sign up to view the full content.

1 Data Structures and Algorithms Instructor’s note: Unlike the other chapters, many of the questions in this chapter are not really suitable for graded work. The questions are mainly intended to get students thinking about data structures issues. 1.1 This question does not have a speci f c right answer, provided the student keeps to the spirit of the question. Students may have trouble with the con- cept of “operations.” 1.2 This exercise asks the student to expand on their concept of an integer repre- sentation. A good answer is described by Project 4.5, where a singly-linked list is suggested. The most straightforward implementation stores each digit in its own list node, with digits stored in reverse order. Addition and multi- plication are implemented by what amounts to grade-school arithmetic. For
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: addition, simply march down in parallel through the two lists representing the operands, at each digit appending to a new list the appropriate partial sum and bringing forward a carry bit as necessary. For multiplication, com-bine the addition function with a new function that multiplies a single digit by an integer. Exponentiation can be done either by repeated multiplication (not really practical) or by the traditional Θ(log n )-time algorithm based on the binary representation of the exponent. Discovering this faster algorithm will be beyond the reach of most students, so should not be required. 1.3 A sample ADT for character strings might look as follows (with the normal interpretation of the function names assumed). 1...
View Full Document

## This note was uploaded on 12/27/2011 for the course MAP 2302 taught by Professor Bell,d during the Fall '08 term at UNF.

Ask a homework question - tutors are online