Fall 24
Fall 24
1. (a) Consider the following function ”FuncA”. Find the time Complexity of the function using
asymptotic notation. [4]
2. (a) How many element comparisons are needed for the following instance of the Descending
Order Quick Sort to find the first and second partitioning elements? [3]
16 23 19 28 7 11 19 12 21
(b) You are given an array A = { 5, 2, -2, -2, 4, -3, -5, 4, 5, 3, -1, 2 }. Each element in the
array ranges from -5 to 5. Sort the array using the Counting Sort algorithm, and clearly
illustrate the intermediate steps of the cumulative sum array [3]
3. (a) Consider a memory system with row-wise memory allocation, a double array X[128][64]
where each double is 8 bytes. let X[20][10] = m + 50000 where m is the last 2 digits of your
1
student id.[Example; if student id = 0112410261 ,then m = 61] Calculate the memory
address of beginning of the array and X[22][15]. [4]
(b) If the system was column-wise will there be any changes to the result. Show your
reasoning. [2]
Show the effect of executing the following function. Assume that each of the nodes has two
fields; data and next, where data is of integer type and next will contain the address of the
next node.
5. Suppose you are designing a text editor, where you want to implement the features given
below. [3]
Which data structure(s) will you prefer to implement these two features? Briefly explain.
Page 2
6. (a) Consider there is a Stack ”A” that is implemented using ”Singly Linked List”. The
Linked List stores data in node. Now, write pseudocode for ”Push” which adds a node and
”Pop” which removes the last inserted node and removes it from the ”Linked list”. [3]
(b) Consider the following Linked list bellow. If we want to implement a ”Queue” using this
Linked list, Where should ”enqueue” operation add a new node. Justify your answer. [2]
Figure 1: Question: 6
Page 3