Answers AlgoSamplePaper
Answers AlgoSamplePaper
Answers AlgoSamplePaper
1 Group B
Part A: Multiple Choice Questions. Select the appropriate answer. Answer sheet is
attached at the end of the MCQ question set. (50 mark)
3. You have to sort a list L consisting of a sorted list followed by a few “random”
elements. Which of the following sorting methods would be especially suitable for
such a task?
4. Let the following circular queue can accommodate maximum six elements with the
following data
front = 2 rear = 4
queue = _______; L, M, N, ___, ___
What will happen after ADD O operation takes place?
a. Stack b. Queue
c. list d. Linked List
e. Linear Queue
8. Each node in a linked list has two pairs of .............. and ...................
a. Link field and information field b. Link field and Next field
c. Data field and information field d. Address field and link field
e. None of the above
10. In a queue, the initial values of front pointer f rare pointer r should be …….. and
……….. respectively.
a. 0 and 1 b. 1 and 0
c. 0 and -1 d. -1 and 0
e. None of the above
01 a b c d e
02 a b c d e
03 a b c d e
04 a b c d e
05 a b c d e
06 a b c d e
07 a b c d e
08 a b c d e
09 a b c d e
10 a b c d e
a. Why Stacks are called “LIFO” structures and Queues are called “FIFO”
structures. Explain the complexities in terms of Big O notations. If required, make
a graphical representation.
a. "LIFO" stands for last-in, first-out, meaning that the most recently item
out first.A stack is a container of objects that are inserted and removed
according to the last-in first-out (LIFO) principle
.
b. "FIFO" stands for first-in, first-out, meaning that the first inserted object
out first. A Queue is a FIFO (First In First Out) data structure where the
element that is added first will be deleted first.
(6 mark)
b. Briefly explain the concept of “Linked List” data structure.
a. A linked list is a linear data structure where each element is a separate
object. Each element of a list is divided into two items - the data and a
reference to the next node. The last node has a reference to null.The entry
point into a linked list is called the head of the list.
(4 mark)
c. Suppose an initially empty queue Q has performed a total of 32 enqueue
operations, 10 front operations and 15 dequeue operations. What would be the
current size of the queue? (No of elements in the current queue)
i. 17
(2 mark)
d. Derive the push/pop function and enqueue/dequeue operations
QUEQE
STACK
(8 mark)
2.
a. Using an appropriate array example, explain how main searching algorithms can
be performed.
(8 mark)
b. Briefly explain where you may apply above searching algorithms and describe
their complexities in terms of big O notation.
-------------------------------I think that Big O will not come-----------------------------
(6 mark)
c. Consider the following code block identify the problems with the code and resolve
the problems. (6 mark)
int binarySearch(int array[], int size, int value)
{
int first = 0, last*,middle, position*;
boolean found = false;
while (*found && first <= last)
{
middle = (first + last) / 2;
if (array[middle] == value)
{
found = true;
position = middle;
}
else if (array[middle] > value)
last = middle +1;
else
first = middle -1;
}
return position;
}
CORRECTIONS
1. last = size -1
2. position = -1
3. !found
4. array[middle] == value
5. last = middle – 1;
6. first = middle +1;
7. position = middle;
3.
a. The insertion sort runs in linear time on an array already sorted. How does it
perform it on an array that is sorted in reverse order? Hint: Consider only on
performance no coding required.
a. Insertion sort takes maximum time to sort if elements are sorted in reverse
order. And it takes minimum time (Order of n) when elements are already
sorted. Also known as the worst case scenario
(2 mark)
4.
a. Draw a tree of your own and identify the followings. (4 mark)
I. Root
II. Siblings
III. Edge
IV. Leaf Node
c. For the above developed graph derive the below traversing output. (6
mark)
In order, Pre order and Post order output.
d. Describe a situation where you can apply binary tree concept.
a. Arithmetic Expression
b. Decision processes
c. Searching
e. (4 mark)