Beruflich Dokumente
Kultur Dokumente
A data structure is a way of organizing data that considers not only the items stored,
but also their relationship to each other. Advance knowledge about the relationship
between data items allows designing of efficient algorithms for the manipulation of
data.
2. List out the areas in which data structures are applied extensively?
1. Compiler Design,
2. Operating System,
3. Database Management System,
4. Statistical analysis package,
5. Numerical Analysis,
6. Graphics,
7. Artificial Intelligence,
8. Simulation
3. What are the major data structures used in the following areas : RDBMS, Network
data model and Hierarchical data model.
4. If you are using C language to implement the heterogeneous linked list, what
pointer type will you use?
The heterogeneous linked list contains different data types in its nodes and we need a
link, pointer to connect them. It is not possible to use ordinary pointers for this. So we
go for void pointer. Void pointer is capable of storing pointer to any type as it is a
generic pointer type.
Two. One queue is used for actual storing of data and another for storing priorities.
Stack. Because of its LIFO (Last In First Out) property it remembers its 'caller' so
knows whom to return when the function has to return. Recursion makes use of
system stack for storing the return addresses of the function calls.
Every recursive function has its equivalent iterative (non-recursive) function. Even
when such equivalent iterative procedures are written, explicit stack is to be used.
7. What are the notations used in Evaluation of Arithmetic Expressions using prefix
and postfix forms?
Sorting is not possible in Deletion. Using insertion we can perform insertion sort,
using selection we can perform selection sort, using exchange we can perform the
bubble sort (and other similar sorting methods). But no sorting method can be done
just using deletion.
1. Straight merging,
2. Natural merging,
3. Polyphase sort,
4. Distribution of Initial runs.
12. List out few of the applications that make use of Multilinked Structures?
1. Sparse matrix,
2. Index generation.
13. In tree construction which is the suitable efficient data structure? (Array, Linked
list, Stack, Queue)
14. What is the type of the algorithm used in solving the 8 Queens problem?
Backtracking.
If the 'pivotal value' (or the 'Height factor') is greater than 1 or less than -1.
16. What is the bucket size, when the overlapping and collision occur at same time?
One. If there is only one entry possible in the bucket, when the collision occurs, there
is no way to accommodate the colliding value. This results in the overlapping of
values.
17. Classify the Hashing Functions based on the various methods by which the key
value is found.
1. Direct method,
2. Subtraction method,
3. Modulo-Division method,
4. Digit-Extraction method,
5. Mid-Square method,
6. Folding method,
7. Pseudo-random method.
18. What are the types of Collision Resolution Techniques and the methods used in
each of the type?
19. In RDBMS, what is the efficient data structure used in the internal storage
representation?
B+ tree. Because in B+ tree, all the data is stored only in leaf nodes, that makes
searching easier. This corresponds to the records that shall be stored in leaf nodes.
A spanning tree is a tree associated with a network. All the nodes of the graph appear
on the tree once. A minimum spanning tree is a spanning tree organized so that the
total edge weight between nodes is minimized.
21. Does the minimum spanning tree of a graph give the shortest distance between
any 2 specified nodes?
No. The Minimal spanning tree assures that the total weight of the tree is kept at its
minimum. But it doesn't mean that the distance between any two nodes involved in
the minimum-spanning tree is minimum.
22. Which is the simplest file structure? (Sequential, Indexed, Random)
Q.1. (a) List out the differences between sequential allocation and dynamic
allocation
Schema: Any valid eight differences. Each difference carries half mark.
(b) List atleast 5 real life examples where stacks and queues are being used.
Schema: Minimum five examples are expected for both Stacks and Queues.
Examples for Stacks:
1. Stack of CDS in a CD box 2. Stack of plates in a Buffet 3. Bangle of same size
4. Rings of same size in a needle 5. Layers in an onion
Examples for Queues
(c) Develop an algorithm to delete an element e from a Linear Single Linked List
Schema: Each box below representing various conditions to be checked carries one
mark
Algorithm: Delete_e_LSLL Input: F, the address of the first node in the list; e,
element to be deleted Output: F, List updated; Method: If (F == Null)
Printf(Deletion Not possible, list is empty) {
Else
If end
Else
} Algorithm ends
Else
If end
}
If (F.link == Null)
{
}
If (F.data == e) F=null;
Else If end
Printf(Deletion Not possible, element not present)
If (F.data == e) { F= F.link}
{ V= F;
While(V.link != null && V.link.data != e) { V=V.link; }
If(V.link == null) Printf(Deletion Not possible, element not present)
Else
/* If (V.link.data == e) */ V.link = V.link.link;
If end
2.5+2.5+5
Q.3 Write a recursive function to solve the Tower of Hanoi Problem. Show the status
of the stack using state space diagram, when the function, Tower of Hanoi is called
with n=3 rings.
Schema: Correct function carries 5 marks and the state space diagram carries 5 marks
Tower_of_Hanoi(n, S, D, T) {
If (n > 0) { Tower_of_Hanoi(n-1,S,T,D); Printf(Move disk from %c to %c, S, D);
Tower_of_Hanoi(n-1,T,S,D); }
Q.4 Obtain the equivalent prefix and postfix expressions for the following infix
expressions
Binary_Search_recursive(A,mid+1,high,key) If end
If end
If end Return(false) Algorithm ends
Tracing for Key = 22
A = [22 29 37 45 67 88 89 90 95]
Low=0 High=8 Key=22
Tracing for Key = 100
A = [22 29 37 45 67 88 89 90 95]
Low=0 High=8 Key = 100
Binary_Search_recursive(A, 0, 8, 22) Low <= high 0 <=8 is true Mid = (0+8)/2 = 4
If(key == A[mid]) 22 ==67 is false If(key < A[mid]) 22<67 is true
Binary_Search_recursive(A, 0, 3, 22)
Binary_Search_recursive(A, 0, 3, 22) Low <= high 0 <=3 is true Mid = (0+3)/2 = 2
If(key == A[mid]) 22 ==37 is false If(key < A[mid]) 22<37 is true
Binary_Search_recursive(A, 0, 2, 22)
Binary_Search_recursive(A, 0, 2, 22) Low <= high 0 <=2 is true Mid = (0+2)/2 = 1
If(key == A[mid]) 22 ==29 is false If(key < A[mid]) 22<29 is true
Binary_Search_recursive(A, 0, 0, 22)
Q.7.
(a) Devise algorithms to realize stack operations Push and Pop using linear single
linked lists To realize Push operation of stack using linear single linked list we need
to implement the algorithm
of inserting an element e as the first node into the LSLL. To realize Pop operation of
stack using linear single linked list we need to implement the algorithm
of deleting the first node from the LSLL
Algorithm: Stack_Push_LSLL Input: F, first node address; e, element being pushed
into the stack; Output: F, Updated Method:
N = getnode(); N.data = e; n.link = F; If (F == null)
Else
F = n;
n.link = F; F = n;
(b) Devise algorithms to realize queue operations Insert and Delete using circular
single linked lists.
To realize Insert operation of Queue using linear single linked list we need to
implement the algorithm of inserting an element e as the last node into the LSLL.
To realize Delete operation of Queue using linear single linked list we need to
implement the algorithm of deleting the first node from the LSLL
Algorithm: Queue_Insert_LSLL Input: F, first node address; e, element being Inserted
into the Queue; Output: F, Updated Method:
N = getnode(); N.data = e; n.link = null;
If (F == null) F = n;
Else
If end Algorithm ends
V=F; While(V.link != null) V=V.link; While end
V.link=n;
Algorithm: Queue_Delete_LSLL Input: F, first node address; Output: F, Updated;
E, Deleted element /*optional */ Method:
If (F == null) Print(Queue empty);
Else
e = F.data;
4*2.5= 10
Q.1.
(a) Is n=2 the largest value of n for which there exist positive integer x, y and z such
that xn+yn=zn has a solution?
2+2+2+4 Ans: Requires to check if the equation xn+yn=zn gets satisfied for any value
greater than 2. Since there are
infinitely many numbers that are greater than n, it enters an infinite loop. Therefore
the statement does not satisfy the finiteness property.
(c) If n<10 assign the value of A or the value of B in to the variable C All the above
three statements fail to satisfy one of the five basic properties of an algorithm. Which
criteria do they violate?
Ans: if n<10 C=A or C=B. OR in this statement has a dilemma or ambiguous.
Therefore violates the property of defineteness.
(d) Write a C program that prints out the integer values X, Y, Z in ascending order
and prove the correctness of your program.
Ans:
#include<stdio.h> #include<conio.h> void Sort_Three_One(int a, int b, int c); void
main() { int x,y,z; printf(Enter the values for x, y and z\n);
scanf(%d%d%d,&x,&y,&z);
Sort_Three_One(x,y,z);
/* or Sort_Three_Two(x,y,z); Or any sorting technique such as Sort_Three_Three(x,
y, z); */
}
void Sort_Three_One(int a, int b, int c) if(a<=b)&& (a<=c) && (b<=c)
Void Sort_Three_Two(A, B, C) { if(a <= b) {
if(a<=c) {
if(b <= c) printf(%d%d%d,a, b, c);
else
printf(%d%d%d,a, c,b); else if(a>c)
printf(%d%d%d, c, a, b);
}
} else if (b<a)
{ if(b<=c)
Q.2.
(a) Define Data, Data Object, Data Storage, Data type and an abstract data type. Ans:
Data:.
Data type: Abstract data type:
Data: Data is a collection of facts which can be served as input to any processing unit
such as a program, equation etc
Data Object: Data object is an instance of data. It is application dependent. Any
natural number in a set of natural numbers is a data object. A bangle in a hand is a
data object.
Data Storage: A structure which holds the data.
Data Type: A data type is a collection of objects speaks the characteristics of the data
in the collections and the operations that can be performed on that.
ADT: An abstract data type is a data type that is organized in such a way that the
specification of the objects and the specification of the operations on the objects is
separated from the representation of the objects and implementation of the operation.
Formally described by Domain, Functions and Axioms.
Ans:
(b) Create and abstract data type Bag. Bag is similar to a set except that a bag may
contain duplicate elements.
ADT for BAG: Domain: Application Dependent items + Boolean Eg: Bag of books,
Bag of vegetables, Bag of Electronic Items, School Bag etc
Functions:
Create(Bag)= null; Isfull(Bag) = Boolean; Isempty(Bag)=Boolean; Insert(item,
Bag)=Bag; Pick(item, Bag)=item Count(Bag) Search(Bag,item) Count_duplicate(Bag
Axioms:
Isfull(create(Bag))=false Isempty(insert(item, Bag))=false If (isfull(bag)==yes), Insert
(item,Bag)=Not possible If(isempty(bag)==yes), Pick(item,Bag)=Not possible
Q.3
(a) Define asymptotic notations O, and .
ASYMPTOTIC NOTATION
Time complexity can be denoted by the following notations. 1. Big (oh) notation -O
[Worst case time complexity] 2. Omega notation - *Best case time
complexity+ 3. Theta notation *Average case time complexity]
1. Big (oh) notation O
Big oh can be expressed as f(n)=O(g(n)) iff there exists c, n0 such that f(n)<=c g(n)
For all n>=n0.
2. Omega notation -
Omega can be expressed as f(n)=(g(n)) iff there exists c, n0 such that f(n)>=c g(n)
For all n>=n0.
3. Theta notation
Theta can be expressed as f(n)=(g(n)) iff there exists c1,c2, n0 such that
c1g(n)<=f(n)<=c2 g(n) For all n>=n0.
(a) f(n)= 3n has higher order term than g(n)= 2n, the
(b) re cannot exist a C and a n0 which satisfy the inequality f(n)<=c g(n)
for n>=n0.
(b)f(n)= n32n+6n23n has higher order term 3n than g(n)= n22n there cannot exist a
C and a n0 which satisfy the inequality f(n)<=c g(n) for n>=n0.