Data Structure Ch 1-16

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

C

# What type would the getLength method for a list return? a) boolean b) ItemType c) integer d) void

b.

1. A pointer variable contains the ______ of a memory cell. a. content b. address c. data type d. ADT

c

1. A priority queue orders its items by ______. a. position b. value c. priority value d. size

B.

1. How is the order of the entries of an ADT list determined? a) by the list itself b) by the client c) by the operating system d) the order doesn't matter

c.

1. In the worst case, a binary search is ______. a. O(n) b. O(1) c. O(log 2 n) d. O(n 2 )

b.

1. The ADT ______ is value-oriented. a. list b. sorted list c. stack d. queue e. binary tree

A

1. What is the first step in implementing a tree? a. choose a data structure to represent its nodes b. determine the type of item to be stored in the tree c. determine the height of the tree d. determine how many items will be in the tree

a.

1. Which of the following is NOT part of the human cost of developing a computer program? a. efficiency of a program b. the the readability of a program c. the modifiability of a program d. the maintainability a program

A

1. Which of the following is a private element of the class ListQueue? a. listPtr b. isEmpty() c. peekFront() d. enqueue(const ItemType& newEntry)

A

1. Which of the following operations was NOT included in the ADT sorted list operations? a. print the sorted list b. insert an entry into a sorted list c. remove the entry at a given position from a sorted list d. remove a given entry from a sorted list

C

10. Given the following queue operations on an empty existing queue called nameQueue. nameQueue.enqueue(Bob) nameQueue.enqueue(Bill) nameQueue.enqueue(Bud) nameQueue.dequeue() nameQueue.enqueue(Boo) What is now the contents of the queue (with front of the queue listed leftmost)? a. Bob, Bill, Bud b. Bob, Bud, Boo c. Bill, Bud, Boo d. Boo, Bud, Bill

b.

10. In a tree, the children of the same parent are called ______. a. leafs b. siblings c. roots d. contemporaries

B

10. In the class LinkedSortedList, the method copyChain(ptr)is classified as which of the following? a. public b. private c. shared d. virtual

D

10. Select the sorting algorithm(s) that is O(n 2 ) a) insertion sort b) selection sort c) bubble sort d) all three

a.

10. The author suggests that when you first look at implementing an ADT List, that "list" is simply a fancy name for a. an array b. a bag c. a linked list d. a stack

A

10. What is the classification of the method getHeightHelper? a. protected b. private c. public d. restricted

C.

10. What should be returned by the list operation (aList.insert(2,x)).getEntry(2) ? a) false b) 2 c) x d) an exception is thrown

a.

10. Which of the following can be used to compare two algorithms? a. growth rates of the two algorithms b. implementations of the two algorithms c. test data used to test programs which implement the two algorithms d. computers on which programs which implement the two algorithms are run

D

10. Which of the following elements of ArrayQueue is not private? a. back b. count c. front d. isEmpty()

b.

11. Algorithm efficiency is typically a concern for ______. a. small problems only b. large problems only c. medium sized problems only d. problems of all sizes Chapter 10 Questions © 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

b.

11. Each node in a tree has ______. a. exactly one parent b. at most one parent c. exactly one leaf d. at most two leaves

B

11. Given the following code from BinaryNodeTree template<class ItemType> bool BinaryNodeTree<ItemType>::________(const ItemType& newData) { auto newNodePtr = std::make_shared<BinaryNode<ItemType>>(newData); rootPtr = balancedAdd(rootPtr, newNodePtr); return true; } // end add What is the name of this method? a. getHeight b. add c. remove d. getEntry

A

11. Given two initially empty queues, queue1 and queue2 and the following commands. queue1.enqueue(1) queue1.enqueue(2) queue2.enqueue(3) queue2.enqueue(4) queue1.dequeue() queueFront = queue2.peekFront() queue1.enqueue(queueFront) queue1.enqueue(5) queue2.dequeue() queue2.enqueue(6) What are now the contents of What is now the contents of queue1 (with front of the queue listed leftmost)? a. 2, 3, 5 b. 5, 3, 2 c. 4, 6 d. 6, 4

A

11. How does the isEmpty method of ArrayQueue class return the proper value? a. return count == 0; b. return front != back c. return front / back == 0 d. return count < DEFAULT_CAPACITY

C

11. In the array based implementation of the ADT List operation replace, what is the efficiency? a. O(n) b. O(n2) c. O(1) d. O(log n)

A

11. The worst scenario for insertion sort is a) 9 8 7 6 5 4 3 2 1 b) 1 9 2 8 3 7 4 6 5 c) 8 2 6 4 5 3 7 1 9 d) 5 6 3 8 9 2 1 7 4

B.

11. What operation does the ADT List have that an array does not? a. identify their items by number b. getLength() c. insertItem() d. isEmpty()

D.

11. What would be returned by the list operation (bList.insert(3,x)).remove(3)? a) 2 b) x c) false d) bList

b.

12. A node on the path from the root to node n is a(n) ______ of node n. a. ancestor b. descendant c. subtree d. leaf

A

12. Consider nameList of size 12. For the operation nameList.insert(Clyde,x), which of the following would be an invalid value for x? a) 0 b) 1 c) 3 d) 12

B

12. Given two initially empty queues, queue1 and queue2 and the following commands. queue1.enqueue(1) queue1.enqueue(2) queue2.enqueue(3) queue1.enqueue(4) queue1.dequeue() queueFront = queue1.peekFront() queue1.enqueue(queueFront) queue2.enqueue(5) queue1.dequeue() queue2.enqueue(7) What is the sum of the contents of queue2? a. 4 b. 15 c. 19 d. none of these

b.

12. If a problem of size n requires time that is directly proportional to n, the problem is ______. a. O(1) b. O(n) c. O(n 2 ) d. O(log 2 n)

C

12. In the class BinaryNodeTree, the protected method inorder has a parameter visit. What is the specification for this parameter? a. virtual b. value c. reference d. dummy

C

12. The ___ compares adjacent items and exchanges them if they are out of order. a) selection sort b) binary search c) bubble sort d) quicksort

B

12. The text defined a class SL_PriorityQueue. What command was used to accomplish the enqueue method? a. insert(newEntry); b. insertSorted(newEntry); c. push(newEntry); d. addItem(newEntry);

C.

12. When designing an array based implementation of an ADT List, which of the following are not specified as private? a. items b. itemCount c. clear() d. maxItems

D

12. Which operation creates a new list and then copies the entries in the given sorted list to the new list. a. newList b. destructor c. constructor d. copy constructor

b.

13. A descendant of node n is a node on a path from node n to ______. a. the root b. a leaf c. a sibling of node n d. a child of node n

C

13. A merge sort operation runs in: a) O(log n) time. b) O(n) time. c) O(n log n) time. d) O(n 2 ) time.

C

13. According to the text, the first step in simulating a system is to do what? a. write a computer program b. time events with a stopwatch c. construct a mathematical model d. hire a lawyer

