Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The bag class in Chapter 5 has a new grab member function that returns a randomly selected item from a bag (using a pseudorandom number
- The bag class in Chapter 5 has a new grab member function that returns a randomly selected item from a bag (using a pseudorandom number generator). Suppose that you create a bag, insert the numbers 1, 2, and 3, and then use the grab function to select an item. Which of these situations is most likely to occur if you run your program 300 times (from the beginning):
- A. Each of the three numbers will be selected about 100 times.
- B. One of the numbers will be selected about 200 times; another number will be selected about 66 times; the remaining number will be selected the rest of the time.
- C. One of the numbers will be selected 300 times; the other two won't be selected at all.
- What is the expression for generating a pseudorandom number in the range 1...N?
- A. rand() % N;
- B. rand() / N;
- C. rand() % (N + 1);
- D. rand() / (N + 1);
- E. (rand() % N) + 1;
- Which expression computes a pseudorandom integer between -10 and 10 using rand() from stdlib.h?
- A. (rand( ) % 20) - 10
- B. (rand( ) % 21) - 10
- C. (rand( ) % 22) - 10
- D. (rand( ) % 20) - 11
- E. (rand( ) % 21) - 11
Multiple Choice Section 5.4 The List ADT with a Linked List - For the linked-list version of the sequence ADT, which operations are constant time operations in the worst case?
- A. attach is constant time, but not insert
- B. insert is constant time, but not attach
- C. Both attach and insert are constant time
- D. Neither attach nor insert are constant time
- Suppose that the sequence is implemented with a linked list. Which of these operations are likely to have a constant worst-case time?
- A. insert
- B. size
- C. remove_current
- D. None of (A), (B), and (C) have a constant worst-case time
- E. TWO of (A), (B), and (C) have a constant worst-case time
- F. ALL of (A), (B), and (C) have a constant worst-case time
- What is the output of these statements, using your sequence ADT implemented as a linked list with Item defined as integer:
sequence x; sequence y; x.insert(41); // Inserts 41 into the sequence x x.insert(42); // Inserts 42, so that x is now 42, 41 with cursor at front y = x; x.attach(43); // Attaches 43 so that x is now 42, 43, 41 with cursor at 43 y.advance( ); cout << "y size is " << y.size( ); cout << " and y current item is " << y.current( ) << endl;
- A. y size is 2 and y current item is 41.
- B. y size is 2 and y current item is 43.
- C. y size is 3 and y current item is 41.
- D. y size is 3 and y current item is 43.
- E. None of the above.
- Suppose that you forgot to override the assignment operator in your sequence ADT implemented as a linked list. What is the most likely output from the previous question?
- A. y size is 2 and y current item is 41.
- B. y size is 2 and y current item is 43.
- C. y size is 3 and y current item is 41.
- D. y size is 3 and y current item is 43.
- E. None of the above.
Multiple Choice Section 5.5 Dynamic Arrays vs. Linked Lists vs. Doubly Linked Lists - What kind of list is best to answer questions such as "What is the item at position n?"
- A. Lists implemented with an array.
- B. Doubly-linked lists.
- C. Singly-linked lists.
- D. Doubly-linked or singly-linked lists are equally best
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started