Data Structure and Algorithm Analysis
Questions 241 to 250
Standard queue operations are
(a) empty(), fill(), place(), remove() (b) enque(), dequeue(), isempty(), isfull()
(c) init(), delete(), add() (d) isempty(), isfull(), fill(), remove()
(e) isempty(), isfull(), init(), delete(),
add().
|
|
Assume that variable A is a sorted array of integers of
length L. Consider the following code segment:
int k=1, flag=0;
for (
; k<L; k++ )
{
if (A[k-l] == A[k] ) flag = 1;
}
Which of the following best describes
when variable flag is 1 after this code segment executes?
(a) Always
(b) Never
(c) If and only if array A really is sorted
(d) If and only if array A contains adjacent
duplicate values
(e) If and only if all values in array A are
the same.
|
|
Consider using binary search to look for a given value in
an array of integers. Which of the following must be true in order for the search to work?
I.
The values in the array are stored
in sorted order.
II.
The array does not contain any
duplicate values.
Ill.
The array does not contain any
negative values.
(a) Only (I) above (b) Only (II) above (c) Both (I) and (II)
above
(d) Both (I) and
(III) above (e) Both (II) and (III) above.
|
|
A program is required to store and process information
about the solar system. Which types of data structure would be most
appropriate for storing the following respectively : (i) A list of the names
of the planets, (ii) full details of a planet including distance from sun,
diameter, atmospheric composition, etc, (iii) a predetermined list of
scientific observations made of the planet.
(a) (i) linked list (ii) structure (iii) linked list
(b) (i) array (ii) structure
(iii) linked list
(c) (i) linked list (ii) array (iii) array
(d) (i) linked list (ii) linked list
(iii) linked list
(e) (i) array (ii) structure
(iii) array.
|
|
If data is a circular array of CAPACITY elements, and R is
an rear index into that array, what is the formula for the index after R?
(a) (R + 1) % CAPACITY (b)
R % (1 + CAPACITY)
(c) (R % 1) + CAPACITY (d) R
+ (1 % CAPACITY) (e) R = R + 1.
|
|
In the linked list implementation of the queue, where does
the insert method place the new entry on the linked 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
(e) This operation is not possible.
|
|
One difference between a queue and a stack is:
(a)
Queues require linked lists, but
stacks do not
(b)
Stacks require linked lists, but
queues do not
(c)
Queue is used for complex programs and
stack is used for simple programs
(d)
Stacks use two ends of the structure,
queues use only one
(e) Queues
use two ends of the structure; stacks use only one.
|
|
Suppose cursor refers to a node in a linked list. What
boolean expression will be true when cursor refers to the tail node of the
list?
(a) cursor.next == null (b) cursor
== null (c) cursor.data
== null
(d) cursor.data == 0 (e) cursor.next == cursor.
|
|
Five statements about lists and stacks are below. Four of
them are correct. Which one is incorrect?
(a) Lists can be implemented by using arrays or
linked lists
(b) Lists are the dynamic data structures
(c) A stack is a special kind of list in which
all insertions and deletions take place at one end
(d) A list is a sequence of one or more data
items
(e) Stacks are easier to implement than lists.
|
|
For questions 10-11, refer to the following:
Queue
q;
int
i=1;
const int value = 10; for ( ; i < value; i++) insert(i, q); printf(“%d”, frontofqueue(q) ) ;
delete(q);
delete(q);
printf(“%d”,
frontofqueue(q) ) ;
while
(! isempty(q))
delete(q);
What is the
output for the above code?
(a) 1, 3 (b) 1, 4 (c) No output (d) 9, 6 (e) 9, 7.
|
Answers
Answer : (b)
Reason: As fill( ), place( ), add( ),empty( )are not the
standard operations on queue, while enque ( ), dequeue( ), isempty( ),
isfull( ) are the standard one.
|
|
Answer : (d)
Reason: Because this
is an array, and k is the index. So k, k-1 are the adjacent index values.
|
|
Answer : (c)
Reason: Because the
precondition for binary search is, the array must be there in sorted order,
should not contain duplicate values and may have positive or negative values.
|
|
Answer : (e)
Reason: To keep
track of the planets a fixed size array is enough as the number of plants is
finite value. In addition, to keep track of complex information as a single
logical unit structure is the best suitable data structure. For predetermined
list array is suitable.
|
|
Answer : (a)
Reason: As the
circular queue is given, if the empty places are there at any place and rear
pointer R is a rear index, then this is the best ever formula to increment R.
All other are not valid or appropriate one.
|
|
Answer : (b)
Reason: Because,
in queue always the new entries are
inserted at the end of queue, no matter the queue is implemented as array or
linked list.
|
|
Answer : (e)
Reason: As all the
other options are meaning less.
|
|
Answer : (a)
Reason: As the
‘next’ field of the node is holding NULL address, means it is the last node .
|
|
Answer : (d)
Reason: As in lists
only one data item of some type can only be stored. More data items can’t be
stored in a list.
|
|
Answer : (a)
Reason: As using
insert we are inserting the elements in queue are 1, 2, 3, 4, 5, 6, 7, 8, 9.
Then using printf statement we are displaying the first element, then we are
deleting the front element twice (i.e. 1, 2) then again we are displaying
front element.
|
No comments :
Post a Comment