DS Akash
DS Akash
DS Akash
AKASH'S
Guru Gobind Singh Indra Prastha University Series
SOLVED PAPERS
TPREVIOUS YEARS SOLVED QUESTION PAPERS]
|B.Tech)
THIRD SEMESTER
Data Structure
(CIC-209)
Rs.81.00/
AKASH BOOKS
NEW DELHI
NEW TOPICS ADDED FROM ACADEMIC SESSION 2022-23
THIRD SEMESTER (B.TECH]
DATASTRUCTURE (CIC-209)
Q.1. What is the Time - Space Trade Off in Algorithm & also explain its
type.
Ans. Time-Space Trade-Of in Algorithms
A trade off is a situation where one thing increases and another thing decreases. It
is a way to solve a problem in:
• Either in less time and by using more space, or
•
In very little space by spending a long amount of timne.
The best Algorithm is that which helps to solve a problem that requires less space
in memory and also takes less time to generate the output. But in general, it is not
always possible to achieve both of these conditions at the same time. The most common
condition is an algorithm using a lookup table. This means that the answers to some
questions for every possible value can be written down. One way of solving this problem
is to write down the entire lookup table, which will let you find answers very quickly but
will use a lot of space. Another way is to calculate the answers without writing down
more
anything, which uses very little space, but might takea long time. Therefore, the
time-efficient algorithms you have, that would be less space-eficient.
Types of Space-Time Trade-off
(a) Comnpressed or Uncompressed data: A space-time trade-off can be applied
to the problem of data storage. If data stored is uncompressed, it takes more space but
less time. But if the data is stored compressed, it takes less space but more time to run
the decompression algorithm. There are many instances where it is possible to directly
work with compressed data. In that case of compressed bitmap indices, where it is faster
to work with compression than without compression.
(b) Re-Rendering or Stored images: In this case, storing only the source and
rendering it as an image would take more space but less time i.e., storing an image in
the cache is faster than re-rendering but requires more space in memory.
(c) Smaller code or Loop Unrolling: Smaller code occupies less space in memory
but it requires high computation time that is required for jumping back to the beginning
of the loop at the end of each iteration. Loop unrolling can optimize execution speed at
the cost of increased binary size. It occupies more space in memory but requires less
computation time.
(d) Lookup tables or Recalculation: In a lookup table, an implementation can
include the entire table which reduces computing time but increases the amount of
memory needed. It can recalculate i.e., compute table entries as needed, increasing
computing time but reducing memory requirements.
Q.2. What is algorithm and why analysis of it is important?
Ans. In the analysis of the algorithm, it generally focused on CPU (time) usage,
Memory usage, Disk usage, and Network usage. All are important, but the most concern
is about the CPU time. Be careful to differentiate between:
•
Performance: How much time/memoryldisk/etc. is used when a program is run.
2021-3
I.P. University-(B.TechJ-Akash Books
Structure
Semester, Data we write. Asymptotic analysis refers to computing the
running time of any operation in
one
Third as the code mathematical units of computation. For example, the running time of as operation
As well program or algorithm scale, it is computed gn). This
2-2021 compiler, etc. as and may be for another operation
machine. a
larger is computed (n)
time will increase línearly with the increase n
in
code gets
requirements of
on the operation running
resource solved by the first
s
This depends means the
of the second operation will increase
exponentially when
Complexity: How do theof the
problem being
vice-versa. n and the running the same if n is
size operations will be nearly
happens as the performance but
not increases. Similarly, the running time of both
i.e. what
Complexity affects significantly small.
Note: complexity theory, which three types -
computational
Algorithm Analysis an important part of resources of an algorithm to solve
a Usually, the time required by an algorithmn falls under
is required determination of the • Best Case - Minimum time required for
program execution.
analysis the
Algorithm estimation for the algorithms is program execution.
provides theoretical
Analysis of Average time required for
computational resources required to execute
prablem. it. •
Average Case-
Worst Case - Maximum time required for
speciic space program execution.
amount oftime and important?
ofAlgorithms is implementing it on a specific
Why Analysis algorithm without Asymptotic Notations
of an to calculate the running
To predict the
behavior
of Following are the commonly used asymptotic notations
measures for the efficiency time complexity of an algorithm.
efficiency every time certoi
Computer. simple a
much more convenient to have test the
and •0 Notation
It is implement the algorithm
algorithm than to computer systemn changes. manv • QNotation
parameter in the underlying There are too
behavior of an algorithm.
impossible to predict the exact •0 Notation
• It is
infuencing factors.
:
O(n) is the formal way to express the upper
Big Oh Notation, O The notationmeasures
only an
approximation; it is not perfect. the worst case time complexity or the
• The analysis is thus we can compare them to bound of an algorithm's running time. It
analyzing different algorithms, longest amount of time an algorithm can possibly take to comnplete.
• More importantly, by purpose.
one for our
determine the best analysis?
Algorithm
Q.3. Explain the different types of
Algorithmn Analysis are as follows:
Ans. Types of less time or minimum
(a) Best case: Define the
input for which algorithm takes Example: In the linear
lower bound of an algorithm. case
case calculate the
time. In the best
present at the first location of large data then the best
search when search data is
OCcurS. or maximum
(b) Worst Case: Define the input for
which algorithm takes a long time
upper bound of an algorithm. Example: In the linear
time. In the worst calculate the
worst case occurs.
search when search data is not present at all then the
(c) Average case: In the
average case take all random inputs and calculate the
computation time for all inputs.
And then we divide it by the total number of inputs. k
Average case = all random case time /total no of case For example, for a function f(n)
Q4. What is the Asymptotic Analysis of Algorithms? Explain the Diferent O(fn)) = {gn): there exists c > 0 and n, such that fn) s egn) for all n > n. }
types ofAsymptotic Notations? Omega Notation, 2 : The notation n) is the formal way to express the lower
bound of an algorithm's running time. It measures the best case time complexity or
-
Ans. AsymptoticAnalysis Asymptotic analysis of an algorithm refers to defining the
the mathematical boundation/traming of its rua-time performance. Using asymptotic
best amount of time an algorithm can possibly talke te onplete.
analysis, we can very well conclude the best case, average case, and worst case scenario
of an algorithm.
Asymptotic analysis is input bound i.e., if there's no
input to the algorithm, it
is concluded to work in a constant time. Other than
the input" all other factors are
considered constant.
Structure
Semester, Data I.P. University-(B.Tech]-Akash Books
2021-5
Third
4-2021 Q.6. What is the Sparse Matrix? Explain the Array & Linked List
representation of Sparse Matrix.
Ans. A matrix is a two-dimensional data object made of m rows and n columns,
therefore having total m Xn values. If most of the elements of the matrix
have 0 value,
then it is called a sparse matrix.
Why to use Sparse Matrix instead of simple matrix?
• Storage: There are lesser non-zero
elements than zeros and thus lesserT memory
can be used to store only those elements,
• Computing time: Computing time can
be saved by logically designing a data
structure traversing only non-zero elements.
Example:
00304
k
00570
for all n >n.
)
{gn) if and only if gn) = 0(fn) and g(n) fn)) for all n >n,.
(f(n) =
} 00 3 0 4
Row 0 1 3
Common Asymptotic Notations 0
05 70
Following is a list of some common asymptotic notations
Column 2 4 2
constant O(1) 0 0
0 0 0
logarithmic O(log n) Value 4 5 7 6
linear 0 2 6 0 0
O(n)
n log n
On log n) Method 2: Using Linked Lists : In linked
quadratic our fields are defined as: list, each node has four fields. These
O(n)
cubic
O(n3) Row: Index of row, where non-zero
polynomial element is located
no) • Column: Index of
column, where non-zero element
exponential is located
90n) •Value:
Value of the non zero element located
at index - (row,column)
• Next node: Address
of the next node
Structure
Semester, Data
Third
I.P. University-(B.Tech]-Akash Books 2021-7
6-2021 START
o 4
Ans. Polynomial can be represented in the various ways. These are:
o03 • By the use of arrays • By the use of Linked List
006 70 Representation of Polynomials Using Arrays
0000C There may arise some situation where you need to evaluate many polynomial
o 2
60 expressions and perform basic arithmetic operations like addition and subtraction with
those numbers. For this, you will have to get a way to represent those polynomials. The
Addreas af
ROW|coLUMN/VALUE Dext node
simple way is to represent a polynomial with degree 'n' and store the coefficient of n+1
NODE
STRUCTURE
structure &
also explain its operations? terms of the polynomial in the array. So every array element will consist of two values:
a Disjoint set data don't have
any elementtin common,
the
•
Coefficient and • Exponent
Q.6. What
tis
sets are called
disjoint sets if they
Polynomial representation using Linked List
Ans. TwO of
|START
10 abe +
11 *{ abc – +
NFO 4INFO X
12 *{( abc – +
13 abe - +d
Single linked list 14 *{( abc -+ d
15 *{( abc + de -
START 16 abc + de -
17 abc -+ de
PREV INFoNEXT Prev 18. abc - + de -
Infonext Prev info next
19. abc - + de - f
–
Nodes +
20. *V(+ abc de-f
21. *W+ abc – + de -fg
Doubly linked list
University-(B.Tech)-Akash Books 2014-3
LP. 4-2014 Third Semester, Data Structures
abc- + de - Sg
22 abc - + de-fgh
*/+ Void print_str (char*S)
23.
*1/ abc- + de- fgh -+
24 abe -+ de - fgh -+/*
int i;
25
linked for (i = 0; S [i); i ++)
If youare using C language to implement the heterogenous
Q1.((ü) putchar (SiD; putchar (\n);
list, what pointer type will you t
heterogeneous linked list. The
Ans. We use the void pointer to implement the we need a link, Q.2.(6) What is Abstract Data type and its implementation through data
heterogenous linked list contain different data types in its nodes and we use structures?
pointer, to connect them. Since we can't use ordinary pointer for this, the void
to any type. Ans. Abstract Data Type: Abstract data type is the specifications of the data type
pointer. Void pointer is a generic pointer type, and capable of storing pointer which specifies the logical and mathematical model of the delta type.
Q.1.(e) What are threaded binary Trees? How are threads different from To implement a fraction data type:
pointers? Andhow we can determine the next node to whicha thread points?
Ans. In a linked representation of any binary tree, half of the entries in the pointer Type day strict ( int numerator, denomination; fraction;)
field LEFT and RIGH will contain null entries. This space may be more efficiehtly main ()
used by replacing the null entries by special pointers called threads. Which points to
the nodes higher in the trees. Such trees are called Threaded Tree. fraction f;
Difference between threads and pointer: Threads in a binary tree must be f. numerator = 1;
distinguished from normal pointer. In a graphical representation of a threaded binary f. denomination=2;
tree, threads are shown by dotted lines. In a computer memory, an extra field called tag
or flag is used to distinguisha thread from a normal pointer.
Tree can be threaded using one way threading or two way threading.
Ina one way
threading, a thread will appear in the right field of the node and will point to the
sucoessor node in the in order traversal of tree: and in two way threading tree a Application-use the ADT
of thread
will also appear in the left field of a node and will point to the preceding node in
the in
order traversal of tree.
|Specification -define the ADT
Q2.(a) Write an algorithm or pseudo code to extract characters from a given
string from a given position for n characters and store it another string which is
initialized at run time. Implementation-Implement ADT
Ans.
#include <stdio.h> When we use abstract data type, our program divide into two:
# define SIZE 100 The Application: The part that use Abstract data type.
void print_str (char S [); The Implementation: The part that implement the Abstract data type.
void read_str (char S); Q2.(e) How will you check the validity of an expression containing nested
main ( ) parenthesis?
{
Ans. To check the validity of an expression containing nested parenthesis we use
char str [SIZE); the stack. Stack works fine for this. The steps are:
do {
(1) Maintain a stack of characters.
read _str (Str): (2) Whenever you find opening braces ?,
print_str (Str);
} while
(Str [0];
(3) Whenever you find closing traces ,
or push it on the stack.
P, T check if top of stack is corresponding
opening bracket, if yes then pop the stack, else break the loop and return false.
(4) Repeat step 2-3 until end of the string.
void read str (char *S) Q.3.(a) Write à pseudo code/algorithm for
(1) insertion at the end
ofa circular linked list.
int i; (iü) Deletion of a node with a given data
char c; ina doubly linked list.
Ans.
for (i = 0; (c = get char () ) != "\n';i++)
S (i] = c; FIRST
Si] = NULL; 10 18
PTR
CPT
University-(B.Tech-Akash Books 2014-5 Third Semester, Data Structures
I.P. 6-2014
FIRST node **colhead; / Head element of columns
(CPT) till link (CPT)
Repeat CPT = Link node ** rowhead; // the head element of rows
i.e int rows cols; // number of rows & columns of matrix;
=
LINK (CPT) PTR operations of the class;
LINK (PTR) = FIRST
PTR
FIRST
CPT Q.3.(e) Write a pseudo codelalgorithm to remove duplicate elernent froma
25 list?
10 18 Ans. Transverse the list from the hed (or start) node. While Traversing, compare
each node with its next node. If data of next node is same as current node then delete the
next node. Before we delete a node, we need to store next pointer of the node.
At the end overflow and STOP. Program:
1. IfAvail = NULL then linked list is
# include < stdio.h>
2. PTR+AVAIL # include < stdlib.h>
AVAII +LINK (AVAIL) Struct node
Read INFO (PTR) (int data;
3. CPT + FIRST struct node * next;
4. Repeat step 5 while LINK (CPT) != FIRST
5. CPT + LINK (CPT) Void remove Duplicates (Struct node * head)
6. LINK (CPT) PTR
LINK (PTR) + FIRST Struct node *current = head;
Struct node* next - next;
7.
8. STOP ==
if (Current NULL)
(ii) Ifa specific node is given. return;
L ifFIRST = NULL then write UNDERFLOW and STOP.
While (Current > next! = NULL)
2. Read DATA as information of node to be deleted.
3.
4.
PTR+ FIRST
=
Repeat step (5) while INFO-(PTR) DATA
if (Currnet - 7 data = = current -> next-> data)
5. PTR c
RPT (PTR) next-next = current -> next-> next;
6. CPT cLPT (PTR) free (current_ next);
TPT+RPT (PTR)
RPT (CPT) + TPT else
LPT (TPT)+CPT
7. RPT (PTR) +AVAIL
current current-> next;
=
AVAIL PTR
8. STOP.
Q.3.(6) How can we use linked list to store a sparse matrix? void Push (Struct node **
Ans. The most advantage of linked list-is manageability of memory and it is very
head-ref, int new-data)
imporant for large programs which are used to process a lot of data.
To represent a sparse matrix we use a inked list for
Struct node * new_node = (Struct node*) malloc (size of (Struct node));
each row and each column. So new_node-> next= (*head-ref);
its needs two pointers : Next in this row and next in this column. (*head-ref) = new-node;
Struct node
node * next (01;
Void printlist (Struct node * node)
node * next row;
int row;
While (node! = NULL)
int col;
int value;
printf ("/d", node -> data);
; node = node - > next;
Class matrix
University-{B.Tech)-Akash Boolke
LP 2014-7
FRONT REAR
:L,: Ly =7x6x6= 210 elements.
Accordingly APRcontains L,
Suppose the programming language store APR in memory in row major order and (U) F inserted
Base (APR) = 200 w =4 words per memory cell.
The effective indices of the subscripts are:
E, =5-2 =3 E, =-1-(4) =3 E, =8-6=2. F D E
For row major order, we have:
E,L, = 3 x6= 18
EL, +E, = 18 +3 = 21 REAR FRONT
(E,L, +E,)L, = 21 x5= 105
(E,L, +E,)L, +E, = 105 + 2 = 107 (vi) D is deleted.
Add (APR (5, - 1, 8]= 200 + 4 (107) =
200 + 428= 628.
Q.4.(6) Consider a circular queue
Front & REAR when following with fixed 5 position. Find the value of
operations are performed F E
(i) A, B, C, inserted.
(i) A is deleted.
(iüü)D &E are inserted. (iv) B &C deleted.
(v) Finserted. (vi) D deleted. REAR FRONT
(oii) G & Hinserted.
Ans. () A, B, C, inserted.
(vii) G &H inserted.
H E
Circular queue
A B C
REAR FRONT
FRONT REAR
Structures
Third Semester, Data
24-2014
on any two of the following: FIRST TERM EXAMINATION [SEPT.-2015]
Q.8. Write short notes
(a) Bucket Hasing records directly in the hash table.
Each record is) THIRD SEMESTER (B. TECH|
Ans. Closed hashing stores all position
h
h (K). T'he slot computed
by
a home that is
the key value value K, has DATA STRUCTURE ETCS-209]
function. bucket to which it is mapped has
available spaco.
When a record is inserted, the space, however it
store the record. Ifthe bucket does not have enough occur done to following reasons.
err
indicates an Time: 1½ Hrs.
MM:30
overflow Note: Attempt Q.No.I which is compulsory any two more questions.
condition called Bucket Overflow. Bucket
which we denote by nb, must he
Insufficient Buckets: The number of bucketnumber of record. Q.1. (a) How the resulting BST will look if the input is already sorted
nn
in
>
choosen such that nb nrfr. Where nr denote total
decreasing order. (1)
fr denote the record that fit in the bucket. more frequent than that Ans. Ifall nodes are already sorted in non decreasing order then all nodes are inserted
Skewness: If the selection of a bucket, during insertion is a
bucket is said to be skewed as against being symmetrical. into the right side of binary search tree, for example
of others, the
• Bucket methods are good for implementing hash table stored on disk, because nodes are 1, 2, 3, 4, 5
the bucket size can be set to the size ofa disk block.
(6) Collision Resolution.
the BST will look like -
suppose
Ans. Suppose we want to add a new record R with the keyK to our file F, but
the memory location address Hk) is already occupied. This situation is called collision.
(1) Collision resolution by open addressing.
(2) Collision resolution by separate chaining.
Open Addressing: In this, all elements are stored in the hash table itself. That is
each table entry contains either an element of the dynamic set or NEL.
Advantage: The advantage of open addressing is that it avoids pointers together.
Instead offollowing pointers, we compute the sequence of slot to be examined. The extra
memory freed by not storing pointers provides the hash table with a large number of
slots for the same amount of memory.
9.1. (6) Construct Binary tree T from following sequence.
Hashing with Changing: This method maintain a chain of elements which has (2)
the same hash address. We can take the hash table as an array of pointers. Size of hash PREORDER: ABDGCEHIF
table can be number of records. Here each pointer will point to one linked list and the
elements which have the same hash address will be maintained in the linked list. We INORDER: D GBAHEICF
can maintained the linked list in sorted order and each elements of linked list wil] Ans.
contain the whole record with key.
Adyantage: The main advantage of this hashing is saving of memory space and PREORDER:ABD GCEHIF
perfect collision resolution. INORDER:D GBAHEICF
• Here hash table contain only pointer which
point to linked
list-containing records.
Disadvantage: The main disadyantage is also wastage of memory space. In case
where records are very small or contains only key.
(e) Complexity of program.
Ans. The complexity of an algorithm is a function fn) which measure
for spaçe used by an algorithm in terms of input size n.
the time and
The choice of particular algorithm depends on following
performance analysis and D
measurements.
(1)Space complexity: Analysis of space complexity of an algorithm or program is
the amount of memory it needs to run to complete.
The space needed by the program
consist of following components.
(1) Instruction space (2) Data space (3) Environment stack space. Q.1. (c) Number of nodes in complete trce is 1000000. Find its depth.
(2) Time complexity: Time complexity an (1)
needs to run to completion. The exact of algorithm is the amount of time it
time will depend on the implementation Ans. The depth of complete binary tree is log(n) where no. of nodes is n. So the depth
algorithm programming language, of the of complete binary tree which has the 1000000 nodes is.
CPUspeed, other hardware optimising the capability of the compiler
and so on. used, the
•
To measure the time complexity log (1000000) = 6
accurately, we have to count Q.1. (d) Write algorithm/programto perform POP operation cn stack using
performed in an algorithm. all sorts of operations
The time complexity also singly linked list. (2)
depend on the amount of data input to ar
algorithm.
Structure
Semester, Data
Third I.P. University-(B.Tech.-Akash Books 2015-3
2-2015
Ans. Void pop (c) Insert a
-1
Struct node ptr;
NULL)
If (top = = Insert z
(printf ("Underflow")
return;
ptr = top;
top = ptr link: Insert 2
free (ptr);
pointer.
points back to the bee.3. Insert y
A circular header list is a header list where the last node
node.
Q.1. () What is the condition that a circular queue is full if the queue i
implemented using arrays? (1)
0(w)
o)
after L-R rotation the tree io
There is the Balance factor
of b
is-2 So Insert e
Inset d
After Insertion of node e the tree is unbalanced so after applying the L-L rotation
the tree is
Insert L
Insert u
-2
+2
+1(6
0(a)
o) -2(0
-10
(w)0
o
Structure
Semester, Data
Third
aner apply the LP. University-(B.Tech,-Akash Books
unbalanced go
R.R
rotation 2015-7
6-2015 tree is he
node the
v
(b) LINK (PTR) -TPT
Aner InBert the
(e) TPT PTR
tree iP
m
(d) PTR CPT
Step 6 Stop.
Q.3. (a) Considor the following in fiz expression and convert into reverse
polish notation using stack. (5)
Ans, (A + (B*C-D/E^F)"G)H)
Character Stack Reverse polish Notatic
o
D0 Scannod Postfix Notation
( (
A ( A
Insert f A
(+( A
B (+( AB
W (+(* AB
(+(* ABC
(+( ABC*
( (+(-( ABC*
D (+(=( ABC* D
(+(-(/ ABC * D
(+(-(/ ABC * DE
o
(+(-(/A ABC* DE
F (+(-(/^ ABC * DEF
Afer Insert the node fthe tree is unbalanced so after apply the R-L rotation the ) (+( ABC * DEF A
final tree is (+(-* ABC * DEF ^/
G (+(-* ABC * DEF ^/G
(+ ABC* DEF ^/G*
ABC* DEF ^/G*
H ABC* DEF ^/G* -
ABC * DEF ^/G*-H*+
o Reverse polish notation
+1
1
3
1
4
0
5
0 i |13 |814
20 0
000 Here node was already full 50 after insert 8, is splitted
it into 2 node and 7 is the
300 1
10 median key.
4|1 0-0 0 1
7 13
13
14 17 48 17 20
Insert 13 5 811
13 splitted into 2 nodes
was already full
so after insert 13, It is and 131a
|7 112 1416 18 19 23 24 25 26
Here node After delete the node 23
the median key.
13
Insert 6, 23, 12, 20
7
13 4 8 17 20
12
14 16
2526| 1819 | 24
|1|35 |6 811 14| 17 23 26
Q.2. (6) Write algorithm/program of depth first search for traversal of graph?
L
Here node was already full, so it is splitted into 2 nodes and 20 is the median Ans. Step 1: Set status = 1 (ready state) for each node in G.
Insert 4 Step 2 :Push the starting node on the stack and set its status =2 (writing state).
A
E, X, Y, Z and its hash address U(K): 4, 8, 2, 11, 4, 11, 5, 1 resp. How file F will
appear in memory when 8records are entercd into table T in above order using
47 13 2o
linear probing and quadratic probing collision resolution technique? Find
average successful search probes (S) and average unsuccessful search probes
1|3|5|6 8 11 12 14 16
17 18 23 24 25 26 (S) and average unsucccssful search probes (U) also for both? (6)
Insert 19 Ans.
Record A, B. C. D. X, Y. Z E
13
H () 4, 8, 2, 11, 4. 11, 5, 1
Suppose the 8 records are entered into the table T in above order using the liner
|47
17 20 probing and Quadratic probing collision resolution technique then the file F will appear
in memory as follows.
1 3
|56 |8 11 12 14 16
Table T: X, C, A. E. Y B. D
18| 19 23|
24 25 26 Address: 1 2, 3. 4. 5. 6. 7. 8, 9, 10, 11
Structure
Semester, Data
Third
address Hk))=5, the record not
14-2015 with hash is
of a previous collisionaBsigned
record E because
only filled by I.P. University-(B.Tech.-Akash Books
Although Yis the already been at T4,. 2015-15
has
since T I5] appear in T(1). followe: Ans. () Division Method: Choose a prime no. M close to 99, such as M= 97 Then.
to T{5), not successful search
SimilarlyZ does probesfor a H (9614) = 11, H(5882) = 62 H (1825) - 79
average no. S of 1+1+1+1+2+2+2+3
The That is dividing 9614 by 97 gives a remainder 11. dividing 5882 by 97 gives a remainder
8 62 and so on. In the case that the memory address begin with 01l rather than 00, we
choose that the function H(k) = k (mod M) + 1 to obtain:
(9614) = 11 +1= 12, H (5882) = 62 + 1 = 63 H (1825) - 79 + 1 = 80
H
1-1.6
8 (it) Midsquare Method:
folloure
unsuccessful search
probes for àn K 9614 5882 1825
average no. U
of
The
7+6+5+4+3+2+l+2+1+l+8 92428996 34597924 3330625
11 H(%) 28 97 06
Observe 4th and 5th digit are choosen for Hash address.
40 =3.6
= (iiü) Folding Method: Choping the keys Kinto 1, 2, 1 digits and add then. So the
11
'address will be:
no. of probes to find each of he 8 records, and thesecondsum
The first sum adds the 11 locatione (9614) = 9 + 61 +4 = 74
H
(+(-* ABC
DEF^/
G (+(-* ABC DEF
(2 ^/G
Q.1. (c)Number of nodes in a complete tree is 1000000. Find its depth? (+
n. ABC * DEF ^/G*
Ans. The depth ofcomplete binary tree is log(n) where no. of nodes is So the depth
^G -
(+ *
of complete binary tree which has the 1000000 nodes is. ABC *
DEF *
H (+*
log (1000000) = 6 ABC* DEF ^/G
Q.2. (a) Write a program/algorithm
to evaluatea postix expression using ABC DEF
^/G-H*+
stack? Consider the following infix expression and convert into postfix Reverse polish notation
+ (2+3)
expression using stack. (A (B"C-(D\E ^F)*G)*H)
Ans. Algorithm for Evaluation of Postfix Expression Q.2. (b) Write a proccdure/program to reversc a
singly linked list without
using any more memory?
Create an empty stack and start scanning the postfix expression from left to right. (5)
Ans. Refer Q.2. (a) End Term Examination 2016.
•If the element is an operand, push it into the stack.
Q.3. (a) Suppose multidimensional arrays A are dcclared as A (-2.2,
•If the element is an operator 0, pop tyice and getA and B respectively. Calculate 2.22) and B(1:8, -5:5,-10:5) stored in column andB
BOA and push it back to the stack. major order. (2+2+3)
(i) Find the length of each dimcnsional ofA and B
• When the expression is ended, the value in the stack is the final answer.
(iü) The number of elements in A und B.
Character Stack Reverse polish Notatic Consider the clements B[3, 3, 3] in B. Find the effective indiccs E1, E2,
(iüi)
Scanned Postfix Notation E3 and the address of the elcment ussuming Busc (b) =400 and
there are w=4
words per memory location.
A
Ans. () The length of a dimension is obtained by:
( A
Length = upper bound- Lower bound + 1
+ (+ A
Hence the length Li of the dimensions ofA are:
(+( A
Ll = 2-(-2) + l=5 and L2 = 22-2+l=21
B (+( AB = = = 16
Ll 8-1+l 8, L2 =5-(-5) + 1+11, L35 -(-10) + 1
(+(* AB (ii) Accordingly A has 5*21 = 105 elements and B has 8*11*16 = 140S elements,
(+ (* ABC (iüi) The effective index Ei is obtained from Ei = ki-LB, where ki is the given index
and LB is the lower bound.
(+( ABC*
Hence El =3-1= 2, E2 = 3 -(-5) = E3 = 3-(-10) = 13
(+(-( ABC*
Considering B is stored in column-major order, the address of B [3,3,3] will be
D
(+(-( ABC* D caleulated as.
(+(-0 ABC * D E3L2 = 13*11 = 143, E2L2 + E2 = 143+8 = 151
Ans.
Location.
Deletion ofnode at given
underflow and stop. Insert y
ICFIRST NULL then write o
Step 1
azb,ge,x,d, e, v,f
w,
(2+6) o(a) 2)+2
Ans. The first balanced binary search tree or height balancing tree was the AVL
tree with has an additional balancing condition. The simplest idea is to require that the
left and right subtrees have the same height, so height balancing tree is required.
AVL tree of nodes- a, z, 5, y, c, z, d, u, e, t,f.
Creation ofAVL Tree There is Balance factor of z is +2 so after L-L rotation the tree is -
Nodes: a,z, b,y. c, z, d, u, e, ,f
Insert c
o
Insert z
Insertx
Insert z
Structure
Semester, Data
Third
So after L-R Totation the tree is-
I.P. University-(B.Tech)-Akash
6-2016
Balance factor
ofbis-2 Books
2016-7
There is the Insert e
C)
+1 (b O-2
o3)
+1
Insert d
Insert U
o
+2
Insert u
+16) (w
After Insertion of w the Balance factor is unbalanced so after applying the R
rotation the tree is
o -20
20
+1
After Insert the node v the tree is unbalanced so after apply the R.Rrotation the
tree is
Structuro
Semester, Data
Third
Insert/
W*1
+10
o)
o
so after
After Insert the node f the tree is unbalanced apply the. R-L rotation
te
final tree is
a o
Q4. (b) Following sequence gives
the preorder and inorder of the Binar
Tree T.
PREORDER :
ABDGCEHIF
INORDER : DGBAHEICE
Construct a binary
tree for the above sequence.
Ans. PREORDER:ABDGCEHIF
Structura
LData
Semester,
Third
circular
queue with N= 5.
following
=3. Front
Insert 20, Rear
=
e 0.
Considerthef
4.
32-2016
Example: Front=0.
FIRST TERM EXAMINATION [SEPT. 2017]
Initially,
Rear=0, Front
THIRD SEMESTER (B.TECH]
10 50
1.
DATA STRUCTURES (ETCS-209]
20 I3 Rear
Time: 1% hrs. MM.:30
Note:Q.l is compulsory. Attmept any two questions from the remaining:
Q1.Attempt all parts:
5. Insert 70, Rear =4, Front Q.1. (a) Convert the given infix into post-fix expression.
Demonstrate the
= 1,
Front =1. steps of conversion.
Rear 2
Insert 10. Front (2)
2.
2 10 50 a+b*- (de^)*g)*h a
+ (b*
Rear Ans. Infix into Postfix expression of c-(d/e^f)*g)*h:
10
Front 20 Character Scanned Stack Postfix Notation
70
Rear 4 +
+( a
6 Delete front, Rear = 4, Front = 2.
= 1. b +( ab
=2, Front
50, Rear
3. Insert +(* ab
Front
1 2 Rear 50 +(* abc
50
Front 10
+( abc*
20
( abc*
70 abc*d
Rear 4 abc*d
e +(/ abc*de
abc*de
f +^ abc*def
) +( abe*defN
+(* abc*def
+(-* abc*def^g
abc*def^g*.
abc*def^g*
abc*def^g*-h
abcdef/g*-h*+
Q1. (6) What is the maximum height of any AVLtrees with 7 nodes? Assuming
height is 0 for a tree with single node. (2)
Ans. The maximum height of any AVL-tree with 7 nodes is 3.
AVL trees are binary trees with the following restrictions.
1) the height difference of the children is at most 1.
Fron
5 6
4 Insert D
(ü)AddP R
2
1
N
M
Rear
Front
Insert G
two elements
(ii) Delete 3
4 5 6
1
D
Rear Insert T
Front
(iv) Add Q, R, S
3 4 5 6
1 2
R S P
R
1
m
2 3 4 5 6
Q R
P
Rear
Q.3. (6) Insert Front
the following elements Insert M
binary search tree: in alphabetical order
into an e
J, R, D, G, T,E,M, H, P, AF,Q
1.Find the final
treeT
Z.
Find the post-order traversal of l
Data Structures
Thind Semester,
62017 LP.University-(B
Toch.-Akash
Benka
2017-7
Insert H
Insert Q
(i)
HDBG HDBG
E
CK'
(iv)
(M)
Insert F
BG
Insert 2 Rebalancing
After
Insert
2
Rebalancing
Ater
Insert 16
Insert 4
After Rebalancing
Insert 5
16)
Insert 15
After Rebalancing
16)
(15)0
Structures
Semester, Data
Third END TERM EXAMINATION [DEC. 2017]
10-2017
THIRD SEMESTER [B.TECH)
Insert 14 DATA STRUCTURES [ETCS-2091
2 Time:3hrs. M.M.:75
16
Note:Attempt any five questions including Q.No. 1. Which
is compulsory. Select one
each unit
questionfrom
Whatiis an Abstract Data Type (ADYT)? (2.5)
Q.1. (a)
Data Types
Ans. Abstract
DData type (ADT) is a
type (or class) for objects whOse behayior is defined
Abstract
a set
of value and of operations.
Tis: set
finaltree by a
Rebalancingthe dofnition of ADT only mentions what operations are to be performed but not
After operations will be implemented. It does notspecify how data will be organized
how these called
memory andl algorithms will be used for implementing the operations..Itis
what
process of providing
in " because it gives. an implementation independent view. The
"abstract
2 and hiding the details is known
essentials
as abstraction.
onlythe
The user of data type need not know that
data type is implemented, for example,
bave been using int, float, char data types only with the knowledge with values that
on them without any idea of how these
n take and operations that can be performedto
16) So a user only needs know what a data type can do but not
types are
implemented.
how it will do it.
We can think of ADT as a black box which hides the
inner structure and design of
three ADTs namely List ADT, Stack ADT, Queue ADT.
the type. Nowwe'll
data define
(2.5)
Q.1. (6)What is a self-referential structure?
to create data structures like linked lists,
Ans. A self referential structure is used
of this kind of structure:
stacks, etc. Following is an example
struct struct _name
datatype datatypename;
struct_name * pointer_name;
to
one of the data structures which refer to the pointer
A self-referential structure is to
same type. For example, a linked list is supposed
(points) to another structure of the a is being pointed, which is of
structure. The next node of node
be a self-referential data
the same struct type. For example,
(
typedef struct listnode
void *data;
struct listnode *next;
linked_list;
)
32-2017
Thble
Final
6 FIRST TERM EXAMINATION [SEP. 2018]
Probing 3 4234
(2)Linear 1
2
2341
|2839/430 THIRD SEMESTER [B.TECHJ
/3920
397 22 DATA STRUCTURES [ETCS-209]
Time:1.5 hrs. M.M. :30
collide at 3 mod 7 Note: Q. No. l is compulsory. Attempt any two more Questions from the rest.
Value (430)is combuted 8s: 7+ 1J
probe is = (430mod mod 7=4 Q1.Attempt all parts:
so the next H430, 1) mod7 =4 steps. (2)
= (3+l] (a) Calculate the postfix expression using stack also demonstrate the
5, 3, +8,2, ,*
so again: mod 7+ 2]
mod 7=5 mod 7
=5
Dot free = [430 Ans.
But the TI4]is
H(430, 2)
Symbol Scanned Stack Operation (B opA)
collide at 5. 5 5
value (397) is
Now ihe 3 5,3
Bo the next
probe is: 1) = 6 [5 +3] (A =3, B
= 5)
H(397, 8
8 8.8
next probe is:
not free so 2
But six is (397, 2) =0
H
8, 8, 2
2, B= 8)
collide at 0.
8,6 [8-2] (A=
(3920)is [8*6] (A=6, B 8]
=
side
dimensioal to Doubly or Circular linked i Start
ATr C
tidinersion:al
queues
Enensiocal or types of (2
expiain different
QLBrietyqueoe: retained and dataleawes
10 30
3
ret data rext
2
Decble ended
qoeae Degaese Slar te quece. f
Ans. Insert
R
Insert
Insert P
D
Insert
Insert Insert A
B
Insert B G
M
Insert
B
Insert E
B:
Insert
Insert M
(V)
B
BG
We first perform the left rotation on the left
E subtree of C. This makes A, the left subtree ofB.
heln t
This is final tree T
different types of rotations in AVL tree with the
Q4 b) Explain (5)
suitable examples.
Ans. AVL Rotations four kinds of rotationg
To balance itself, an AVL tree may perform the following
• RR rotation Node C is still unbalanced, however now, it is
•
Lrotation because of the left-subtree of the left-subtree.
• LR rotation
• RL rotation a
R-R Rotation: Ifa tree becomes unbalanced, when node is inserted
into the right
a
subtree of the right subtree, then we perform single left rotation
2
A C
0 We shall now right-rotate the tree,
B making B the new root node of this
subtree. C now becomes the right subtree of
its own left subtree.
left rotation.
R-L
Rotation: The followed by
rotation Action Q1.Attempt all:
combination ofright
(a) What is bucket Hashing? (25)
State insertedinto ttheleft subtree
A node has been This
makes A, an Ans. Hash buckets are used to apportion data items for sorting or lookup purposes
subtree.
of the right The aim of this work is to weaken the linked lists so that searching for a specifc item
node with balance factor 9 can be accessed within a shorter timeframe.
unbalanced
Keys Hash Funcion Bucket
123-9876
Mark BelH
123-7654
First, we perform the
right rotation
subtree ae
along C node, making C the right John Reese
B. Now, B becomes tL
its own left subtree
of A.
right subtree 123-1234
Michelle Curtis -
IFCircular Queue is empty then we can not delete an element from Circular Queue.
This condition is known as "Underflow"
Q. 1. (c) What is Header Linked list? (2.5)
The tree is now balanced. Ans. A Header linked list is one more variant of linked list. In Header linked list,
wa have a special
node present at the beginning of the linked list. This special node is
A used to store number ofnodes present in the linked list. In other linked list variant, if
We want to know
the size of the linked list we use traversal method. But in Header
linked list, the size of the linked list is stored in its header itself.