Rajiv Gandhi Institute of Petroleum Technology, Jais Amethi
Rajiv Gandhi Institute of Petroleum Technology, Jais Amethi
INSTRUCTIONS:
i) There are 8 questions in this question paper.
ii) All the questions are COMPULSORY.
iii) Marks against each question are indicated in brackets.
iv) Copied answers will not be evaluated.
v) Attempt the questions in serial order (if possible).
Q1. Identify and report the correct matching. [For example, (i, ii, iii, iv) -> (a), (v, vi, vii)
-> (b), (viii) -> (c)] [4]
(i). Insertion at the beginning in an array (a). O(n)
Q2. (a). Find the running time of the following program. [2]
void fun(){
for(int i=1;i<=n;i++)
{
for(int j=1; j<=n;j=j+i)
printf(“RGIPT”);
}
}
(b). Given two algorithms A1 and A2 to solve the same problem with the running times
O(n) and θ(n), respectively. State with the proper justification, which algorithm you would
choose. [2]
Q3. (a) The kth element of an array, with the base address base, can be found at the address
………………….. [1]
(b). How to assign elements of an array ARR2 to another array ARR1 of the same type and size?
Do you think ARR1 = ARR2 will work? [2]
Q4. Let ARR1 and ARR2 be the two arrays of integers. However, ARR1 is sorted whereas ARR2
is not. You are supposed to write an algorithm (sequence of steps) to merge these two arrays into
a third array ARR3 such that it is also sorted. [4]
Note: You are not allowed to sort any array. Assume ARR2 does not contain repeated elements.
int main(){
int arr[]={1,2,3};
printf("%d\n", arr[0]);
fun1(arr);
printf("%d\n", arr[0]);
fun2(&arr);
printf("%d\n", arr[0]);
return 0;
}
Q6. Consider the following given inputs: head and tail pointers of a doubly linked list,
new_elem and key are two integers.
State the steps to insert a new node (with the value new_elem) in the given doubly linked list.
Assume that each node of linked list consists of a data (integer) field and two pointers. The new
node is supposed to be inserted after the last node which has the value key. Explain using an
example of your choice with five nodes in the linked list. [5]
Note: You must use the given input variables (as well as require intermediate variables) to
state the steps. It should not be plain english.
Q7. Complete the following code to reverse a doubly linked list. [4]
Q8. State the steps to evaluate a postfix expression using stack. Also, illustrate with an example of
your choice (number of operands not less than 5 and number of operators not less than 4) of binary
operators. [4]
Note: All operators should not be together. For instance, 5 6 4 2 7 + * - + is not a valid example.