Quiz 1

advertisement
CptS 122 – Data Structures
January 18, 2016
Your Name: ___________________________
ID#:
___________________________
TA’s Name: ___________________________
Section #: ___________________________
Take-Home: Quiz 1 (15 pts) – Introduction to Data Structures
Print out, and provide your solutions to your TA in lab during the week of
January 25th!
1. (5 pts) In your own words, what is a test case?
A test case specifies the state and environment, test inputs and conditions,
and expected result for the unit/function/system under test. The goal of the
test case is to determine if the unit/function/system satisfies requirements
or works as intended.
Note: a test driver is a function or utility program that applies test cases to
the unit/function/system under test.
2. (5 pts) If an application requires the following kinds of questions answered:
a. What item is at position n?
b. Is item x in the list?
c. What is the last item in the list?
Is an array good choice for the underlying structure in the application? Explain.
An array is a “good” and efficient structure for an application that must
satisfy the questions listed above. Why? Well, let’s explore each question:
a. What item is at position n? We know that arrays are contiguous
in memory and support indexing. Accessing an item at position
n requires what is called “constant” time complexity. Constant
time is considered fast. If the underlying implementation was a
linked list, then accessing an item at position n would require
what is called “linear” time (because indexing is not supported
- must start at beginning of linked list and count nodes).
Constant time is faster than linear time.
b. Is item x in the list? If the items in the array are not in any
particular order, then finding an item x could require that the
entire array is searched (which would be the same with a
linked list). However, if the items in the array are in a
particular order, then binary search could be performed, so
only part of the array would be searched. Performing binary
Instructor: Andrew S. O’Fallon
CptS 122 – Data Structures
January 18, 2016
Your Name: ___________________________
ID#:
___________________________
TA’s Name: ___________________________
Section #: ___________________________
search on a linked list generally does not make sense, because
addresses (links) are being used instead of indexing.
c. What is the last item in the list? Generally we keep track of the
number of items in an array, so to find the last item requires
constant time complexity. However, to get the last item in a
linked list, all other items in the list must be visited, which is
considered linear time complexity.
3. (5 pts) Provide an example application for which a list is appropriate.
Please be sure to provide details with your application.
There are several applications that require lists as the underlying structure.
Grocery list, music collections, etc.
Instructor: Andrew S. O’Fallon
Download