0% found this document useful (0 votes)
225 views3 pages

Rajiv Gandhi Institute of Petroleum Technology, Jais Amethi

This document is the mid-semester examination question paper for Data Structures and Algorithms from Rajiv Gandhi Institute of Petroleum Technology. It contains 8 questions related to data structures, algorithms and their analysis. The questions cover topics like array operations, time complexity analysis, merging sorted arrays, linked list operations and evaluating postfix expressions using stacks. Students are instructed to attempt all questions in serial order within the allotted time of 2 hours.

Uploaded by

Anu Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
225 views3 pages

Rajiv Gandhi Institute of Petroleum Technology, Jais Amethi

This document is the mid-semester examination question paper for Data Structures and Algorithms from Rajiv Gandhi Institute of Petroleum Technology. It contains 8 questions related to data structures, algorithms and their analysis. The questions cover topics like array operations, time complexity analysis, merging sorted arrays, linked list operations and evaluating postfix expressions using stacks. Students are instructed to attempt all questions in serial order within the allotted time of 2 hours.

Uploaded by

Anu Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Rajiv Gandhi Institute of Petroleum Technology, Jais Amethi

B. Tech 2nd year (CSE + ECE)


Mid-sem Examination, 2021-22
Instructors: Dr. Daya Sagar Gupta and Dr. Niraj Kumar

Subject: Data Structure and Algorithms Course Number: CS211


Date & Time: 22 Nov 2021, 9:30 AM – 11:30 AM Full Marks: 30

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)

(ii). Insertion at the beginning in a linked list (b). O(1)

(iii). Insertion at the end in a linked list (c). θ(n)

(iv). Insertion at the end in an array


(v). Searching a value in a linked list

(vi). Searching a value in an array


(vii). Deleting (first) node (which consists the given key)
in a linked list

(viii). Deleting a value in an array

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.

Q5. What would be the output of the following program? [2]


void fun2(int *ptr){
ptr[0] = 10;
}

void fun1(int array[3]){


array[0] = 0;
}

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]

//reverse linked list


void reverse_list(struct Node **head_adr){
struct Node *prev = NULL, *curr = *head_adr, *next =
NULL;

//complete this part


}

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.

----End of the Question Paper----

You might also like