Data Structures &amp; Alogs HW_Part_1

# Data Structures &amp;amp; Alogs HW_Part_1 - 1 Data...

This preview shows pages 1–3. 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 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

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Chap. 1 Data Structures and Algorithms // Concatenate two strings String strcat(String s1, String s2); // Return the length of a string int length(String s1); // Extract a substring, starting at ‘start’, // and of length ‘length’ String extract(String s1, int start, int length); // Get the first character
This is the end of the preview. Sign up to access the rest of the document.

## Data Structures &amp;amp; Alogs HW_Part_1 - 1 Data...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online