计算机科学导论第11章参考答案
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
CHAPTER 11
Data Structures
Review Questions
1.We need data structures to hold a collection of related variables so that we can
solve complex problems more efficiently.
3.An array is a fixed-size sequenced collection of elements of the same data type.
5.Elements of an array are contiguous in memory and can be accessed by use of an
index. Elements of a linked list are stored in nodes that may be scattered through-
out memory and can only be accessed via the access functions for the list (i.e., a
specific node is returned by a search function).
7.A frequency array shows the number of elements with the same value found in a
particular collection of data.
9.An array is stored contiguously in memory. A two-dimensional array uses row-
major storage in which the array is essentially stored as an array of arrays.
11.The fields of a node in a linked list are the data itself and a pointer (address) to the
next node in the list.
13.The head pointer contains the address of the first node in the list.
15.A singly linked list is a linked list in which each node contains only one pointer
that contains the address of the following node. There are multi-linked lists in
which each node contains more than one pointer, allowing for much more complex
data structures.
Multiple-Choice Questions
17.d
19.d
21.b
23.d
25.c
27.b
29.d
3
4CHAPTER 11DATA STRUCTURES
31.a
33.a
35.b
Exercises
37.
Compare
Input: Two arrays (A and B) of 10 integers
1. Set Index equal to 0
2. While Index is less than 10
2.1 If A [Index] is not equal to B [Index]
2.1.1 Return false
End if
2.2 Increment Index
End loop
3. Return true
End
39.
Print
Input: An array (A), the number of rows (I), and the number columns (J)
1. Set RowIndex equal to 0
2. Set ColIndex equal to 0
3. While RowIndex is less than I
3.1 While ColIndex is less than J
3.1.1 Print A [RowIndex][ColIndex]
3.1.2 Increment ColIndex
End loop
3.2 Move to next line in output
3.3 Increment RowIndex
End loop
End
41.
AddFractions
Input: Two fractions (Fr1 and Fr2)
1. Allocate new fraction object (Fr3)
2. Set Fr
3.denominator equal to Fr1.denominator * Fr2.denominator
3. Set Fr3.numerator equal to (Fr1.numerator * Fr2.denominator) +
(Fr2.numerator *Fr1.denominator)
4. Return Fr3
End
SECTION 5
43.
MultiplyFractions
Input: Two fractions (Fr1 and Fr2)
1. Allocate new fraction object (Fr3)
2. Set Fr
3.denominator equal to Fr1.denominator * Fr2.denominator
3. Set Fr3.numerator equal to Fr1.numerator * Fr2.numerator
4. Return Fr3
End
45.See Figure 11.1
Figure 11.1Exercise 45
47.When an element is to be added to the array, a new array must be allocated and all
of the old elements and the new element must be moved to the new array.
49.Adding an element to a linked list is easier because a linked list does not have to be
totally reallocated.
51.Accessing an element of an array is easier because an index can be used.
53.Sorting an array is easier because the elements can just be swapped rather than
having to redirect up to four different pointers.
6CHAPTER 11DATA STRUCTURES
SECTION 7
8CHAPTER 11DATA STRUCTURES。