B.

13. Given the commands below, what do they do? n = 0 for (position = 1 through intList.getLength()) n+= intList.getEntry(position) a) insert integers into the list b) sum the values found in list c) sum the numbers 0 through n d) calculate n!

D

13. To save a binary search tree in a file and then restore it to its original shape, what type of traversal should be used? a. postorder b. inorder c. reorder d. preorder

D.

13. What is the return type of the list operator remove(int position)? a. void b. int c. itemType d. bool

c.

13. Which of the following growth-rate functions grows the fastest in value? a. 1 b. n c. n 2 d. log 2 n

a.

14. A subtree of node n is a subtree rooted at ______. a. node n b. the parent of node n c. a child of node n d. a sibling of node n

D

14. An algorithm performing simulation of an oft repeated cycle, measuring the times and generating statistics is called what? a. customer loop b. timing loop c. statistical loop d. event loop

C.

14. Given the commands below, what do they do? for (position = 1 through aList.getLength()/2) { a = aList.getEntry(aList.getLength()-position+1) aList.setEntry(aList.getEntry(aList.getLength()-position+1)) aList.setEntry(a,position) } a) randomize the entries b) sort the entries c) reverse the order of the entries d) count how many entries there are

A

14. To remove a leaf in a binary search tree, what must be done? a. set the pointer in the leaf's parent to nullptr b. set the pointer in the leaf to nullptr c. set the pointer in the root to nullptr d. delete the data from the leaf

a.

14. Which of the following growth-rate functions grows the slowest in value? a. 1 b. n c. n 2 d. log 2 n

A.

14. Which of the following operators uses two parameters? a. insert b. getLength c. remove d. clear

d.

15. Each node in a binary tree has ______. a. exactly one child b. at most one child c. exactly two children d. at most two children

B.

15. Given the following diagram. What list operation does this depict? a. deleting an item in the list b. inserting an item in the list c. expanding the array to make it larger d. counting the number of items in the list

B

15. If node N is being removed from a binary search tree and has a left child, what must be done if P is the parent of N? a. let the left child of N adopt P b. let P adopt the left child of N c. store the data of the left child of N in N d. store the data of N in P

A

15. Which of the following are not position-oriented ADTs? a. bag b. stack c. list d. queue

a.

15. Which of the following growth-rate functions indicates a problem whose time requirement is constant? a. 1 b. n c. 2 n d. log 2 n

C

16. If a file contains items in a specified order, how must they be added to put them into a binary search tree in that same order? a. use the method addInOrder b. use the method inOrderAdd c. use the method add d. use the method reOrderAdd

a.

16. The ______ of a tree is the number of nodes on the longest path from the root to a leaf. a. height b. length c. depth d. balance

C.

16. To thoroughly test the insert method in an array-based implementation of ADT List, what other method do we need? a. clear b. remove c. getEntry d. the constructor

a.

16. Which of the following growth-rate functions indicates a problem whose time requirement is independent of the size of the problem? a. 1 b. n c. 2 n d. log 2 n

B

16. Which of the following would be an example of a value-oriented ADT? a. bag b. priority queue c. list d. stack

b.

17. A linear algorithm has the growth-rate function ______. a. 1 b. n c. 2 n d. log 2 n

C

17. For a stack, the push method places a new item onto the stack. What method for the queue would do a similar task? a. dequeue b. isEmpty c. enqueue d. peek

A.

17. Given the following diagram. What list operation does this depict? a. deleting an item in the list b. inserting an item in the list c. expanding the array to make it larger d. counting the number of items in the list

c.

17. In a ______ of height h, all nodes that are at a level less than h have two children each. a. general tree b. binary tree c. full binary tree d. complete binary tree

D

17. What efficiency is the tree sort in the average case? a. O(n) b. O(log2 n) c. O(n2) d. O(n * log n)

b.

18. A ______ of height h is full down to level h - 1, with level h filled in from left to right. a. full binary tree b. complete binary tree c. balanced binary tree d. general tree

a.

18. A quadratic algorithm is ______. a. O(n 2 ) b. O(n 3 ) c. O(2 n ) d. O(log 2 n)

D

18. For a queue, the dequeue removes the first item. What method for the stack is used to remove the appropriate item? a. peek b. poke c. enqueue d. pop

D.

18. In the author's array based implementation of the ADT List, to what one variable does the clear method assign a value? a. items[0] b. items[maxItems] c. position d. itemCount

c.

19. An exponential algorithm is ______. a. O(n 2 ) b. O(n 3 ) c. O(2 n ) d. O(log 2 n)

d.

19. In ______, the left and right subtrees of any node have heights that differ by at most 1. a. all trees b. all binary tress c. n-ary trees d. balanced binary trees

B

19. In the list based implementation of the ADT List, which of the following is not a private variable in the classe? a. headPtr b. isEmpty c. itemCount d. getNodeAt

A

19. Which ADT would be best use to model the customers at a bakery who take numbers to mark their turn? a. queue b. stack c. list d. bag

c.

2. Algorithm analysis should be independent of all of the following EXCEPT ______. a. the programming style used in the implementation of the algorithm b. the computer used to run a program which implements an algorithm c. the number of significant operations in an algorithm d. the test data used to test a program which implements an algorithm

B

2. Consider an array-based representation of a tree and a variable called root as the index to the tree's root node. What value does the text suggest to assign to root if the tree is empty? a. 0 b. -1 c. 1 d. nullptr

d.

2. The ADT stack manages an association between data items and the ______ of the data items. a. names b. values c. sizes d. positions

d

2. The first item to be removed from a priority queue is the item ______. a. at the front of the priority queue b. at the end the priority queue c. with the highest value d. with the highest priority value

c.

2. The members of a node structure can be accessed with the ______ operator. a. [] b. & c. -> d. at

c.

2. The selection sort continues until ______ of the n items in an array have been swapped. a. n/2 b. n - 2 c. n - 1 d. n

A.

2. Which element of the list does not have a unique predecessor? a) the head of the list b) the tail of the list c) the middle element of the list d) all have unique predecessors

B

2. Which of the following methods from ListQueue throws an exception? a. isEmpty() b. peekFront() c. ListQueue() d. dequeue()

B

2. Which of the following operations from the ADT sorted list behave as they do in the ADT list? a. getPosition(anEntry) b. getLength() c. removeSorted(anEntry) d. insertSorted(newEntry)

C.

20. Given the following diagram. What List action does this depict? a. insert a new node b. get the value stored at a node c. remove a node from the chain d. get the value stored at a node

d.

20. Which of the following is NOT a property of a complete binary tree of height h? a. all nodes at level h - 2 and above have two children each b. when a node at level h - 1 has children, all nodes to its left at the same level have two children each c. when a node at level h - 1 has one child, it is a left child d. all leaves are at level h

B

20. You are writing a simple word processor. What ADT would be best to use which would allow the typist to correct typing errors by using the Backspace key. a. queue b. stack c. list d. sorted list

B

