0% found this document useful (0 votes)
10 views8 pages

B.Sc. Special Honou S Degr Information Tech Ology: Sri Lanka Institute of Inform

Uploaded by

dil shan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views8 pages

B.Sc. Special Honou S Degr Information Tech Ology: Sri Lanka Institute of Inform

Uploaded by

dil shan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

00045

•• I~ ••
•• l"!"'JI ••
••••••
anr
~••,.r,
••••••

Sri Lanka Institute of Information Tee ology

B.Sc. Special Honours Degree


In

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

Question 01 (25 marks)

a) Consider the following Stack and draw the Stack frames after executi g each statement given

below. (6 marks)

int a = 22, b = 44;

50 ~ __ Top
.) theStack.push(2);

ii) theStack.push(a);

iii) theStack.push(a + b);


t
iv) theStack.popf);

v) theStack.push(b);

vi) theStack.push(a - b);

b) You are given following Circular Queue. Draw the FINAL queue frame after performing the

following methods in the queue. (4 marks)

Front Rear

i) dequeuei);

ii) enqueue(' i');

iii) enqueue('j');

iv) enqueue('k');

Page 1 of 7

21/11/2016
00045

c) A stack called myStack has the following stack frame

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.

.J9'F<m,l .~~~.~ (5 marks)

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

Consider that a StackX class already implemented to store a set of integers.


(Hint: You may use listBoxl->Items->AddO and
textBoxl-> Text=System: :Convert: :ToStringO )

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)

ii) ,Implement a function kthSmallestElement() to find the kth smallest element in an


integer array using selection sort algorithm. (4 marks)

int kthSmallestElement(int arr[ ],int k, int size)

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.

Nimalka Anil Kamal Nimali Mala Pubudi Sarath


Show-all steps in the order the recursive algorithm would actually sort the data. (5 marks)
}
~

Qu StiOD 03 (25 marks)

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) ;

ii) insertBefore ( 178, 165) ;


(hint: first parameter - existing value; second parameter - new value. This method will
create a ne~ link and insert it before the existing value)

iii) deleteFirst( ) ;

iv) deleteNode(156) ;

v) find(l78);

Page 5 of 7

21/11/2016
00045

g) Consider the following classes.

Link '. LinkList Stack

double do'ata
Link *first LinkList *StackList
Link *next
.
LinkList () Stack ()
Link Vlouble d}
void displayLink(} void insertFirst(double d} void push ( ouble d)

double deleteFirst(} double po ()

t double peek(}

i) Write the pusht) method of the Stack class (2 marks)


ii) Write the popt) method of the Stack class (3 marks)
iii) Write the peekt) method of the Stack class (3 marks)

Question 4 (25 marks)

a) What is meant by a binary search tree? (2 marks)

b) i) Insert the below values in a binary search tree. (4 marks)


P DCRMFQT

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)

Node* Tree: :insertRec(int id, double dd, Node* cur)

if ( )

Node* theNode = new node(id, dd);


return theNode;

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)

End of Question paper

Page 7 of 7

21/11/2016

You might also like