You are on page 1of 6

DAYALBAGH EDUCATIONAL INSTITUTE

FACULTY OF ENGINEERING
EEM 303 DATA STRUCTURES SESSION 2018 - 19
SECOND YEAR BTECH Updated July 2018
QUESTION BANK
Unit 1

1. Explain the term data structure, and briefly mention some specific applications of the data
structures that you are familiar with.

2. What is an algorithm? How is the efficiency of an algorithm denoted? Give an example each
of an algorithm whose complexity is (i) O(log n) (ii) O(n) (iii) O(nlogn) (iv) O(n2) (v) O(n3)
(vi) O(2n) (vii) O(n!). Justify your answer.

3. What are heuristics? When are they employed? Give an example of a heuristic for the
Travelling Salesman Problem.

4. What is the Eight Queens’ Problem? Give a brute-force algorithm in the form of pseudo-code
for the problem.

5. Implement the Sieve of Eratosthenes to find all prime numbers less than 100000.

6. What are the advantages of developing a program as a collection of independent


functions?

7. Write a function that tests if a given integer is a prime number or not. What is the
computational complexity of your function?

8. Define a C structure for representing complex numbers. Give C functions to perform addition,
subtraction and multiplication of complex numbers.

9. Write a 'C' program to input a desired number of student records, each consisting of roll
number, student name and cgpa, and then output the name and roll number of the topper of
the class. State the form of the structure assumed and the key explicitly. Use an array of
structures.

10. Repeat Q9 using an array of pointers to structures.

11. Write a program to perform the addition of two very large numbers (eg. 100 or 200 digit
numbers). What kind of data structure would you use for representing such large numbers?
What is the computational time and space complexity required by your algorithm for performing
this operation?

12. What is recursion? Write recursive C functions for computing (a) the maximum of a given array
of numbers and (b) the kth Fibonacci number. What are the drawbacks associated with
recursion?

13. Distinguish between (a) Local and Global variables (b) Call by value and call by reference
parameters (c) Static and dynamic memory allocation.

14. State briefly, the role of each of the following in inputting and executing a program: Editor,
Loader, Linker, Assembler, Compiler, Interpreter, Operating System, Integrated Development
Environment.

UNIT II

1. What are the typical operations that can be performed on an array? Mention the operations and
the complexity of each operation.

2. Write functions to perform the following:

(i) Insert k in an array A that has n elements and is sorted. The array must remain sorted
after the insertion.
(ii) Insert k at position x in an array A, that has n elements.
(iii) Insert k at the end of array A. The end is marked by a sentinel “-9999”.
(iv) Delete k from an array A that has n elements and is sorted. The array must remain
sorted after the insertion.
(v) Delete k from position x in an array A that has n elements.
(vi) Delete k from the array a. The end of the array is marked by a sentinel “-9999”.

3. Write a C program to input an array of integers and find the minimum and maximum. Try to reduce
the number of comparisons required. Hint: This can be done in less than 2(n-1) comparisons for n
integers. Exactly how many comparisons does your program make? What is the time complexity of
your program?

4. Write a C program that takes two sorted arrays as inputs and merges them to create a third sorted
array. Comment on the complexity of your program.

5. Use an array to store the coefficients of a polynomial in a single variable. Write an algorithm to
add two polynomials stored in this manner.

6. Write an algorithm to multiply two polynomials stored as in Q5 above.

7. A sparse polynomial in a single variable can be stored in a 2-dimensional array by storing the
coefficients in the first row and the corresponding exponents in the second row. Write an
algorithm to add two polynomials stored in this manner.

8. Write an algorithm to multiply two polynomials stored as in Q7 above.

9. A sparse matrix is defined as a matrix in which most of the elements (typically >> 50%) of the
elements are 0. Devise an efficient representation to store such matrices, and write a C program
that stores two sparse matrices and add them. Clearly state any assumptions you make in your
implementation. What is the complexity of your algorithm?

10. Devise a representation for storing sparse matrices. Write a program to efficiently find the
transpose of the matrix input in your representation. What is the complexity of your
algorithm?

11. What is the advantage of writing expressions in postfix form over infix form? Convert the
following expressions into postfix form: (a) a ^ b ^ c (b) a + b - c * d / e (c) a / b * c + d –
e (where ^ represents the exponentiation operator).
12. Write an algorithm to convert an infix expression into postfix form. Illustrate the algorithm
using a suitable example.

13. Give an algorithm to evaluate an expression in postfix form. Illustrate the algorithm using a
suitable example.

14. Write functions to add and delete an element from the global stack, STACK which is implemented as
an array. Also write functions to check if the stack is empty or full. Initial conditions must be fully
stated.

15. Implement a global queue QUEUE which is implemented as an array and write functions to insert
and delete elements from the queue. State initial conditions clearly. When does your function say
that the queue is full?

16. What is the advantage of a circular queue representation over a simple queue representation
when arrays are used? Write functions to add and delete items from a circular queue
implemented as an array. Assume any global variables required.

17. Write C functions to (a) compute the length of a given string (b) concatenate two strings (c)
copy one string into another, assuming that enough space has been allocated for the destination
to store the source string.

18. Write a C function that compares two strings s1 and s2, and returns an integer that is less than,
equal to, or greater than 0, depending on whether s1 is lexicographically less than, equal to, or
greater than s2.

UNIT III

1. What is a pointer? Explain the relationship between pointers and arrays in C.

2. Let P be a pointer to the first node in a singly linked list and X be an arbitrary node in this list.
Give an algorithm to delete this node from the list. If P=X then P should be reset to the new first
node in the list.

3. What are the operations that can be performed on a singly linked list implemented using pointers?
Which of these operations can be done in constant time?