21. In an event driven simulation, how is simulated time advanced? a. by a single time unit b. by a stop watch c. advanced to the time of the next event d. by a calendar

D.

21. In the link based implementation of the ADT List, what method does the destructor call? a. remove b. insert c. isEmpty d. clear

a.

21. The traversal of a binary tree is ______. a. O(n) b. O(1) c. O(n2) d. O(log2 n)

a.

22. Any data element within a record of a binary search tree is called a ______. a. field b. tree c. collection d. key

A.

22. Given the following pseudocode logic: if ( the insertion position is 1 ) Add the new node to the beginning of the chain else Ignore the first node and add the new node to the rest of the chain What does this describe? a. recursive addition of a node to the list b. iterative addition of a node to the list c. addition of a node to the beginning of the list d. adding a node to the end of the list

D

22. You wish to model who gets to land first as airplanes arrive at a busy airport. What kind of simulation would this be? a. time-driven simulation b. customer-driven simulation c. a sorted list d. event-driven simulation

B

23. In an array based implementation of the ADT List, what is a characteristic of the time required to access any particular element in the list? a. you have no way of knowing how long it will take b. the time required is a constant c. the time required is a function of the size of the list d. It is of order O(n2)

A

23. Lining up to buy a movie ticket or being put on hold by a computerized phone system are both examples of what type of ADT? a. queue b. stack c. list d. sorted list

b.

23. The maximum number of comparisons for a retrieval operation in a binary search tree is the ______. a. length of the tree b. height of the tree c. number of nodes in the tree d. number of leaves in the tree

a.

24. The maximum height of a binary tree of n nodes is ______. a. n b. n / 2 c. (n / 2) - 2 d. log2(n + 1)

C.

24. When calling the insert or remove methods, what is an advantage for the link-based implementation of the ADT List? a. searching for that position is quicker b. takes less memory c. no need to shift data d. easier to understand

B

24. Which of the following tasks would be a good application of the ADT Queue? a. generating random numbers for a game b. reading a string of characters c. keeping a grocery list d. parsing a mathematical expression such as (9 + 5) * 7^ 2

d.

25. The minimum height of a binary tree of n nodes is ______. a. n b. n / 2 c. (n / 2) - 2 d. ⎡log2(n + 1)⎤

C

25. What ADT would be used along with a queue to determine if a string is a palindrome? a. list b. sorted list c. stack d. priority queue

A.

25. When calling the insert or remove methods, what is an disadvantage for the link-based implementation of the ADT List? a. searching for that position is slower b. takes more memory c. must shift data d. harder to understand

B.

26. Adding or removing an entry anywhere within a link based list requires a change of at least how many pointers? a. one b. two c. three d. four

a.

26. Locating a particular item in a binary search tree of n nodes requires at most ______ comparisons. a. n b. n / 2 c. (n / 2) - 2 d. ⎡log2(n + 1)⎤

D

26. You are making a "to do" list for this week. You brainstorm all the things which need your attention, then you arrange them from most important to least. You have just used what kind of ADT? a. list b. sorted list c. stack d. priority queue

B.

27. A link based getEntry method requires how many steps to access the nth item in the list? a. n - 1 b. n c. n + 1 d. n2

A

27. An event list contains all future arrival events and what else? a. departure events b. event loops c. clock time d. externally generated events

d.

27. Locating a particular item in a balanced binary search tree of n nodes requires at most ______ comparisons. a. n b. n / 2 c. (n / 2) - 2 d. ⎡log2(n + 1)⎤

c.

28. A full binary tree whose height is 4 has ______ nodes. a. 7 b. 8 c. 15 d. 31

C.

28. In either the link based or array based implementation of the ADT List, what is the single parameter for both the remove and getEntry methods? a. itemCount b. maxItems c. position d. ItemType

B

28. Which of the following is not a similarity between a stack and a queue as described by the text? a. both have an isEmpty method b. both can retrieve an item from any position c. both can insert an entry at one end of the structure d. both can retrieve an entry from one end of the structure

C

29. A large corporation is facing financial troubles and finds that they must do a reduction in force (RIF). The people who were most recently hired must be let go. This is an example of which ADT? a. bag b. list c. stack d. queue

D

29. The post order traversal of the following tree is a. 1, 2, 3, 4, 5, 6, 7, 8, 9 b. 6, 2, 1, 4, 3, 5, 8, 7, 9 c. 6, 2, 8, 1, 4, 7, 9, 3, 5 d. 1, 3, 5, 4, 2, 7, 9, 8, 6

A.

29. What is the last step in the insertion process for a linked implementation of the ADT List? a. Connect the new node to the linked chain by changing pointers b. Create a new node and store the new data in it c. Determine the point of insertion d. The order of these steps really doesn't matter

d.

3. A pointer variable whose sole purpose is to locate the first node in a linked list is called ______. a. the list's top b. the node's link c. the list's link d. the list's head

d.

3. An algorithm's execution time is related to the number of ______ it requires. a. parameters b. test data sets c. data fields d. operations

A.

3. Changing the value of an entry at a given position on the list would probably be the task of which of these methods? a) replace b) get c) push d) insert

b.

3. Given the following array: 4 15 8 3 28 21 which of the following represents the array after the second swap of the selection sort? a. 4 3 8 15 21 28 b. 4 15 8 3 21 28 c. 3 4 8 15 21 28 d. 21 4 3 8 15 28

C

3. Given the following sequence of names added to an ADT sorted list: nameListPtr->insertSorted("Tammie"); nameListPtr->insertSorted("Brenda"); nameListPtr->insertSorted("Sarah"); nameListPtr->insertSorted("Tom"); nameListPtr->insertSorted("Carlos"); What would be returned by the call nameListPtr-> getPosition("Tammie") a. 1 b. 3 c. 4 d. 5

C

3. In an array-based representation of a tree, what keeps track of available nodes? a. the variable emptyCount b. the variable nextAvailable c. the free list d. the node list

C

3. In the class ListQueue, which method calls the list method insert? a. isEmpty() b. dequeue() c. enqueue(const ItemType& newEntry) d. the copy constructor

b.

3. The operations of the ADT sorted list are based upon the ______ of data items. a. names b. values c. sizes d. positions

D

3. Which data structure represents a waiting line and limits insertions to be made at the back of the data structure and limits removals to be made from the front? a. Stack. b. tree. c. Linked list d. Queue.

D

30. Each node in a binary tree has ______. a. exactly one child b. at most one child c. exactly two children d. at most two children

C.

30. What is the first step in the deletion process for a linked implementation of the ADT List? a. Return the node to the system b. Disconnect the node from the linked chain by changing pointers c. Locate the node you want to delete d. The order of these steps really doesn't matter

B

31. The maximum number of comparisons for a retrieval operation in a binary search tree is the ______. a. length of the tree b. height of the tree c. number of nodes in the tree d. number of leaves in the tree

d.

4. A(n) ______ operation sequentially visits each node in a linked list. a. access b. delete c. get d. traverse

