Litrraryr: Technology
Litrraryr: Technology
Litrraryr: Technology
Litrraryr
FacultY of TechnologY l''i
Rajarata UniversitY of Sri Lanka
Mihinthate
l. a. What are the factors that you should consider when selecting a data structu.re for an
algorithm? (04 marks)
b. Explain, using examples, how a selected data structure increases or decreases the
effrciency of an algorithm. (04 marks)
c. Explain the term abstract data types using a.n example. (03 marks)
d. Suppose you need to read a given text and count the frequency ofoccurrences ofeach
word appeared in the text. Suggest a suitable structure to store the list of wotds along
with their frequencies. Explain its usage. (04 marks)
[Total15 marks]
2. a. Compare and contrast array based lists and dynarnie lists. (0d marks)
b. Suppose that a programmer has designed a dynamic list that only allows adding
elements before the head element. Assume that a node of the list contains two
integers, n1 and n2, and nl is considered as the key.
i. Write a function that removes the highest key element and inserts it into another
list. (06 marks)
ii. Write a recursive function to print the contents of the'list in reverse order.
(04 marks)
c. Suppose that p and q arc two consecutive elements of an array-based list. Write a few
lines of pseudo code to insert a new element betweenp and q if the length ofthe array
is n and the array is not full. (04 marks)
d. Suppose that p is a middle node of a doubly linked Iist. Write a few lines of pseudo/C
code to delete the node p. (04 marks)
[Total20 marks]
Page 1 of 3
, '-. 0&
a. Briefly discuss haw queue and stack data structures are used in computer Operating
Systems to perform various operations. (04 marks)
b. A programmer needsto read a set of student records and keep them in a queue until
they are processed. A student record consists of index number and marks for five
subjects. A processed record only contaims the index number and the total marks of
five subjects. Once a record is processed it is pushed to a stack'
Write a few lines of C codes / C function for the followings:
i. Implement required node structures of the queue and stack of the above scenario.
(05 marks)
ii. Implement a frrnction to process a node of the queue and to return a stacknode.
(06 marks)
c. If the programmer needs to print the set of processed records in descending order of
their total marks, suggest a suitable method. (05 marks)
[Total20 marks]
b. A Priarity Queue can be implemented using a heap. Explain how to use heap property
to implement a priority queue. (02 marks)
Explain how the highest priority element is removed from an away-based heap.
(04 marks)
e, Explain the terms in-place sorting and stable sorting. (04 marks)
f. Illustrate how to sort the given list of integers fls, 12, 4, 20, 18,2, L0,5] using merge
sorl algorithm. (04 marks)
[Total22 marks]
5. a. Explain how binary search /ree,s (BST) differ from trees. (02 marks)
b. If a BST node contains two fields, height and integer key,wfite a C-code to implement
the structure ofthe BST node. (03 marks)
Page 2 of 3
0$
Apply the following algorithm to the given tree and write the expected output. Show
thi contents of the queue, Q, at each iteration. Assume that enqueue and dequeue
functions are available' (08 marks)
FronL=dequeue {Q)
f. Illustrate how to inset the list [15, 12, 4,2A, 18, 2, 10, 5,71into an AW free. Show
each step clearly. (05 marks)
[Total23 marks]
- End --
Page 3 of 3