Académique Documents
Professionnel Documents
Culture Documents
Y13 Batch
CE / EE E / ME
K L UNIVERSITY I I / I V B.TECH. DEGREE
EXAMINATIONS - JULY 2 0 1 6
SECOND
SEMESTER
DATA STRUCTURES
Max. Marks: 60
Time: 3 hours
Write your answers sequentially.
1. Answer the following:
(a)
(b)
lOxlM
Write and analyze an algorithm to check whether all the elements in a given array of n elements are distinct?
Show the result of running Shell sort on the input (), X, 7, 6, 5, A , 3, 2, 1 using the increments { 1 , 3 , 7 }.
(d)
What is meant by list ADT? What are the types of linked lists?
(e)
What do you mean by tree traversal? Write an algorithm for in order traversal. (0 What is rehashing?
(g) Distinguish between the two common ways to represent a graph.
(h) Convert the given infix expression into postfix and prefix expression
((D + E)*Fy
(i) Find the maximum number of nodes and non-leaf nodes in a binary tree of height
H. What is the height of the empty sub tree?
(j) Construct Max-Heap for the set of integers {5, 10, 20, 15}.
Answer any five from the following:
2.
5 x 10M
Write the algorithms for the following, perform running time analysis by
deriving Recurrence Relations, and solve using Iteration / Substitution method:
(a) Recursive Binary Search:
T(l)=a
T(n/2)+ b
if n > 1
ifn = 1
T(n) = 2T(n- 1 ) + b
ifn> 1
(Turn Over)
i n i c - -i
i.
(a) Design Shell sort routine using Shell's increments. Trace Shell sort after each
pass for an array ,4 = < 81, 94, 11,96, 12,35, 17,95,28,58,41,75, 15 >. (b) Explain polyphase merge method to sort numbers residing in
secondary storage memory.
4.
(a)
Linked lists.
(b)
5.
Arrays.
(a) Outline an algorithm to Merge two ordered singly linked lists of integers into one
ordered'list.
(b) Outline an algorithm to delete an i,h node on a linked list. Be sure that such a node exists.
6.
Show the result of inserting <3, 1, 4, 6, 9, 2, 5, 7> into an initially empty binary search tree. Show the result of deleting the root. Explain the
different tree traversals for the resultant tree by giving algorithms and running times.
7.
Given the input {4371, 1323,6173,4199,4344,9679, 1989}, a fixed table size of 10, and a hash function H(X) = X mod 10, show the
resulting:
8.
(a)
(b)
(c)
(d)
Show the result of rehashing which is twice as large as the old table size.
Show
time,
8, 15,
Show
3, 9, 7, 4, 11,
the
result
of
13, and 2,
using
the
one at a
linear-time
the
most
commonly
used
representations
of
graph.
1. Adjacency
Matrix
2. Adjacency
List
There are other representations also like, Incidence Matrix and Incidence List. The choice of the
graph representation is situation specific. It totally depends on the type of operations to be
performed and ease of use.
Adjacency
Matrix:
Adjacency Matrix is a 2D array of size V x V where V is the number of vertices in a graph. Let the
2D array be adj[][], a slot adj[i][j] = 1 indicates that there is an edge from vertex i to vertex j.
Adjacency matrix for undirected graph is always symmetric. Adjacency Matrix is also used to
represent weighted graphs. If adj[i][j] = w, then there is an edge from vertex i to vertex j with
weight w.
The adjacency matrix for the above example graph is:
Pros: Representation is easier to implement and follow. Removing an edge takes O(1) time.
Queries like whether there is an edge from vertex u to vertex v are efficient and can be done
O(1).
Cons: Consumes more space O(V^2). Even if the graph is sparse(contains less number of
edges), it consumes the same space. Adding a vertex is O(V^2) time.
Adjacency
List:
An array of linked lists is used. Size of the array is equal to number of vertices. Let the array be
array[]. An entry array[i] represents the linked list of vertices adjacent to the ith vertex. This
representation can also be used to represent a weighted graph. The weights of edges can be
stored in nodes of linked lists. Following is adjacency list representation of the above graph.