c.

4. Assuming a linked list of n nodes, the C++ statements Node *cur = head; while (cur != null) { cout &lt;&lt; curr-&gt;item &lt;&lt; endl; cur = cur-&gt;next; } // end while require ______ assignment(s). a. n b. n - 1 c. n + 1 d. 1

c.

4. Given the fact that a selection sort of n items requires n 2 /2 + 5 * n/2 - 3 major operations, the selection sort is ______. a. O(1) b. O(n) c. O(n 2 ) d. O(log 2 n)

D

4. In the class LinkedSortedList, which of the following items are private? a. the constructor b. isEmpty() c. getEntry(position) d. getNodeAt(position)

B

4. In the class ListQueue, which method calls the list method remove? a. isEmpty() b. dequeue() c. enqueue(const ItemType& newEntry) d. the copy constructor

c.

4. The ______ is a position-oriented ADT that is not linear. a. sorted list b. queue c. binary tree d. list

D

4. What do you do if you remove a node from a tree in an array-based implementation? a. assign it to nullPtr b. nothing, leave it as is, just don't link anything to it c. remove it from the array d. add it to the free list

B

4. Which of the following characterizes a stack? a. FIFO b. LIFO c. FILO d. LILO

D

4. Which of the following list methods would have only one parameter? a) isEmpty b) setEntry c) insert d) remove

c.

5. Assuming a linked list of n nodes, the C++ statements Node *cur = head; while (cur != null) { cout &lt;&lt; curr-&gt;item &lt;&lt; endl; cur = cur-&gt;next; } // end while require ______ comparison(s). a. n b. n - 1 c. n + 1 d. 1

A

5. Given a sorted list with entries in ascending order, where do you insert a new entry? a. just before the first entry that is not smaller than the new entry b. just after the first entry that is not smaller than the new entry c. just before the first entry that is not larger than the new entry d. at the end of the list

A

5. In the class BinaryNode, which of the following methods are specified as type bool? a. isLeaf b. setItem c. setLeftChildPtr d. getLeftChildPtr

C

5. In the class ListQueue, which method besides isEmpty calls the isEmpty method from the list class? a. listPtr b. isEmpty() c. peekFront() d. enqueue(const ItemType& newEntry)

c.

5. The ______ compares adjacent items and exchanges them if they are out of order. a. selection sort b. binary search c. bubble sort d. quicksort

a.

5. To remove a node N from a linear linked list, you will need to ______. a. set the pointer next in the node that precedes N to point to the node that follows N b. set the pointer next in the node that precedes N to point to N c. set the pointer next in the node that follows N to point to the node that precedes N d. set the pointer next in N to point to the node that follows N

A

5. Which of the following characterizes a queue? a. FIFO b. LIFO c. FILO d. LILO

D.

5. Which of the following methods from list would have no parameters and void for the return type? a) setEntry b) getEntry c) insert d) clear

a.

5. Which one of the following ADTs is position-oriented? a. binary tree b. sorted list c. table d. priority queue

c.

6. A bubble sort requires at most ______ passes to sort an array of n items. a. n/2 b. n - 2 c. n - 1 d. n

a.

6. Assuming a linked list of n nodes, the C++ statements Node *cur = head; while (cur != null) { cout &lt;&lt; curr-&gt;item &lt;&lt; endl; cur = cur-&gt;next; } // end while perform ______ write operations. a. n b. n - 1 c. n + 1 d. 1

B.

6. Given bList: snibble, nibble, tribble, wibble, quibble. The command bList.insert(3, Bob) is executed. What is the appearance of the list? a) snibble, nibble, tribble, Bob, wibble, quibble b) snibble, nibble, Bob, tribble, wibble, quibble c) snibble, nibble, tribble, wibble, quibble, Bob, Bob, Bob d) Bob, Bob, Bob, snibble, nibble, tribble, wibble, quibble

D

6. Given the following diagram, a chain of linked nodes with head and tail pointers: How does this type of a linked list help us to implement a queue? a. able to traverse the list from back to front b. able to easily delete the node at the back/end of the chain c. able to keep a sorted chain d. able to easily add a node to the back/end of the chain

B

6. Given the following figure to the right: According to the text, what is the relationship between List A and List B? a. List A is composed of an instance of List B b. List B is composed of an instance of List A c. List A is concatenated to list B d. List B is a subset of list A

D

6. In the class BinaryNode, what value is stored in rootPtr if the tree is empty? a. 0 b. -1 c. 1 d. nullptr

b.

6. The node of a tree that has no parent is called a(n) ______. a. edge b. root c. leaf d. vertex

C

6. Which of the following is not an ADT Queue operation as presented by the author? a. test if queue is empty b. add new entry to back of queue c. add new entry to front of queue d. get entry that was added earliest to the queue

d.

6. Which of the following statements deletes the node to which cur points? a. prev->next = cur; b. cur->next = prev; c. cur->next = cur->next; d. prev->next = cur->next;

A.

7. Given bList: bob, slob, snob, cob, hob, rob and the operation bList.remove(4) is executed. What does the list become? a) bob, slob, snob, hob, rob b) bob, slob, snob, cob, rob c) bob, slob d) hob, rob

A

7. In class LinkedQueue, where does neNodePtr point? a. the back or end of the chain b. the front or beginning of the chain c. nullPtr d. the next element of the queue

B

7. In the class BinaryNode, if the tree is not empty, what points to the root's left child? a. getLeftHildPtr() b. rootPtr->getLeftChildPtr() c. getLeftChildPtr()-> rootPtr d. leftChildPtr

d.

7. In the worst case, the insertion sort's comparison occurs ______ times. a. n b. n - 1 c. (n - 1) / 2 d. n * (n - 1)/2

b.

7. The lines between the nodes of a tree are called ______. a. branches b. edges c. arches d. subtrees

d.

7. The solution to the Towers of Hanoi problem with n disks requires 2 n - 1 moves. If each move requires the same time m, the solution requires ______ time units. a. 2 n - 1 b. (2 n - 1) + m c. (2 n - 1) / m d. (2 n - 1) * m

C

7. When an ADT sorted list is implemented using an instance of the ADT list which is link based, what is the worst case efficiency? a. O(1) b. O(n) c. O(n2) d. O(n * log2 n)

C

7. Which of the following ADT Queue operators does not have return type specified as bool? a. isEmpty b. dequeue c. peekFront d. enqueue

c.

7. Which of the following statements deletes the first node of a linear linked list that has 10 nodes? a. head->next = cur->next; b. prev->next = cur->next; c. head = head->next; d. head = NULL;

d.

8. Consider an algorithm that contains loops of this form: for (i = 1 through n) { for (j = 1 through i) { for (k = 1 through 10) { Task T } } } If task T requires t time units, the innermost loop on k requires ______ time units. a. j b. 10 c. k * t d. 10 * t

a.

8. Each merge step of the mergesort requires ______ major operations. a. 3 * n - 1 b. 4 * n - 1 c. (n - 1)/2 d. n - 1

