Professional Documents
Culture Documents
General Instructions:
Attempt all questions on Question Paper.
c. Swap head and the node M (you may not swap data).
Task Answer
int count = 0;
for (int i = 0; i < N; i++){
for (int j = i+1; j <= N; j=j*2){
for (int k = N-1; k < 1; k=k/2){
count++;
}
}
}
b) Application regarding shopkeeper and customer. After every 10 seconds a new customer will
come & add himself in a stack. The shopkeeper serves the customer once every 15 seconds
using the LIFO fashion. Identify issues and give solution. (1 marks)
c) When I used some code on an array of 2500 integers on my slow old computer at home, it
took 5.0 seconds (I tried it several times--5.0 seconds every time). Approximately how long
will this code take to run if N is 10000 (assuming I use the same computer)? Justify your
answer. Big-O for the code is O (1). (1 marks)
Student ID #: ____________________
d) List the following functions by increasing asymptotic growth rate. If two functions have
the same asymptotic growth rate, state that fact. No justification is needed. (1.5 marks)
In these problem you do not need to write annotations, but you are free to do so if you wish.
You may assume that all function arguments of type stack are non-NULL.
a) Write a function rev (Stack S, Stack D). We require that D is originally empty.
When rev returns, D should contain the elements of S in reverse order, and S should be
empty. (3 Marks)
Student ID #: ____________________
b) An alternative to terminating lists with NULL is to terminate them with a self-loop. We call
such a list a sloop. For example, the following is a sloop of length 3.
Write a function is_self_loop (LinkedList list) to test if list is a self-loop, that is, a
linked list terminated by a self-loop. You should assume that there are no other cycles in the
list. (3 Marks)