4. Compare linked lists and arrays as data structures - in terms of the operations that can be
performed and the efficiency with which they can be performed.

5. Given a linked list head pointer, find a method to determine if this is a circular list. Avoid making
changes to the linked list structure.

6. Write an algorithm to merge two sorted lists pointed to by X and Y and obtain a new list pointed
to by Z. The original lists must remain intact. Mention the structures used.

7. Illustrate with the help of a suitable diagram in each case, (i) Singly linked list, (ii) Singly linked
Circular list, (iii) Doubly linked list, and (iv) Doubly linked Circular List. What advantage does a
doubly linked offer over a singly linked list?
8. Given a pointer p to the head node of a singly linked list, write functions that perform the following
operations. Assume suitable type of structure and state it explicitly.

(i) Insert a structure with given data at the end of the list.
(ii) Deleting from the list, a structure whose pointer is given.
(iii) Print the contents of the list
(iv) Print the contents of the list in reverse order i.e. data in the last node first.
(v) Create a copy of the list and return a pointer to the head node of the new copy.

9. Repeat Q8 for a doubly linked list.

10. Given a pointer to the head node of a linked list write a function to return a pointer to the node
exactly in the middle of the list. Assume suitable type of structure but state it explicitly. Hint: This
can be done efficiently without counting the number of nodes in the list.

11. Given a pointer to the head node of a linked list write a function to reverse the nodes in the list
i.e. the first node should become the last node and the last node the head node. How many
pointers were required for doing this?

12. Write functions to add and delete an element from the global stack, STACK which is implemented
as a linked list. Also write functions to check if the stack is empty or full. Initial conditions must be
fully stated.

13. Implement a global queue QUEUE as a linked list and write functions to insert and delete
elements from the queue. State initial conditions clearly. When does your procedure say that the
queue is full?

14. Give a structure declaration for storing the terms of a polynomial. Assume that two polynomials are
stored as linked lists of structures of the given type in ascending order of exponents. Write a
function to add the two polynomials and produce a third one.

UNIT IV

1. Define and illustrate with the help of an example the following terms related to trees:
(a) Subtrees (b) Terminal nodes (c) Non terminal nodes (d) Siblings (e) Degree of tree (f) Level of
node (g) Depth of tree

2. (a) Calculate the maximum number of nodes at level K in a binary tree.


(b) Calculate the maximum possible number of nodes in a binary tree of level K.
(c) Prove that in a binary tree, n0 = n2 + 1, where n0 is the number of nodes with no children and n2
is the number of nodes with two children.

3. Calculate the fraction of pointers wasted in a linked representation of a full tree of degree (i) 2 and
(ii) 3 of level n. Comment on the result.

4. A strictly binary tree is a binary tree which has nodes of degree 0 or 2 only. Prove that if there are n
leaves in a strictly binary tree, the total number of nodes is 2n-1.

5. Write recursive functions to traverse a given binary tree in (a) Inorder (b) Preorder (c) postorder.
Clearly mention any assumptions made.

6. For the following digraph obtain:


(i) the in degree and out degree of each vertex
(ii) its adjacency matrix
(iii) its adjacency list representation

7. Write C functions to perform Depth first search on an undirected graph starting from vertex 1,
using (a) adjacent matrix (b) adjacency list graph representation.

8. Write C functions to perform Breadth first search on an undirected graph starting from vertex
1, using (a) adjacent matrix (b) adjacency list graph representation.

9. Write a C function to determine the connected components of a given undirected graph. State the
graph representation used.

10. Trace the working of Kruskal's Minimum spanning tree algorithm on the following graph.

11. Trace the working of Prim’s Minimum spanning tree algorithm on the graph given in Q13.

12. Trace Dijkstra’s shortest path algorithm to obtain in non-decreasing order the lengths of the
shortest paths from vertex 1 to all remaining vertices in the digraph below:

13. Given a sequence of integers, write functions to


a. create a Binary Search Tree (BST)
b. insert an element into a BST
c. delete an element from a BST

14. What are height-balanced trees? With a suitable example, explain how they are they different from
binary search trees.
UNIT V

1. Work through the algorithms of Binary search and Fibonacci search on the sorted integer array
given below. (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) and determine the number of key
comparisons made while searching for the keys 2, 10 and 15 in each case.

2. Write a recursive function to perform binary search on a sorted array of integers.

3. Write a function to perform Fibonacci Search in a sorted array of integers. How is Fibonacci search
better than Binary search?

4. Mention various sorting methods known to you along with their average case and worst case
complexities. What is the difficulty in interpreting worst case results?

5. Professor Trump claims that an algorithm with complexity O(n2) is definitely slower than an
algorithm with complexity O(nlogn) for the same problem. Do you agree? Why/why not?

6. “Worst case complexity results do not convey the full story about the performance of a given
algorithm”. Do you agree? Why/why not?

7. Write functions that take as arguments an array of integers and the number of elements, N, and
sort them using (a) bubble sort (b) selection sort and (c) insertion sort.

8. Show the working of the following algorithms (the status at the end of each iteration) on the
following array: (a) Insertion sort (b) Quick sort

F = (12, 2, 16, 30, 8, 28, 4, 10, 20, 6, 18)

9. What is a heap? Show how heap sort works on the following array: (26, 5, 17, 1, 61, 11, 59, 15, 48,
19)

10. Write a C function to implement the Quick Sort algorithm on an array of integers. What is the Worst
Case Complexity of Quick Sort? Explain your answer.

11. Write a function in C to perform Merge Sort on an array of integers and explain the worst case
complexity of the algorithm.

12. Show that any algorithm that sorts on the basis of Compare and exchange cannot be faster than
O(n log n).

13. Give a linear time algorithm to sort an array of integers. Clearly state any assumptions or limitations
of this algorithm.

You might also like