C.

8. Given cList: bip, snip, pip, rip, dip, clip. What value would be returned by the call to method cList.getEntry(3)? a) bip b) snip c) pip d) rip

B

8. In the class LinkedQueue, what must the peekFront method do before returning the value at the front of the queue? a. traverse the chain b. check that the queue is not empty c. remove the node at the beginning of the chain d. establish a pointer to the beginning of the chain

c.

8. The node that is directly above node n in a tree is called the ______ of node n. a. root b. leaf c. parent d. child

C

8. What overladed operator did the class BinaryNodeTree have specified in the text? a. less than b. not c. assignment d. plus (concatenation)

D

8. When an ADT sorted list is implemented using an instance of the ADT list which is link based, which of the following operations has worst case efficiency? a. insertSorted (newEntry) b. getEntry (position) c. clear() d. isEmpty()

D

8. Which of the following ADT Queue operators has a parameter? a. isEmpty b. dequeue c. peekFront d. enqueue

a.

8. Which of the following statements inserts a new node, pointed to by newPtr, at the end of a linear linked list? a. newPtr->next = cur; prev->next = newPtr; b. newPtr->next = head; head = newPtr; c. newPtr->next = NULL; d. prev->next = cur; newPtr->next = cur;

d.

9. A ______ allows the deletion of a node from a linked list without the need to traverse the list to establish a trailing reference. a. head pointer b. dummy head node c. tail pointer d. precede pointer

d.

9. A node directly below node n in a tree is called a ______ of node n. a. root b. leaf c. parent d. child

c.

9. Consider an algorithm that contains loops of this form: for (i = 1 through n ) { for (j = 1 through i) { for (k = 1 through 10) { Task T } } } If task T requires t time units, the loop on j requires ______ time units. a. 10 * t b. (10 * t) + i c. 10 * t * i d. t * i

B.

9. Given cList: bip, snip, pip, rip, dip, clip. What value would be returned by the call to method cList.insert(9, sip)? a) true b) false c) it throws an exception d) sip

A

9. Given the following figure to the right: According to the text, what is the relationship between List A and List B? a. List B is a descendant of List B b. List A is a descendant of List A c. List A comes after list B d. List B is a clone of list A

B

9. Given the following queue operations on an empty existing queue called nameQueue. nameQueue.enqueue(Sid) nameQueue.enqueue(Sal) nameQueue.enqueue(Sue) nameQueue.enqueue(Sam) nameQueue.dequeue() display (nameQueue.peekFront()) What name is displayed? a. Sid b. Sal c. Sue d. Sam

a.

9. The quicksort is ______ in the worst case. a. O(n 2 ) b. O(n 3 ) c. O(n * log 2 n) d. O(log 2 n)

D

9. To copy a tree, traverse it in __________ and add each data item visited to a new node. a. inorder b. postorder c. reorder d. preorder

C

9. What would be the purpose of the following lines of code? back = (back + 1) % DEFAULT_CAPACITY; items[back] = newEntry; a. enables a circular linked list implementation of a queue b. eliminates rightward drift c. enables a circular array implementation of a queue d. keeps a linked list from running out of memory

1. What is used to start accessing a linked chain of nodes? a. The head pointer b. item[0] c. item[1] d. The null pointer

A

1. What program sees whether a given string is a member of the language? a. The compiler b. A word processor c. An encryption program d. A text editor

A

1. Which of the following provides a way to enforce the wall of an ADT? a. Implement the ADT as a C++ class b. Always use public fields c. Never use private records together methods d. Link records together

A

13. Given the following method from the class Node: What does this method do? template<class ItemType> void Node<ItemType>::doSomething(const ItemType& anItem) { item = anItem; } a. setItem b. getItem c. setNext d. setPrevious

A

13. What is an easy way for the method clear to make the bag appear empty? a. Set itemCount to zero b. Set all the data values in all the entries to blanks and zeros c. Set itemCount to maxItems - 1 d. Set maxItems to zero

A

5. Term "infix" indicates that every binary operator appears where? a. between its operands b. after its operands c. before its operands d. before each operand

A

5. Which of the following methods needs a counter? a. getFrequencyOf b. toVector c. add d. remove

A

5. Which of the following methods would definitely be considered part of a core group? a. add b. findNext c. clear d. search

A

7. Given the following code: template < class ItemType> bool ArrayStack<ItemType>::doSomething() { bool result = false ; if (!isEmpty()) { top--; result = true ; } return result; } What method is this? a) pop() b) peek() c) default constructor d) copy constructor

A

9. What do we call the strategy used for guessing at a solution and backing up when an impasse is reached? a. backtracking b. impasse resolution c. modified guessing d. back guessing

A

9. What is the type of the value returned by the method isEmpty? a. bool b. int c. real d. long

A

9. When copying an object involves only copying the values of its data members, the copy is called a(n) ? . a. shallow copy b. deep copy c. transfer copy d. virtual copy

A

10. If you implement a stack using a chain of linked nodes that has a head pointer, where should the top of the stack be placed for easiest and fastest access? a) at the first node of the chain b) at the top of the tree structure c) at the last node of the chain d) it doesn't matter

A.

13. Given the following code: template < class ItemType> LinkedStack<ItemType>::~doSomething() { while (!isEmpty()) pop(); } What does this method do? a) it is the destructor b) it is the constructor c) it displays the contents of the whole stack d) if the stack is not empty, it returns the top of the stack

A.

14. The return type of the peek() operation in the array-based and pointer-based implementations of a stack is a) ItemType b) bool c) int d) assert

A.

18. In designing a link based implementation of the stack, what standard exception did the author decide to ignore? a) bad_alloc b) logic_error c) PrecondViolatedExcep d) nullPtrError

A.

29. Consider the push(newEntry) operation of the ADT Stack. What is the output of the operation? a. true or false b. there is no output c. the object that is at the top of the stack d. the number of items left on the stack

A.

10. What object oriented feature can we use to have a single test program, with one set of method calls in which the user can decide which bag implementation (array- or link-based) needs testing? a. copy constructor b. polymorphism c. toVector d. the case statement

B

10. Which method uses a while loop to cycle through an array's indices from 0 to itemCount - 1, comparing a given object to every object in the array? a. delete b. getFrequencyOf c. toVector d. isFull

B

10. Which of the following has the more involved grammar? a. postfix b. infix c. prefix d. reflex

B

14. Given the following method from the class LinkedBag What does this method do? template<class ItemType> bool LinkedBag<ItemType>::doSomething(const ItemType& anEntry) const { return (getPointerTo(anEntry) != nullptr); } a. setItem b. contains c. isEmpty d. destructor

B

15. In the array based implementation of a stack class, what does the constructor initialize the private variable top to? a) 0 b) -1 c) 1 d) MAX_STACK

B

2. Each method for the array based implementation of the ADT bag will require access to the array of entries and what else? a. The number of fields b. The current number of entries in the bag c. The ID of the previous bag entry d. The ID of the next bag entry

