Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CSD 201 MIDSEMS 2017, Exercises of Programming Languages

CSD 201 MIDSEMS 2017, High chance of question getting repeated or getting the similar type of questions, C language.

Typology: Exercises

2016/2017

Available from 08/10/2021

meetendra-singh
meetendra-singh 🇮🇳

17 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Programme: B.Tech Discipline: Computer Science and Engineering
Exam: Mid Semester Year: 2016-2017
Course Code: CSD201 Course Title: Data Structures
Date: February 25, 2017 Time: 9:30 AM 11:00 AM Max. Marks: 50
Ques.1 Indicate whether the following statements are True/False (No explanation is
required): (5 Marks)
(a) A self-referential structure contains a pointer member that points to an object of a
different type.
(b) Creating and maintaining dynamic data structures requires dynamic memory allocation
a program's ability to obtain more memory space at execution time to hold new nodes and
to release space no longer needed.
(c) The following statement evaluates sizeof(struct node) to determine the size in bytes of a
structure of type struct node, allocates sizeof(struct node) bytes in memory and stores a
pointer to the allocated memory in variable newPtr.
newPtr = malloc( sizeof( struct node ) );
(d) Function malloc returns a pointer of type void * to the memory it allocates. If it is unable
to allocate memory, it returns a NULL pointer.
(e) push is used to place elements on the bottom of a stack and pop is used to remove
elements from the top of a stack.
Ques.2 Choose the correct option (if options are given): (5 Marks)
(a) What is the time complexity of fun()?
int fun(int n)
{
int count = 0;
for (int i = 0; i < n; i++)
for (int j = i; j > 0; j--)
count = count +1;
return count;
}
(b) You have to sort a list L consisting of a sorted list followed by a few random elements.
Which of the following sorting methods would be especially suitable for such a task?
(i) Bubble sort (ii) Selection sort (iii) Quick sort (iv) Insertion sort
(c) A linear list of elements in which deletion can be done from one end (front) and insertion
can take place only at the other end (rear) is known as a
(i) queue (ii) stack (iii) tree (iv) linked list
(d) The data structure required to evaluate a postfix expression is
(i) queue (ii) stack (iii) array (iv) linked-list
(e) The result of evaluating the postfix expression 5, 4, 6, +, *, 4, 9, 3, /, +, * is __________
(i) Theta (n)
(ii) Theta (n2)
(iii) Theta (n logn)
(iv) Theta (n logn logn)
pf3

Partial preview of the text

Download CSD 201 MIDSEMS 2017 and more Exercises Programming Languages in PDF only on Docsity!

Exam : Mid Semester Year: 2016- Course Code: CSD201 Course Title: Data Structures Date: February 25, 2017 Time: 9:30 AM – 11:00 AM Max. Marks: 50

Ques.1 Indicate whether the following statements are True/False (No explanation is required): (5 Marks)

(a) A self-referential structure contains a pointer member that points to an object of a different type. (b) Creating and maintaining dynamic data structures requires dynamic memory allocation— a program's ability to obtain more memory space at execution time to hold new nodes and to release space no longer needed. (c) The following statement evaluates sizeof(struct node) to determine the size in bytes of a structure of type struct node, allocates sizeof(struct node) bytes in memory and stores a pointer to the allocated memory in variable newPtr. newPtr = malloc( sizeof( struct node ) ); (d) Function malloc returns a pointer of type void * to the memory it allocates. If it is unable to allocate memory, it returns a NULL pointer. (e) push is used to place elements on the bottom of a stack and pop is used to remove elements from the top of a stack.

Ques.2 Choose the correct option (if options are given): (5 Marks)

(a) What is the time complexity of fun()? int fun(int n) { int count = 0; for (int i = 0; i < n; i++) for (int j = i; j > 0; j--) count = count +1; return count; }

(b) You have to sort a list L consisting of a sorted list followed by a few “random” elements. Which of the following sorting methods would be especially suitable for such a task? (i) Bubble sort (ii) Selection sort (iii) Quick sort (iv) Insertion sort

(c) A linear list of elements in which deletion can be done from one end (front) and insertion can take place only at the other end (rear) is known as a

(i) queue (ii) stack (iii) tree (iv) linked list

(d) The data structure required to evaluate a postfix expression is

(i) queue (ii) stack (iii) array (iv) linked-list

(e) The result of evaluating the postfix expression 5, 4, 6, +, *, 4, 9, 3, /, +, * is __________

(i) Theta (n) (ii) Theta (n^2 ) (iii) Theta (n logn) (iv) Theta (n logn logn)

Exam : Mid Semester Year: 2016- Course Code: CSD201 Course Title: Data Structures Date: February 25, 2017 Time: 9:30 AM – 11:00 AM Max. Marks: 50

Ques.3 Answer the following questions as indicated:

(i) Which data structure is used to perform recursion? (1 Mark) (ii) Convert the expression ((A + B) * C – (D – E) ^ (F + G)) to equivalent Postfix Notation. Show all the steps during conversion. (2 Marks) (iii) Write down three differences between Arrays and Linked Lists. (3 Marks) (iv) State any two differences between static and dynamic memory allocation. (2 Marks) (v) What do you mean by stack overflow? (1 Mark) (vi) What are the limitations of linear queue? (2 Marks) (vii) Write the average case and worst case time complexity of (i) Selection Sort (ii) Insertion Sort. (2 Marks) (viii) What is the smallest value of ‘n’ such that an algorithm whose running time is 100n^2 runs faster than an algorithm whose running time is 2n^ on the same machine.? (1 Mark) (ix) Arrange these functions by order of growth from highest to lowest (2 Marks) 100n^2 1000 2 n^ 10n n^3 2*n (x) Write down any four applications of a stack. (4 Marks)

Ques.4 Suppose we are comparing implementations of insertion sort and merge sort on the same machine. For inputs of size ‘n’, insertion sort runs in 8n^2 steps, while merge sort runs in 64 nlogn steps. For which values of ‘n’ does insertion sort beat merge sort? (2 Marks)

Ques.5 Write down the algorithm(pseudocode) for Quick sort (by taking the first element of the array as a pivot element) to sort the array into non-increasing order. Also illustrate the operation of Quick Sort on the following array A = {13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11} (10 Marks)

Ques.6 Use the linked list pictured below to answer the questions 1 to 3. (3 Marks) First

Temp1 Temp

(1) What is the value of First -> next -> next -> data? (2) Pick the right option from the following: (a) First -> next == Temp (b) Temp1 -> next -> data == 60 (c) Temp2 -> next -> next == NULL (i) Only (a) is true. (ii) Only (b) is true. (iii) Both (a) and (b) are true. (iv) Both (a) and (c) are true. (v) Both (b) and (c) are true.