lOMoARcPSD|53294742
202320 Final exam CS 210-040
Data Structures and Abstractions (University of Regina)
Scan to open on Studocu
Studocu is not sponsored or endorsed by any college or university
Downloaded by Yes Me (
[email protected])
lOMoARcPSD|53294742
Department of Computer Science, University of Regina,
CS 210 – 040 Final examination, Spring/Summer 2023,
June 26, 2023 from 9:00 am to 12:00 pm,
Duration: 3 hours, Location: CL 110,
Total marks: 130, Instructor: Dr. Sultan Ahmed
Student First Name:
Student Last Name:
Student ID:
Student Signature:
Notes:
1. This is a closed book examination. You are allowed to use a calculator. You are
not allowed to use any materials that have not been approved by instructor.
2. Write your Name and Student ID, and sign this first page. Write your Student ID
on each of the other pages in the top-left corner.
3. You are expected to comply with the policies regarding academic integrity,
which are outlined in the University of Regina Undergraduate calendar. You must
maintain the confidentiality of your examination; do not provide any opportunity
for others to copy any of your work.
4. You should answer each question in the space provided.
5. You must submit this examination booklet and sign the attendance sheet.
6. There are total 13 questions. Each question has 10 marks. Total mark is 130.
lOMoARcPSD|53294742
Student ID: CS 210 Final exam
1. You are given an Unsorted Linked List of only lower-case letters, where Ptr points the first node of the
list. Write an algorithm FindLength(Temp) that returns the number of elements in the list. Temp is a
pointer that initially points the first element of the list.
Page 2 of 14
lOMoARcPSD|53294742
Student ID: CS 210 Final exam
2. Draw the Binary Search Tree whose elements are inserted in the following order: 50, 72, 96, 94, 107,
26, 12, 11, 9, 2, 10, 25, 51, 16, 17, 95
Page 3 of 14
lOMoARcPSD|53294742
Student ID: CS 210 Final exam
3. You are given a Sorted Linked List of integer values (consider ascending order), where Ptr points the
first node of the list. You can consider that each node consists of an integer value (Item) and a pointer to
the next node (Next). Write an algorithm FindItem(Temp,ItemToFind) that returns the pointer of the
element ItemToFind in the Linked List. If the element ItemToFind does not exist in the Linked List, the
algorithm should return NULL. Temp is a pointer that initially points the first element of the list. Obtain
the best case and the worst case time complexities of algorithm FindItem.
Page 4 of 14
lOMoARcPSD|53294742
Student ID: CS 210 Final exam
4. Implement the EnQueue(NewItem) operation for the queue below that inserts NewItem in the queue.
Int Items[50];
Int Front;
Int Rear;
Int MAX_ITEMS;
Assume that a new item is always inserted in the Rear side and an item is always deleted from the Front
side. When the queue is empty, both Front and Rear are -1.
You need to show appropriate overflow or underflow. Consider that the operations IsFull() and IsEmpty()
already exist.
Page 5 of 14
lOMoARcPSD|53294742
Student ID: CS 210 Final exam
5. Write a function Print(Temp) that prints the elements of a circular linked list in order. The parameter
Temp points the first element of the list. For instance, for the circular linked list X Y Z where the first
element X is pointed by Temp, calling Print(Temp) should print X Y Z. You may assume that the list is not
empty and each node is of CirListNode type.
Page 6 of 14
lOMoARcPSD|53294742
Student ID: CS 210 Final exam
6. Write a recursive function, FindMaximum(Temp), that returns the maximum value of a linked list, where
the first node is pointed by Temp. Assume that there exists at least one element in the list.
Page 7 of 14
lOMoARcPSD|53294742
Student ID: CS 210 Final exam
7. Use the following elements to construct a 5-way B-tree: 3, 7, 9, 23, 45, 1, 5, 14, 25, 24, 13, 11, 8, 19, 4,
31, 35, 56.
Page 8 of 14
lOMoARcPSD|53294742
Student ID: CS 210 Final exam
8. Consider the Towers of Hanoi problem. Write a recursive function, TOH(n,A,B,C), where A, B, and C are
pegs. Pegs can contain stacks. A stack can never be on another stack where the latter is smaller than the
former. The peg A contains n number of stacks. The function should determine the sequence of
movement of stacks from one peg to another peg so that all stacks on A are moved to peg C by considering
peg B as an auxiliary peg.
Page 9 of 14
lOMoARcPSD|53294742
Student ID: CS 210 Final exam
9. A binary tree can be implemented using an array with the array index properties. You are given an
array-implemented tree as follows.
Element 10 6 8 5 2 6 1
Index 0 1 2 3 4 5 6 7 8 9
(a) Is this tree a max-heap? If not, make the necessary changes to make it a max-heap.
(b) In the heap, insert a new integer 26 and draw the reconstructed array.
(c) From the most updated heap, delete an element 10, if exists, and draw the reconstructed array.
Page 10 of 14
lOMoARcPSD|53294742
Student ID: CS 210 Final exam
10. Given a pointer implementation of a Binary Search Tree (BST) where the root node is pointed by the
Root pointer, write an algorithm, called InsertNewItem(Root, NewItem), that inserts NewItem in the BST,
if NewItem already does not exist in the BST. If the item already exists, then return and do not insert. You
do not need to check for overflow or underflow.
Page 11 of 14
lOMoARcPSD|53294742
Student ID: CS 210 Final exam
11. Given the elements in the following, draw the AVL-tree: 3, 2, 1, 4, 5, 6, 7, 16, 15, 14.
Page 12 of 14
lOMoARcPSD|53294742
Student ID: CS 210 Final exam
12. Consider that Items[] is an array of N integers. Write the Bubble Sort algorithm that will sort the
array elements in ascending order. Determine the worst case and the best case time complexities of the
Bubble Sort algorithm.
Page 13 of 14
lOMoARcPSD|53294742
Student ID: CS 210 Final exam
13. Apply the principle of Heap Sort to sort the following integers in ascending order: 45, 27, 19, 89, 55,
83, 2, 90, 17, 23, 18. You need to show all the steps.
Page 14 of 14