B

2. What states the rules of a language? a. The compiler b. The grammar c. The English teachers d. The computer teachers

B

2. What value should headPtr contain if there are no nodes for it to point to? a. The boolean value TRUE b. nullptr c. The constant ZERO d. The constant NULL

B

3. What is accomplished by hiding implementations of a stack in a class? a) client code can access any entries of the stack b) only the top of the stack can be accessed by client code c) you can also treat the ADT as a queue d) the code runs faster

B

31. Which of the following is not a listed outcome of the exhaustive search strategy described in the text? a. You go around in circles forever b. It is impossible to reach a city because no flights go there c. You eventually reach the destination city d. You reach a city C from which there are no departing flights

B

6. An add method that encounters a full array should either signal it's client or a. Crash the program b. Allocate a larger array c. Loop back to the beginning of the array for another pass through the array d. Merely increment the loop counter into the next area of memory

B

6. In what type of expression does an operator precede its operands? a. postfix b. prefix c. outfix d. infix

B

6. What type does the method contains return? a. int b. bool c. string d. ItemType

B

12. What kind of method might be most useful during program debugging? a) return the bottom element of the stack b) display the contents of the whole stack c) sort the items in the stack d) reverse the order of the items in the stack

B.

19. In the array based implementation of the stack is an if statement if (top < MAX_STACK - 1) ... // What is this checking for? a) a null pointer error b) does the stack have room for a new entry c) is the array empty d) where should we put the new entry

B.

30. Why would axioms be specified for an ADT. a. to determine the cost of development b. specify the behavior of the ADT c. to determine possible uses of the ADT d. to determine which ADT should be used

B.

4. In a link-based implementation of a stack you must write both a copy constructor and a) a virtual constructor b) a virtual destructor c) a sort() method d) a virtual instructor

B.

8. Given the following code: template < class ItemType> ItemType ArrayStack<ItemType>::doSomething() const { assert (!isEmpty()); return items[top]; } What method is this? a) pop() b) peek() c) default constructor d) copy constructor

B.

11. What method could be easily defined by calling getFrequencyOf? a. itemCount b. isEmpty c. add d. delete

C

11. Which of the following are a good reason for using an array-based implementation of a bag? a. An array is not fixed size b. You must traverse n entries to get to the nth item in the array c. Requires less memory than a link-based implementation d. Good choice for a large bag

C

22. The ______ operation of the ADT stack retrieves and then removes the top of the stack. a. isEmpty b. push c. pop d. peek

C

3. From the symbols of grammar given by the text, what is used to signify "x or y"? a. x ^ y b. x % y c. x | y d. x && y

C

3. Given the following poorly written code sequence: headPtr = new Node<std::string>(); headPtr = nullptr; What is the result? a. headPtr points to the new node b. Access the new node by use of headPtr c. The new node is inaccessible d. The program crashes

C

3. The default constructor for an array implementation of the ADT Bag should do what? a. Load the bag with blanks and zeros b. Set itemCount to DEFAULT_CAPACITY c. Initialize the current number of items d. Load the new entry with blanks and zeros

C

7. Given infix expression a + b Which of the following is the equivalent postfix expression? a. b + a b. + a b c. a b + d. + a b +

C

7. Rather than returning a value, a method can signal its client by a. Crashing the program b. Beeping c. Throwing an exception d. Ignoring the requested record

C

7. What must be done with a node that is removed from the bag? a. Set it to nullptr b. Decrement itemCount c. Use the delete command so system can use returned memory d. return canRmoveItem

C

9. If you implement a stack using an array, where should the bottom element of the stack be placed? a) at the end of the array b) mid array for a binomial search c) at the first element of the array d) it doesn't matter

C

11. Why would a stack be a poor choice for implementing an ADT bag? a) it might fill up b) you couldn't account for duplicates c) you need to be able to look through all the elements in the bag, not just the top of the stack d) actually it would be a good choice

C.

16. In the linked based implementation of a stack class, what does the default constructor initialize the private variable topPtr to? a) OrigChainPtr b) newChainPtr c) nullPtr d) 0

C.

2. When should a constructor use an initializer? a) when the value of the data member needs validation b) when the stack is full c) when the value of the data member has no restrictions d) when the stack is empty

C.

26. Consider the peek() operation for the ADT Stack as described by the author. What is its output? a. true or false a. there is no output b. the object that is at the top of the stack c. the number of items left on the stack

C.

6. Given the following code: template < class ItemType> ArrayStack<ItemType>::ArrayStack() : top(-1) { } What method is this? a) the default destructor b) the virtual destructor c) the default constructor d) the copy constructor

C.

12. What was the method recommended to avoid gaps in the array when an element is removed? a. Shift all the entries beyond the new gap back one slot b. Shift all the entries in front of the new gap up one slot c. Set the pointer in the entry before the gap to the entry after the gap d. Replace the entry being removed with the last entry in the array

D

12. Which of the following are a good reason for using a link-based implementation of a bag? a. A link list is fixed size. b. You can access nodes directly with equal access time c. A link-based implementation is good choice for a small bag d. Linked chains do not have a fixed size

D

20. Given this graphic of an array based stack. What would be returned by a call to the method peek() a) 2 b) 10 c) 20 d) 30

D

23. A stack is initially empty, then the following commands are performed: push 5, push 7, pop, push 10, push 5, pop which of the following is the correct stack after those commands (assume the top of the stack is on the left)? a. 5 10 7 5 b. 5 10 c. 7 5 d. 10 5

D

4. Given the expression a + b. What type of expression is this? a. prefix b. postfix c. outfix d. infix

D

4. In a link-based implementation, what node is the only one to which we have direct access? a. The last b. All are equally direct access c. The one at nullPtr d. The first

D

4. Why should we prevent a client's direct access to a data structure? a. To protect the job security of the systems analyst b. It is a federal law c. Most computer languages do not allow it d. The client could possibly damage the ADT's data

D

8. A destructor's name is a(n) ? followed by the class name. a. ^ b. $ c. @ d. ~

D

8. Given the infix expression a + (b * c) Which of the following is the equivalent prefix expression? a. a b c * + b. c * b + a c. a b c * + d. + a * b c

D

8. What did the method getCurrentSize return? a. The value of DEFAULT_CAPACITY b. The value stored in maxItems c. The ID of the most recently added element d. The value stored in itemCount

D

17. In the linked based implementation of a stack class, what method besides push() allocates a new node? a) pop() b) display() c) default constructor d) copy constructor

D.

28. Which of the following is a good analogy of the ADT Stack? a. people standing in a cafeteria line b. a paper bag with colored poker chips c. a group of people playing musical chairs d. a pile of textbooks on your desk

D.

5. What command is used to enforce a precondition that the peek() method cannot work on an empty stack. a) result = false; b) if (top < MAX_STACK - 1) c) return top < 0; d) assert (!isEmpty());

D.

