CS301- Data Structures
SOLVED MCQS & SUBJECTIVE FROM MIDTERM PAPERS
December 2014
Virtual University of Pakistan
Bhakkar Campus (PBHK01) Pioneer College of Commerce Bhakkar
(1) Here is the start of a class declaration: class Foo
{
public:
void x(Foo f);
void y(const Foo f); void z(Foo f) const;
...
Which of the three member functions can change the PRIVATE member variables ofthe Foo object that activates the function?
a. Onlyx and y b. Only x and z c. Onlyy and z
d. Noneof three the functions.
e. All three functions.
(2) What is the common pattern of writing class definitions?
a. Member functions and member variables are both private.
b. Member functions are private, and member variables arepublic.
c. Member functions are public, and member variables are private.
d. Member functions and member variables are both public.
(3) The Bag ADT is likethe List ADT. The Bag ADT does not store items in any particular
order and it allows duplicates. Suppose thatthe Bag class is efficiently implemented with a fixed array with a capacity of 4000. Insert appends the new item at the end of the array. Choose the best description of b’s member variables size (count of items in the bag) and data (the array that holds the actual items) after we execute these statements:
Bag b;
b. insert (5); b. insert (4); b.insert(6);
What will be the values ofb.size and b.data after the statements?
a. b.size is 3, b.data[0] is 4, b.data[1]is 5, b.data[2] is 6
b. b.size is 3, b.data[0] is 5, b.data[1] is 4, b.data[2] is 6
c. b.size is 3, b.data[0] is 6, b.data[1] is 4, b.data[2] is 5 d. b.size is 3, b.data[0] is 6, b.data[1] is 5, b.data[2] is 4
(4) Consider the following pseudo code:
declare a stack of characters
while ( there are more characters in theword to read ) {
read a character
push the character on the stack
}
while ( the stack is not empty ) { pop a character off the stack write the character to the screen
}
What is written to the screen for the input “carpets”?
a. serc
b. carpets
c. steprac
d. ccaarrppeettss
(5) In thelinked list implementation of the stack class, where does the push member function place the new entry on thelinked list?
a. At the head
b. At the tail
c. After all other entries that are greater than the new entry. d. After all other entries that are smaller than the new entry.
(6) One difference between a queue and a stack is:
a. Queues require dynamic memory, but stacks do not. b. Stacks require dynamic memory, but queues do not.
c. Queues use two ends of the structure; stacks use only one.
d. Stacks usetwo ends of the structure, queues use only one.
I have implemented the queue with a linked list, keeping track of a front pointer and a rear pointer. Which of these pointers will change during an insertion into a NONEMPTY queue?
a. Neither changes
b. Only front pointer changes. c. Only rearpointer changes. d. Both change.
I have implemented the queue with a linked list, keeping trackof a front pointer and a rear pointer. Which of these pointers will change during an insertion into an EMPTY queue?
a. Neither changes
b. Only front pointer changes. c. Only rear pointer changes. Both change.