Sample Tests

advertisement
Lewis/Chase
Java Software Structures
Test Bank
Sample Tests
The material that follows is a series of exams like those used in some Data Structures courses. These tests
include numerous questions related to the material in Chapters 1-9 of Java Software Data Structures, by
Lewis and Chase.
Test One
(itec220exam1.doc)
You have 50 minutes (one class period) to complete this exam. Your answers must be
recorded on this exam. This is a closed book, closed notes, (and closed neighbor) exam.
You may ask the instructor questions but do not disturb your classmates. The Radford
University Honor Code will be strictly enforced!
Questions 1-30 are short answer, fill in the blank, true/false and multiple choice. Each
questions is worth 2 points.
1. The first step in software development is to ___________________.
2. The ____________ process is often the most time consuming and expensive part
of the software life cycle.
3. True or false, exhaustive testing of software systems is possible and necessary.
4. The Spiral model of software development is designed to reduce _________.
Questions 5 - 8 relate to the following UML diagram.
LibraryCustomer
name
address
register()
deregister()
LibraryItem
0..*
0..*
title
callNumber
checkout()
return()
5. LibraryCustomer is a ______________.
6. Checkout() and return() are ______________.
7. The relationship between is LibraryCustomer and LibraryItem is an example of
____________.
A.
Association
B.
Aggregation
C.
Inheritance
D.
None of the above
©2004 Addison Wesley
1
Lewis/Chase
Java Software Structures
Test Bank
8. True or false, the cardinality of the relationship between LibraryCustomer and
LibraryItem means that for any given LibraryCustomer there are many
LibraryItems.
9. Recursion is a programming technique in which a ___________ calls
____________.
10. The non-recursive part of a recursive definition is called the _____________.
11. If method1 calls method2, method2 calls method3, and method3 calls method1,
this is called ______________.
12. Each recursive call to a method creates new ____________ and
_______________.
13. A ____________ is an object that collects and organizes other objects.
14. A data type whose values and operations are not inherently defined within a
programming language is ___________________.
A.
collection
B.
data structure
C.
abstract data type
D.
none of the above
15. A Java _____________ defines a set of abstract methods which is useful in
separating the concept of an abstract data type from its implementation.
16. An _____________ is an object that allows you to step through the elements of a
collection one at a time.
17. A linked list is composed of objects that each point to _____________________.
18. In inserting a node in a linked list, the order of operations is crucial. Given that
current points to node we wish to insert behind and that element points to the
element to be inserted, which of the following is the correct sequence of
operations.
A.
current.next = element
element.next = current
B.
element.next = current.next
current.next = element
C.
none of the above
19. A linked list is _____________ meaning that it may grow as needed.
©2004 Addison Wesley
2
Lewis/Chase
Java Software Structures
Test Bank
20. An array is ______________ meaning that it has fixed size.
21. Searching is the process of either finding a designated target within a list of items
or ________________________________________.
22. Linear search may require up to __________ comparisons while binary search
will only require roughly _____________ comparisons.
23. _____________ Sort sorts a list of values by repetitively putting a particular value
into its final, sorted, position.
24. _____________ Sort sorts a list of values by repeatedly comparing neighboring
elements in the list and swapping their position if they are not already in order.
25. _____________ Sort sorts a list of values by continually dividing the list in half
until each sub-list has one element and then recombining these sub-lists in order.
120 0
100 0
800
600
400
200
0
1
7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 97
26. The graph represents four growth functions (n log n, n2, n, 2n). Place each label
on the appropriate curve on the graph.
27. The following code segment is O(____).
for (int count =0; count < n; count++)
{
count2 = 1
while (count2 < n)
{
count2 *= 2;
}
}
©2004 Addison Wesley
3
Lewis/Chase
Java Software Structures
Test Bank
28. True or false, there are times when a linear search will be preferable to a
logarithmic search.
29. True or false, speeding up the processor by 10 times will speed up the processing
by 10 times.
30. The growth functions (10n2 + 100n, 10n3, 2n, n2 * log n) in ascending order
should be:
A.
10n3, 10n2 + 100n, n2 * log n, 2n
B.
10n2 + 100n, n2 * log n, 2n, 10n3
C.
10n2 + 100n, n2 * log n, 10n3, 2n
D.
none of the above
Questions 31 and 32 are worth 20 points each.
31. There is a variation of the Bubble sort algorithm called gap sort that rather than
comparing neighboring elements each time through the list, compares elements
that are some number(i) positions apart, where (i) is an integer less than n. For
example, the first element would be compared to the (i + 1) element, 2nd element
to the (i + 2) element, nth element to the (n-i) element, etc. A single iteration is
completed when all of the elements that can be compared, have been compared.
On the next iteration, i is reduced by some number greater than 1 and the process
continues until i is less than 1. Modify the bubble sort code given below to
implement gap sort.
public static void bubbleSort (Comparable[] data, int maxlength)
{
int position, scan;
Comparable temp;
for (position = maxlength; position >= 1; position--)
{
for (scan = 0; scan <= position – 1; scan++)
{
if (data[scan].compareto(data[scan+1]) > 0)
{
// Swap the values
temp = data[scan];
data[scan] = data[scan + 1];
data[scan + 1] = temp;
}
}
}
}
©2004 Addison Wesley
4
Lewis/Chase
Java Software Structures
Test Bank
32. The add operation for our linked list implementation of a bag assumed that since
order does not matter in a bag we would always add to the front of the list.
Modify the add operation to add to the rear of the list. You must not assume any
additional modifications. You may only modify the add operation.
//----------------------------------------------------------------// Adds the specified element to the bag.
//----------------------------------------------------------------public void add (Object element)
{
BagNode node = new BagNode (element);
node.next = contents;
contents = node;
count++;
}
©2004 Addison Wesley
5
Lewis/Chase
Java Software Structures
Test Bank
Test Two
(itec220exam2.doc)
Part I
You have 50 minutes (one class period) to complete this portion of your exam. Your
answers must be recorded on this exam. This is a closed book, closed notes, (and closed
neighbor) exam. You may ask the instructor questions but do not disturb your
classmates. The Radford University Honor Code will be strictly enforced!
This portion of your exam is worth 50 points. The second part of your exam, also worth
50 points will be given at the regularly scheduled exam time for your class.
Questions 1-50 are short answer, fill in the blank, true/false and multiple choice. Each
questions is worth 1 point.
1. A Last In First Out collection is called a ___________________.
2. The ____________ process is often the most time consuming and expensive part
of the software life cycle.
3. True or false, exhaustive testing of software systems is possible and necessary.
4. A First In First Out collection is called a ________________.
Questions 5 - 8 relate to the following UML diagram.
LibraryItem
title
callNumber
checkout()
return()
Book
author
publisher
Video
producer
studio
5. Book, Video, and LibraryItem are ______________.
©2004 Addison Wesley
6
Lewis/Chase
Java Software Structures
Test Bank
6. True or False, a book has only the attributes author and publisher.
7. The relationship between is Video and LibraryItem is an example of
____________.
a. Association
b. Aggregation
c. Inheritance
d. None of the above
8. True or false, a Video has methods or operations for checkout and return.
9. Recursion is a programming technique in which a ___________ calls
____________.
10. A collection in which items may be inserted or removed from either end but not
from the middle is called a _______________.
11. If method1 calls method2, method2 calls method3, and method3 calls method1,
this is called ______________.
12. Recurring software ____________ allow designers to capitalize on the expertise
of other developers.
13. We say that a program is __________ if it handles exceptional situations
gracefully, which means that the program recognizes the situation when it occurs
and either deals with it or terminates with useful error messages.
14. A data type whose values and operations are not inherently defined within a
programming language is ___________________.
a. collection
b. data structure
c. abstract data type
d. none of the above
15. A Java _____________ defines a set of abstract methods, implementing some of
them but not all of them, and is useful in separating the concept of an abstract data
type from its implementation.
16. An _____________ is an object that allows you to step through the elements of a
collection one at a time.
17. A ____________ list is a collection whose elements are ordered according to
some inherent characteristic of the elements.
18. A _____________ list is a collection where elements may be added to the front of
the list, to the rear of the list, or after any specified element in the list.
©2004 Addison Wesley
7
Lewis/Chase
Java Software Structures
Test Bank
19. A ______________ list is a collection whose elements are can be referenced by
numeric index
20. An array is ______________ meaning that it has fixed size.
21. Searching is the process of either ________________________________ or
________________________________________.
22. Linear search may require up to __________ comparisons while binary search
will only require roughly _____________ comparisons.
23. _____________ Sort sorts a list of values by repetitively putting a particular value
into its final, sorted, position.
24. The operation to place an element on a Stack is called ____________.
25. The operation to place an element on a Queue is called ____________.
120 0
100 0
800
600
400
200
0
1
7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 97
26. The graph represents four growth functions (n log n, n2, n, 2n). Place each label
on the appropriate curve on the graph.
27. The following code segment is O(____).
for (int count =0; count < n; count++)
{
for (int count2=count; count2 < n; count2++)
{
}
}
©2004 Addison Wesley
8
Lewis/Chase
Java Software Structures
Test Bank
28. A find operation on a linked implementation of a List is O(_____).
29. True or false, a Queue could be used to efficiently implement a Stack.
30. True or false, an Unordered List could be used to efficiently implement a Queue.
31. A _________ tree is a tree in which each node can have from 0 to 2 children.
32. A node that does not have a parent is called the _________ of a tree.
33. A node that does not have any children is called a ___________.
34. A tree of height h has at least one path from the root to a leaf of length
_________.
35. A balanced N-ary tree with n elements in it will have height _________.
B
J
E
L
X
Z
P
36. For the tree shown above, list the root _________.
37. For the tree shown above, list the leaves __________.
38. For the tree shown above, list the height _________.
39. For the tree shown above, list the internal nodes __________.
40. True or False, the tree shown above is balanced.
41. True or False, the tree shown above is complete.
42. A person who has responsibility for something simply because of their position is
said to have _________ responsibility.
©2004 Addison Wesley
9
Lewis/Chase
Java Software Structures
Test Bank
43. A person who has responsibility for something because they have done
something, or failed to do something, which caused the thing to happen is said to
have __________ responsibility.
44. A person who has responsibility for something because they have done something
wrong, or failed to do something they should have done, which caused the thing
to happen is said to be ______________.
45. A person who is financially responsible for something is said to be _________.
46. True or false, a person must have done something wrong in order to be financially
responsible.
47. True or false, a non-circular array implementation of a Queue is more efficient
with respect to time than a linked implementation.
48. True or false, a circular array implementation of a List never requires elements in
the array to be shifted as the result of an operation.
49. In the array implementation of a stack, the ____________ of the stack is always
in position 0 of the array.
50. In the circular array implementation of a Queue, we would know that the queue is
empty if front and rear are pointing to the same element in the array and
____________________________.
©2004 Addison Wesley
10
Lewis/Chase
Java Software Structures
Test Bank
Test Two
(itec220exam2_part2.doc)
Part II
You have 2 hours to complete this portion of your exam. Your answers must be recorded
on this exam. This is a closed book, closed notes, (and closed neighbor) exam. You may
ask the instructor questions but do not disturb your classmates. The Radford University
Honor Code will be strictly enforced!
This portion of your exam is worth 50 points (12.5 points per problem). The first part of
your exam that you took last week is also worth 50 points.
1. What is the exact output of the following legal java program?
//********************************************************************
// recurse.java
Author: Davis
//
// Demonstrates recursion.
//********************************************************************
public class recurse
{
//----------------------------------------------------------------//
//----------------------------------------------------------------public static void main (String[] args)
{
recurse(1);
System.out.println();
recurse(3);
}
public static void recurse(int x)
{
if (x<=0)
System.out.print("*");
else
{
recurse(x-1);
System.out.print(x);
recurse(x-1);
}
}
}
©2004 Addison Wesley
11
Lewis/Chase
Java Software Structures
Test Bank
2. Given the LinearNode class (below), write the addAfter(element, target) method for a
linked implementation of an unordered list.
//*******************************************************************
//
//
file: LinearNode.java
//
//*******************************************************************
class LinearNode {
Object element;
LinearNode next;
//===========================================================
// Creates a new LinearNode with the specified element.
//===========================================================
LinearNode (Object element) {
this.element = element;
next = null;
} // constructor LinearNode
} // class LinearNode
3. Write a method called stackcopy(stack1) that will return an exact copy of the stack
that it receives as a parameter. This method must create the copy using only the methods
push and pop. Hint: you may create and use as many stacks as you wish.
4. Write a method called countvalue(target, list) that given a particular target element
and an unoderedlist, will return an integer value of the number of times the particular
target element occurs in the list.
©2004 Addison Wesley
12
Lewis/Chase
Java Software Structures
Test Bank
Test Three
(itec220exam1Spring03.doc)
You have 50 minutes (one class period) to complete this exam. Your answers must be
recorded on this exam. This is a closed book, closed notes, (and closed neighbor) exam.
You may ask the instructor questions but do not disturb your classmates. The Radford
University Honor Code will be strictly enforced!
Questions 1-30 are short answer, fill in the blank, true/false and multiple choice. Each
questions is worth 2 points.
1. The first step in software development is to analyze the problem to develop a
thorough and accurate set of ___________________.
2. A ________________________ defines a process to be followed during
development of a system.
3. Systems that are ______________________ are much easier and cheaper to
maintain.
4. The Spiral model of software development is designed to reduce _________.
Questions 5 - 8 relate to the following UML diagram.
LibraryCustomer
name
address
LibraryItem
0..*
0..*
register()
deregister()
title
callNumber
checkout()
return()
5. LibraryItem is a ______________.
6. register and deregister are ______________.
7. The relationship between LibraryCustomer and LibraryItem is an example of
____________.
a. Association
b. Aggregation
c. Inheritance
d. None of the above
8. True or false, the cardinality of the relationship between LibraryCustomer and
LibraryItem means that for any given LibraryCustomer there is exactly one
LibraryItem.
©2004 Addison Wesley
13
Lewis/Chase
Java Software Structures
Test Bank
9. ______________ is a programming technique in which a method calls itself.
10. True or False, the non-recursive part of a recursive definition is called the base
case but is not required.
11. Recursion that does not terminate is called ___________________.
12. Each recursive call to a method creates new ____________ and
_______________.
13. A ____________ is an object that collects and organizes other objects.
14. A ____________ is an abstraction where the details of the implementation are
hidden.
15. A _____________ is a group of values and operations defined on those values.
16. An _____________ is an object that allows you to step through the elements of a
collection one at a time.
17. Decisions on how to handle ______________ should be made considering
whether the ADT or the user of the ADT should control the particular behavior.
18. In inserting a node in a linked list, the order of operations is crucial. Given that
current points to node we wish to insert behind and that element points to the
element to be inserted, which of the following is the correct sequence of
operations.
A.
current.next = element
element.next = current
B.
element.next = current.next
current.next = element
C.
none of the above
19. A linked list is _____________ meaning that it may grow as needed and
essentially has no capacity limitations.
20. An array is ______________ meaning that it has fixed size.
21. _____________ is the process of either finding a designated target within a list of
items or determining that it does not exist.
22. The process of searching by dividing a sorted list in half each time is called
_______________.
©2004 Addison Wesley
14
Lewis/Chase
Java Software Structures
Test Bank
23. _____________ Sort sorts a list of values by repetitively inserting a particular
value into a subset of the list that has already been sorted.
24. _____________ Sort sorts a list of values by repeatedly comparing neighboring
elements in the list and swapping their position if they are not already in order.
25. _____________ Sort sorts a list of values by partitioning the list using an
arbitrarily chosen partition element and then recursively sorting the sub-lists on
either side of the partition element.
120 0
100 0
800
600
400
200
0
1
7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 97
26. The graph represents four growth functions (n log n, n2, n, 2n). Place each label
on the appropriate curve on the graph.
27. The following code segment is O(____).
for (int count =0; count < n; count++)
{
for (int count2=0; count2 < n; count2++)
{
x++;
}
}
28. Linear search will be preferable to a logarithmic search when
________________________________________________.
29. True or false, speeding up the processor by 10 times will speed up the processing
by 10 times.
©2004 Addison Wesley
15
Lewis/Chase
Java Software Structures
Test Bank
30. The growth function (5n4 +10n2 + 100n) is Order(______):
A.
n log n
B.
n6
C.
n4
D.
none of the above
Questions 31 and 32 are worth 20 points each.
31. Currently, our linked bag implementation has a method called contains that will
return true if a bag contains a particular element and false otherwise. Create a new
method called eitherContains:
Public boolean eitherContains(BagADT bag, Object target)
That will return true if this bag or the one passed as a parameter contains the
target element. One obvious solution is to simply to test bag.contains(target). You
must NOT use that solution.
//----------------------------------------------------------------// Returns true if this bag contains the specified target
// element.
//----------------------------------------------------------------public boolean contains (Object target)
{
boolean found = false;
LinearNode current = contents;
for (int look=0; look < count && !found; look++)
if (current.getElement().equals(target))
found = true;
else
current = current.getNext();
return found;
}
32. The add operation for our array implementation of a bag assumed that since order
does not matter in a bag we would always add to the rear of the list. Modify the
add operation to add to the front of the list. You must not assume any additional
modifications. You may only modify the add operation.
//-----------------------------------------------------©2004 Addison Wesley
16
Lewis/Chase
Java Software Structures
Test Bank
// Adds the specified element to the bag, expanding the capacity
// of the bag array if necessary.
//-----------------------------------------------------public void add (Object element)
{
if (size() == contents.length)
expandCapacity();
contents[count] = element;
count++;
}
©2004 Addison Wesley
17
Lewis/Chase
Java Software Structures
Test Bank
Test Four
(itec220exam2Spring03.doc)
Part I
You have 50 minutes (one class period) to complete this portion of your exam. Your
answers must be recorded on this exam. This is a closed book, closed notes, (and closed
neighbor) exam. You may ask the instructor questions but do not disturb your
classmates. The Radford University Honor Code will be strictly enforced!
This portion of your exam is worth 80 points. The second part of your exam, worth 20
points will be given at the regularly scheduled exam time for your class. (11 am
Thursday, May 1)
Questions 1-30 are short answer, fill in the blank, true/false and multiple choice. Each
questions is worth 2 points.
1. A First In First Out collection is called a ___________________.
2. True or false, a stack can be easily implemented using an ordered list.
3. True or false, exhaustive testing of software systems is possible and necessary.
4. A collection where each node can have from 0 to 2 children is called a
________________.
Questions 5 - 8 relate to the following UML diagram.
LibraryItem
title
callNumber
checkout()
return()
Book
author
publisher
Video
producer
studio
5. Book, Video, and LibraryItem are ______________.
©2004 Addison Wesley
18
Lewis/Chase
Java Software Structures
Test Bank
6. True or False, a video has only the attributes producer, studio, title and
callNumber.
7. The relationship between is Video and LibraryItem is an example of
____________.
a. Association
b. Aggregation
c. Inheritance
d. None of the above
8. True or false, a Video has methods or operations for checkout and return.
9. A list that allows an element to be added after a target element is an
_____________ list.
10. A collection in which items may be inserted or removed from either end but not
from the middle is called a _______________.
11. If method1 calls method2, method2 calls method3, and method3 calls method1,
this is called ______________.
12. A data type whose values and operations are inherently defined within a
programming language is ___________________.
a. collection
b. data structure
c. abstract data type
d. primitive data type
13. An _____________ is an object that allows you to step through the elements of a
collection one at a time.
14. A ____________ list is a collection whose elements are ordered according to
some inherent characteristic of the elements.
15. A ______________ list is a collection whose elements are can be referenced by
numeric index
16. An array is ______________ meaning that it has fixed size while a linked
structure is ______________ meaning it allocates space as needed.
17. Linear search may require up to __________ comparisons while binary search
will only require roughly _____________ comparisons.
18. The operation to remove an element on a Stack is called ____________.
©2004 Addison Wesley
19
Lewis/Chase
Java Software Structures
Test Bank
19. The operation to remove an element on a Queue is called ____________.
20. The following code segment is O(____).
for (int count =0; count < n; count++)
{
int count2 = 0;
while (count2 < count)
{
count2 = count2 * 2;
}
}
21. A find operation on a binary tree is O(_____).
22. A node that does not have a parent is called the _________ of a tree.
23. A node that does not have any children is called a ___________.
24. A tree of height h has at least one path from the root to a leaf of length
_________.
B
J
E
L
X
H
Z
P
25. For the tree shown above, list the root _________ , the leaves __________ , and
the height ____________.
26. True or False, the tree shown above is balanced and complete.
27. A person who has responsibility for something simply because of their position is
said to have _________ responsibility while person who has responsibility for
something because they have done something, or failed to do something, which
caused the thing to happen is said to have __________ responsibility.
28. True or false, a person must have done something wrong in order to be financially
responsible.
29. When enqueueing an element on circular array implementation of a queue, the
equation to update the front variable is:
©2004 Addison Wesley
20
Lewis/Chase
Java Software Structures
Test Bank
Front =
30. In the circular array implementation of a queue, if front = rear, and the position in
the array at index front is not null, what does this mean?
Questions 31 and 32 are coding questions. Each questions is worth 10 points.
31. Given a linked list named x where each node in the list is a linearnode as
described in class (i.e. with setNext() and getNext() methods), write the addLast
method that given a new element will add it to the end of the list. For this
exercise, assume there is a pointer named front that points to the first element in
the list.
©2004 Addison Wesley
21
Lewis/Chase
Java Software Structures
Test Bank
32. What is the output of the following program?
//********************************************************************
// recurse.java
Author: Davis and Chase
//
// Demonstrates recursion.
//********************************************************************
public class recurse2
{
//----------------------------------------------------------------//
//----------------------------------------------------------------public static void main (String[] args)
{
recurse(2);
System.out.println();
recurse(3);
}
public static void recurse(int x)
{
if (x<=0)
System.out.print("***");
else if ((x % 2) == 0)
{
System.out.print(x);
recurse(x-1);
System.out.print(x);
}
else
{
System.out.print(x);
recurse(x-1);
recurse(x-2);
}
}
}
©2004 Addison Wesley
22
Lewis/Chase
Java Software Structures
Test Bank
Test Four
(itec220exam2_part2Spring03.doc)
Part II
You have 1 hour to complete this portion of your exam. Your answers must be recorded
on this exam. This is a closed book, closed notes, (and closed neighbor) exam. You may
ask the instructor questions but do not disturb your classmates. The Radford University
Honor Code will be strictly enforced!
This portion of your exam is worth 20 points. The first part of your exam that you took
last week is worth 80 points. Questions 1 – 5 are 1 point each.
1. A list that allows an element to be added to the front, rear, or after a particular
target element is a(n) _____________ list.
2. A collection in which items may be added or removed but have no order within
the collection is called a(n) ______________.
3. The find operation on a balanced binary search tree is O(_____).
4. An iterator that throws an exception if the underlying collection is modified while
the iterator is in use is said to be _______________. All of the Java Collections
API iterators have this attribute.
5. True or False, an unbalanced binary search tree will still always be more efficient
than a linked list.
Question 6 is worth 5 points
6. What is the advantage of the circular array implementation of a queue over an
array implementation of a queue?
©2004 Addison Wesley
23
Lewis/Chase
Java Software Structures
Test Bank
Question 7 is worth 10 points
7. Given the LinearNode class (below), write the addAfter(element, target) method for a
linked implementation of an unordered list.
//*******************************************************************
//
//
file: LinearNode.java
//
//*******************************************************************
class LinearNode {
Object element;
LinearNode next;
//===========================================================
// Creates a new LinearNode with the specified element.
//===========================================================
LinearNode (Object element) {
this.element = element;
next = null;
} // constructor LinearNode
} // class LinearNode
Question 8 is a 5 point extra credit question
8. Given our definition of a doubly linked list from class, write a method called
find_compare(target) that will search from the beginning of the list counting the number
of comparisons until a target is found, and search from the end of the list counting the
number of comparisons until the same target is found, and then output whether the target
is closer to the front or rear of the list. Note: this not an ordered list. This is simply a
doubly linked list.
©2004 Addison Wesley
24
Lewis/Chase
Java Software Structures
Test Bank
4. Write a method called countvalue(target, list) that given a particular target element
and an unoderedlist, will return an integer value of the number of times the particular
target element occurs in the list.
©2004 Addison Wesley
25
Lewis/Chase
Java Software Structures
Test Bank
Test Five
(itec220newexam1.doc)
You have 50 minutes (one class period) to complete this exam. Your answers must be
recorded on this exam. This is a closed book, closed notes, (and closed neighbor) exam.
You may ask the instructor questions but do not disturb your classmates. The Radford
University Honor Code will be strictly enforced!
Questions 1-30 are short answer, fill in the blank, true/false and multiple choice. Each
questions is worth 2 points.
1. The first step in software development is to analyze the problem to develop a
thorough and accurate set of ___________________.
2. A ________________________ defines a process to be followed during
development of a system.
3. Systems that are ______________________ are much easier and cheaper to
maintain.
4. The Spiral model of software development is designed to reduce _________.
Questions 5 - 8 relate to the following UML diagram.
LibraryCustomer
name
address
LibraryItem
0..*
0..*
register()
deregister()
title
callNumber
checkout()
return()
5. LibraryItem is a ______________.
6. register and deregister are ______________.
7. The relationship between LibraryCustomer and LibraryItem is an example of
____________.
a. Association
b. Aggregation
c. Inheritance
d. None of the above
8. True or false, the cardinality of the relationship between LibraryCustomer and
LibraryItem means that for any given LibraryCustomer there is exactly one
LibraryItem.
©2004 Addison Wesley
26
Lewis/Chase
Java Software Structures
Test Bank
9. ______________ is a programming technique in which a method calls itself.
10. True or False, the non-recursive part of a recursive definition is called the base
case but is not required.
11. Recursion that does not terminate is called ___________________.
12. Each recursive call to a method creates new ____________ and
_______________.
13. A ____________ is an object that collects and organizes other objects.
14. A ____________ is an abstraction where the details of the implementation are
hidden.
15. A _____________ is a group of values and operations defined on those values.
16. An _____________ is an object that allows you to step through the elements of a
collection one at a time.
17. Decisions on how to handle ______________ should be made considering
whether the ADT or the user of the ADT should control the particular behavior.
18. In inserting a node in a linked list, the order of operations is crucial. Given that
current points to node we wish to insert behind and that element points to the
element to be inserted, which of the following is the correct sequence of
operations.
A.
current.next = element
element.next = current
B.
element.next = current.next
current.next = element
C.
none of the above
19. A linked list is _____________ meaning that it may grow as needed and
essentially has no capacity limitations.
20. An array is ______________ meaning that it has fixed size.
21. _____________ is the process of either finding a designated target within a list of
items or determining that it does not exist.
22. The process of searching by dividing a sorted list in half each time is called
_______________.
©2004 Addison Wesley
27
Lewis/Chase
Java Software Structures
Test Bank
23. _____________ Sort sorts a list of values by repetitively inserting a particular
value into a subset of the list that has already been sorted.
24. _____________ Sort sorts a list of values by repeatedly comparing neighboring
elements in the list and swapping their position if they are not already in order.
25. _____________ Sort sorts a list of values by partitioning the list using an
arbitrarily chosen partition element and then recursively sorting the sub-lists on
either side of the partition element.
120 0
100 0
800
600
400
200
0
1
7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 97
26. The graph represents four growth functions (n log n, n2, n, 2n). Place each label
on the appropriate curve on the graph.
27. The following code segment is O(____).
for (int count =0; count < n; count++)
{
for (int count2=0; count2 < n; count2++)
{
x++;
}
}
28. Linear search will be preferable to a logarithmic search when
________________________________________________.
29. True or false, speeding up the processor by 10 times will speed up the processing
by 10 times.
©2004 Addison Wesley
28
Lewis/Chase
Java Software Structures
Test Bank
30. The growth function (5n4 +10n2 + 100n) is Order(______):
A.
n log n
B.
n6
C.
n4
D.
none of the above
Questions 31 and 32 are worth 20 points each.
31. Currently, our linked bag implementation has a method called contains that will
return true if a bag contains a particular element and false otherwise. Create a new
method called eitherContains:
Public boolean eitherContains(BagADT bag, Object target)
That will return true if this bag or the one passed as a parameter contains the
target element. One obvious solution is to simply to test bag.contains(target). You
must NOT use that solution.
//----------------------------------------------------------------// Returns true if this bag contains the specified target
// element.
//----------------------------------------------------------------public boolean contains (Object target)
{
boolean found = false;
LinearNode current = contents;
for (int look=0; look < count && !found; look++)
if (current.getElement().equals(target))
found = true;
else
current = current.getNext();
return found;
}
©2004 Addison Wesley
29
Lewis/Chase
Java Software Structures
Test Bank
32. The add operation for our array implementation of a bag assumed that since order
does not matter in a bag we would always add to the rear of the list. Modify the
add operation to add to the front of the list. You must not assume any additional
modifications. You may only modify the add operation.
//-----------------------------------------------------// Adds the specified element to the bag, expanding the capacity
// of the bag array if necessary.
//-----------------------------------------------------public void add (Object element)
{
if (size() == contents.length)
expandCapacity();
contents[count] = element;
count++;
}
©2004 Addison Wesley
30
Download