16. A(n) ______ is a C++ construct that enables a programmer to define a new data type. a. class b. method c. data field d. object

a

24. What is the task of the toVector() method of the ADT Bag? a. copy the entries of the bag into a vector b. vector the entries to the printer c. test to see if there is a vector to the bag d. remove all objects from the bag

a

1. The specifications of an ADT's operations indicate ______. a. what the operations do b. how to implement the operations c. how to store the data in the ADT d. how to carry out the operations

a.

1. What is the corrected input if the line yww<dshr<<wd<e is typed on a keyboard, where < represents the backspace character? a. ywdswe b. ywwdwde c. ywdshwe d. ywdswd

a.

1. When is an array based implementation of the ADT stack not a better choice? a) the stack can be large, but often is not b) the stack does not exceed the fixed size of the array c) the stack is most always right around 80 characters d) the stack represents the number of students in a typical class

a.

11. If a stack is used by an algorithm to check for balanced braces, which of the following is true of a balanced braces string once the end of the string is reached? a. the stack is empty b. the stack has one "{" c. the stack has one "}" d. the stack has one "{" and one "}"

a.

11. In a recursive method that writes a string of characters in reverse order, the base case is ______. a) a string with a length of 0 b) a string whose length is a negative number c) a string with a length of 3 d) a string that is a palindrome

a.

14. Which of the following is the postfix form of the infix expression: (a + b) * c / d a. a b + c * d / b. a b * c / d + c. a + b * c / d d. a b + c d * /

a.

15. When you solve a problem by solving two or more smaller problems, each of the smaller problems must be ______ the base case than the original problem. a) closer to b) farther to c) either closer to or the same "distance" from d) either farther to or the same "distance" from

a.

16. In a graph that represents the flight map for the HPAir problem, if a flight exists from city C1 to city C2, C2 is said to be ______ C1. a. adjacent to b. similar to c. related to d. bordering

a.

19. Which of the following is NOT a precondition for an array that is to be searched by a recursive binary search algorithm? (first is the index of the first item in the array, last is the index of the last item in the array, and SIZE is size of the array) a) SIZE <= first b) 0 <= first c) last <= SIZE - 1 d) anArray[first] <= anArray[first + 1] <= ... <= anArray[last]

a.

2. A binary search uses a ______ strategy. a) divide-and-conquer b) sequential c) determine-the-pivot d) smallest-to-largest

a.

20. A function can indicate that an error has occurred by ______ an exception. a. throwing b. catching c. implementing d. declaring

a.

22. For an array containing 2, 3, 5, 6, 9, 13, 16, and 19, what value does a recursive binary search algorithm return when it searches for 10? a) -1 b) 0 c) 1 d) 10

a.

23. In a sorted array having SIZE locations, the kth smallest item is given by ______. a) anArray[k-1] b) anArray[k] c) anArray[SIZE-k] d) anArray[SIZE+k]

a.

25. A recursive solution that finds the factorial of n always reduces the problem size by ______ at each recursive call. a) 1 b) 2 c) half d) one-third

a.

25. Understanding what the problem is and what the requirements of a solution are is called a. Object Oriented Analysis b. Object Oriented Design c. Object Oriented Solution d. Algorithmic Oriented Design

a.

27. In the recursive solution to the Towers of Hanoi problem, the number of disks to move ______ at each recursive call. a) decreases by 1 b) increases by 1 c) decreases by half d) increases by half

a.

4. An ADT's ______ govern(s) what its operations are and what they do. a. specifications b. implementation c. documentation d. data structure

a.

6. When should an operation contract be written? a. during analysis b. after coding c. at the same time as user documentation d. when taking initial notes from client

a.

9. In the box trace for a recursive function, a new box is created each time ______. a) the function is called b) the function returns a value c) an object is created d) an object is initialized

a.

9. Which of the following operations of the ADT stack accepts a parameter? a. push b. isEmpty c. peek d. destroyStack

a.

10. According the CRC specifications for a Bag, which of the following behaviors would not be one of the responsibilities of the class Bag? a. See if the bag is empty b. See if the bag is full c. Look at all the objects in the bag d. Count the number of times a certain object occurs in the bag

b.

12. Which of the following is a precondition for a method that accepts a number n and computes the nth Fibonacci number? a) n is a negative integer b) n is a positive integer c) n is greater than 1 d) n is an even integer

b.

13. Which of the following is NOT true about converting infix expressions to postfix expressions? a. the operands always stay in the same order with respect to one another b. the operators always stay in the same order with respect to one another c. an operator will move only "to the right" with respect to the operands d. all parentheses are removed

b.

14. An ADT's operations are known as its ______. a. axioms b. methods c. variables d. interfaces

b.

19. An algorithm that uses a stack to implement a nonrecursive solution to the HPAir problem reaches the conclusion that there is no path from an origin city to a destination city only after ______. a. the algorithm has backtracked to the origin b. the algorithm has backtracked to the origin and there remain no unvisited cities to fly to from the origin c. the algorithm has reached a city and there remain no unvisited cities to fly to from that city d. the algorithm has reached the destination and there remain no unvisited cities to fly to from the destination

b.

2. Data structures are part of an ADT's ______. a. definition b. implementation c. specifications d. usage

b.

21. For an array containing 2, 3, 5, 6, 9, 13, 16, and 19, what value does a recursive binary search algorithm return when it searches for 6? a) 1 b) 3 c) 4 d) none of the above

b.

21. To ______ an exception means to deal with the error condition. a. declare b. catch c. implement d. try

b.

26. In the recursive solution to finding the kth smallest item in an array, the problem size decreases by ______ at each recursive call. a) 1 b) at least 1 c) half d) at least half

b.

27. Which of the following could not be a module? a. a standalone function b. a data member c. a class method d. a class itself

b.

28. A recursive solution that finds the factorial of n generates ______ recursive calls. a) n - 1 b) n c) n + 1 d) n * 2

b.

3. The item that is removed first from a stack is called the ______ of the stack. a. front b. top c. base d. prime

b.

30. Which of the following is a base case for a recursive binary search algorithm? (first is the index of the first item in the array, last is the index of the last item in the array, and mid is the midpoint of the array). a) last > first b) first > last c) 0 <= first d) last <= SIZE-1

b.

5. The base case for a recursive definition of the factorial of n is ______. a) factorial (-1) b) factorial (0) c) factorial (n) d) factorial (n - 1)

b.

6. The ______ operation of the ADT stack adds an item to the top of the stack. a. isEmpty b. push c. pop d. peek

b.

7. In the box trace, each box roughly corresponds to a(n) ______. a) recursive relation b) activation record c) base case d) pivot item

b.

8. What kind of interface contains a method if and only that method is essential to that class's responsibilities? a. complete b. minimal c. expanded d. compact

b.

23. For the method remove(anEntry) of the ADT Bag, what would be the output of the method? a. anEntry b. nothing c. true or false d. the previous position of anEntry in the bag

c

