B.Sc. Special Honou S Degr Information Tech Ology: Sri Lanka Institute of Inform
B.Sc. Special Honou S Degr Information Tech Ology: Sri Lanka Institute of Inform
•• I~ ••
•• l"!"'JI ••
••••••
anr
~••,.r,
••••••
Information Technology
Repeat Examination
Year 1, Semester 2 (2016)
ITI02-Software Technology-l
I Duration: 2 Hours I
Instructions to Candidates:
• This paper has FOUR questions. Answer All Questions.
• Total Marks 100.
• This paper contains 8 pages with the cover pag .
• This paper is preceded by a 10-minute reading eriod. The
supervisor will indicate when answering may c mmence.
21/11/2016
00045
a) Consider the following Stack and draw the Stack frames after executi g each statement given
below. (6 marks)
50 ~ __ Top
.) theStack.push(2);
ii) theStack.push(a);
v) theStack.push(b);
b) You are given following Circular Queue. Draw the FINAL queue frame after performing the
Front Rear
i) dequeuei);
iii) enqueue('j');
iv) enqueue('k');
Page 1 of 7
21/11/2016
00045
7 +-- top
8
-3
14
5
What is the output of the following code on the stack above? (4 marks)
int x;
while (!myStack.isEmpty())
{
x= myStack.pop();
if (x>O)
cout«x«" ";
d) Consider the following Windows Form designed in Visual Studio .Ne, 2010.
EVEN~
r---
- '-- __
~J
OOOCD.rt
C?<XI ,
I
You are required to store the following numbers in a stack. Retrieve tl e values from the stack
and display the EVEN numbers and ODD numbers in the list ox-l, an listBox2 respectively.
At the same time display the total count of even and odd numbers in th textBox 1 and textBox2
when button! is clicked.
3 6 5 8 3 2 11
Page 2 of 7
21/11/2016
00045
A
private: System: :Void buttonl_Click(System::Object sender,
System::EventArgs A
e)
I //Coding
}l
Question 2 (25 marks)
f
a)
i) Write the time complexities of the following algorithms in Big 0 notation. (2 marks)
1) Linerar search
2) Binary search
ii) Explain a situation where Linear search is more efficient than Bin' ry search and vice
versa. (2 marks)
b)
i) Selection sort can be used to find the kth smallest element in a date set. Illustrate how the
kth element could be found using an example. (3 marks)
iii) Determine the time complexity of the above algorithm in Big 0 otation for the
following situations (Assume that there are only n number of ele ents in the array)
(4 marks)
1) When k = 1
2) When k = n
Page 3 of 7
21/11/2016
00045
iv) "Selection sort is faster than the bubble sort". Do you agree with this statement? Justify
your answer. (2 marks)
c)
i) Give advantages and disadvantages of merge sort algorithm. (2 marks)
ii) Sort the following name list in the alphabetical order using Merg Sort.
d) Write the code segment to change the linked list in Diagram A to Diagram B. (5 marks)
PI P2
i) A First J J
L.I a 0---+ 1 f 11---+1 b
D~
PI P2
B First J J
L.I a 0---+ 1 b IJ ---+1 f
1
I~
PI
Page 4 of 7
21/11/2016
00045
ii) A First J
L.I 0-. IJ-'I
25
1
75
PI
85
o~
B First J
L.I 0-.1 0-'1 0-'1
I
25 55 75 85
o~
~
e) Consider the following Linked List. If you apply" deleteFirst" metho to delete all the Links
in the Linked List, what would be the order in which the data in the Li ked List be deleted.
(2 marks)
First
L.1~mO~I_pO-'I_k 0-'1---,1 o~
f) Consider the linked list given below and illustrate the resultant linked I st after executing each
of the following operations
(10 marks)
First
L.I 120 I 1-. 1 156 0 -.1_ ----'I0
178
S
i) insertFirst (110) ;
iii) deleteFirst( ) ;
iv) deleteNode(156) ;
v) find(l78);
Page 5 of 7
21/11/2016
00045
double do'ata
Link *first LinkList *StackList
Link *next
.
LinkList () Stack ()
Link Vlouble d}
void displayLink(} void insertFirst(double d} void push ( ouble d)
t double peek(}
ii) Perform the below operations to the tree created in section b) and draw the final tree
structure (3 marks)
1) Remove('D');
2) Insert('B');
3) Insert('A');
c) Mention three scenarios you need to consider when deleting a node fr m a tree. (3 marks)
Page 6 of 7
21/11/2016
00045
d) Consider the insert method of a tree class given below. Complete the m thod. (6 marks)
if ( )
e l-s e if ( )
/ cur->leftChild=insertRec(id, dd, cur->leftChild);
~
else if ( )
cur->rightChild=insertRec(id, dd, cur->rightChild);
return cur;
e) A student has written the below inorder method in a tree class to displ y the values in sorted
order.
void Tree: :inOrder(Node* localRoot)
if (localRoot ,= NULL)
inOrder(localRoot->leftChild);
inOrder(localRoot->rightChild);
i) What is the result you get if the above method is executed on th tree created in b) i)?
(3 marks)
ii) Does the above method display the values according to "inorder" sequence? lf not
modify the method. (4 marks)
Page 7 of 7
21/11/2016