You are on page 1of 6

DAYALBAGH EDUCATIONAL INSTITUTE

FACULTY OF ENGINEERING
EEM 303 DATA STRUCTURES SESSION 2016 - 17
SECOND YEAR BTECH Updated July 2016
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. Would you consider an algorithm of complexity O(nk), k=10, to be efficient? Do algorithms of


such complexity exist in practice? Why or why not?

4. Explain the importance of data structures in determining the efficiency of a program, using a
suitable example.

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

6. Write a 'C' program to input a desired number of structures and then output them in sorted
order according to some key value. State the form of the structure assumed and the key
explicitly. Use an array of structures.

7. Repeat Q7 but using an array of pointers to structures.

8. Devise a representation to store extremely large integers (say maximum 50 digits). Write a
program to add two integers stored in this representation.

9. Devise a representation to store extremely large integers (say maximum 50 digits). Write a
program to multiply two integers stored in this representation.

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

11. 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.

12. Write recursive functions to


(a) Find the minimum of an array of integers.
(b) Find the maximum of an array of integers.
(c) Compute the kth Fibonacci number.
(d) Find the sum of an array of numbers.

13. Write functions to determine the following for a given array of integers: (i) Mean (ii) Median (iii)
Mode.
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 program that takes two sorted arrays as inputs and merges them to create a third sorted
array. Comment on the complexity of your program.

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

5. Write a program to multiply two polynomials stored as in Q4 above.

6. 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 a program
to add two polynomials stored in this manner.

7. Write a program to multiply two polynomials stored as in Q6 above.

8. 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.

9. Write a program to store two sparse matrices represented as in Q8 and add them. You must state
your assumptions clearly.

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. What is a priority queue? How is it different from an ordinary queue? Devise an array
implementation of a priority queue and write the relevant functions.

18. 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.

19. 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 is 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 Q7 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 to do 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.

15. 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 multiply 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 2 in a binary tree.


(b) Calculate the maximum possible number of nodes in a binary tree of level 2.
(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 binary tree of degree (i)
2 and (ii) 3 of level n. Comment on the result.

4. Suppose that you are given two sequences that supposedly correspond to the preorder and inorder
traversals of a binary tree. Prove that it is possible to construct the binary tree uniquely.

5. 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.
6. Two binary trees are similar if they are both empty, or if they are both non empty, their left sub-
trees are similar and their right sub-trees are similar. Write an algorithm to determine if two binary
trees are similar.

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

8. Write a program that takes as input a series of integers and creates a binary search tree. State any
assumptions that you make clearly.

9. For the following digraph obtain:


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

10. 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.

11. 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.

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

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

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

15. 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:

16. Given a sequence of integers, write a function to create a Binary Search Tree.

17. What are height-balanced trees? How are they different from binary search trees?
18. Give algorithms for insertion and deletion in an AVL Tree. State the structure representation
assumed explicitly.

UNIT V

1. Work through algorithms 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. Write a program to input an array of integers and sort them using Bubble sort.

6. Write a program to input an array of integers and sort them using selection sort.

7. Write a program to input an array of integers and sort them using insertion sort.

8. You have a large array of large structures. Which algorithm would you prefer if you needed to sort
the array in the following cases? Justify your answer with suitable logic in each case.

a. The input is completely random


b. You know that the input is almost sorted and there are only few data items “out-of-order”.

9. 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)

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

11. 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.

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

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

14. Give a linear time algorithm to sort an array of integers.

You might also like