1. In a recursive solution, the ______ terminates the recursive processing. a) local environment b) pivot item c) base case d) recurrence relation

c.

10. Which of the following strings contains balanced braces? a. ab{cde{fg}hi{jkl} b. ab{cde{fghi}j}kl} c. {abc{de}{fg}hij}kl d. {ab{cde{fgh}ijkl}

c.

13. How many bases cases does a recursive binary search of a sorted array have? a) 0 b) 1 c) 2 d) 3

c.

14. The number of ways to choose k out of n things is ______. a) the number of ways to choose k - 1 out of n - 1 things b) the number of ways to choose k out of n - 1 things c) the sum of the number of ways to choose k - 1 out of n - 1 things and the number of ways to choose k out of n - 1 things d) the product of the number of ways to choose k - 1 out of n - 1 things and the number of ways to choose k out of n - 1 things

c.

15. Encapsulation combines an ADT's data with its operations to form a(n) ______. a. exception b. method c. object d. variable

c.

16. A recursive method that computes the number of groups of k out of n things has the precondition that ______. a) n is a positive number and k is a nonnegative number b) n is a nonnegative number and k is a positive number c) n and k are nonnegative numbers d) n and k are positive numbers

c.

17. A C++ class contains data members and ______. a. clients b. interfaces c. methods d. data structures

c.

17. In a graph that represents the flight map for the HPAir problem, if a flight exists from city C1 to city C2, the path from C1 to C2 is called a _______. a. relation b. neighborhood c. directed path d. connecting path

c.

17. The midpoint of a sorted array has the index ______, where first is the index of the first item in the array, and last is the index of the last item in the array. a) first / 2 + last / 2 b) first / 2 - last / 2 c) (first + last) / 2 d) (first - last) / 2

c.

20. Typically, ______ are used by a compiler to implement recursive methods. a. linked-lists b. arrays c. stacks d. queues

c.

20. What does the following recursive algorithm display? writeBack(in s:string) if (s is empty) return else { Write the first character of s writeBack(the string beginning at the second character of s) } a) nothing b) the first character of s a number of times equal to the length of s c) the string s d) the string s backward

c.

21. When a recursive call to a function occurs, the compiler's implementation must remember all of the following information EXCEPT ______. a. values of parameters b. values of local variables c. values of global variables d. a reference to the point from which the recursive call was made

c.

24. A recursive binary search algorithm always reduces the problem size by ______ at each recursive call. a) 1 b) 2 c) half d) one-third

c.

26. Objects collaborate when they a. are cohesive b. are used by a programming team c. send each other messages d. model a real life situation

c.

29. In the Fibonacci sequence, which of the following integers comes after the sequence 1, 1, 2, 3? a) 3 b) 4 c) 5 d) 6

c.

3. A(n) ______ allows two modules to communicate with each other. a. data structure b. axiom c. interface d. client

c.

5. What behavior does the ADT stack exhibit? a. first in, first out b. first in, never out c. last-in, first-out d. last in, last out

c.

5. When each module performs one well-defined task, we say that it is ___. a. loosely coupled b. highly coupled c. cohesive d. not easily reused

c.

6. What is fundamentally wrong with computing the Fibonacci sequence recursively? a) it has two base cases b) each call to the function results in two recursive calls c) it computes the same values over and over d) nothing

c.

7. The ______ operation of the ADT stack retrieves and then removes the top of the stack. a. isEmpty b. push c. pop d. peek

c.

8. In the box trace, each box contains all of the following EXCEPT ______. a) the values the function's arguments b) the function's local variables c) the function's execution time d) a placeholder for the value returned by each recursive call from the current box e) the value returned by the function itself

c.

12. What should a programmer do before implementing a recently designed class? a. write code that uses the class b. check comments that document specifications c. adjust the design when problems are discovered d. all of these

d

10. What happens if a recursive function never reaches a base case? a) the function returns the correct value b) the function returns an incorrect value c) the function terminates immediately d) an infinite sequence of recursive calls occurs

d.

11. A client program depends solely on the ______ of the ADT. a. data members b. structure c. implementation d. behavior

d.

12. Given the language L, where: L = {w$w' : w is a possibly empty string of characters other than $, w' = reverse(w) } which of the following strings is NOT in L? a. XY$YX b. Z$Z c. $ d. XYZ$ZXY

d.

13. Object-oriented programming views a program as ______. a. a sequence of actions b. a collection of classes c. a group of methods d. an interaction among objects

d.

15. What is the value of the following postfix expression: 5 2 - 8 4 + *? a. -9 b. 28 c. 35 d. 36

d.

18. A(n) ______ is an instance of a class. a. method b. data field c. interface d. object

d.

18. If the value sought by a recursive binary search algorithm is in the array, which of the following is true? a) the algorithm makes the same comparisons as a sequential search b) the algorithm is successful without reaching a base case c) the algorithm searches the entire array d) the algorithm searches only the array half containing the value

d.

18. ______ are considered when choosing the next city to visit in a stack-based nonrecursive solution to the HPAir problem. a. All cities b. All unvisited cities adjacent to the destination city c. All cities adjacent to the city on the top of the stack d. All unvisited cities adjacent to the city on the top of the stack

d.

19. A(n) ______ is a class that inherits the members of another class. a. base class b. superclass c. abstract class d. subclass

d.

2. If the array 6, 2, 7, 13, 5, 4 is added to a stack, in the order given, which number will be the first number to be removed from the stack? a. 6 b. 2 c. 5 d. 4

d.

22. Which of the following are ways to address unusual situations? a. simply assume the invalid situation will never occur b. guess at the client's intention c. return a value that signals a problem d. all of the above are options

d.

3. A ______ is a mathematical formula that generates the terms in a sequence from previous terms. a) local environment b) pivot item c) base case d) recurrence relation

d.

4. If the array 6, 21, 35, 3, 6, 2, 13 is added to a stack, in the order given, which of the following is the top of the stack? a. 2 b. 6 c. 3 d. 13 e. 35

d.

4. The factorial of n is equal to ______. a) n - 1 b) n - factorial (n-1) c) factorial (n-1) d) n * factorial (n-1)

d.

7. What information is included in the operation contract? a. the method's interface b. data flow among the modules c. assumptions about input d. all of these

d.

8. The ______ operation of the ADT stack retrieves the top of the stack, but does not change the stack. a. isEmpty b. push c. pop d. peek

d.

9. What must be known about the ADT Bag in order to use it in a program? a. how entries in the bag are represented b. how bag operations are implemented c. how many entries can be stored in the bag d. the interface of the bag

d.


Set pelajaran terkait

S4 N243 PrepU - Ch. 62: Management of Patients with Burn Injury

View Set

Chp. 1- Demographic & Health Characteristics of Older Adults

View Set

Emergency Care: Seizures and Strokes

View Set

Reach for the Stars: Revenge of the Event

View Set

Chapter 3 Study Guide: Ethics in Social Research

View Set

Solutions: Quiz 1 Chemistry preap

View Set