Sie sind auf Seite 1von 42

EE2204 DATA STRUCTURES AND ALGORITHMS 3 0 0 3

Unit 1
Part a
1. What is !ant "# an a"stra$t %ata t#&!'
An ADT is a set of operation. Abstract data types are mathematical
abstractions.Eg.Objects such as list, set and graph along their operations can be
viewed as ADTs.
2. What ar! th! (&!rati(ns () ADT'
nion, !ntersection, si"e, complement and find are the various operations of
ADT.
3. What is !ant "# *ist ADT'
#ist ADT is a se$uential storage structure. %eneral list of the form a&, a',
a(.)., an and the si"e of the list is *n. Any element in the list at the position ! is
defined to be ai, ai+& the successor of ai and ai,& is the predecessor of ai.
4. What ar! th! +ari(,s (&!rati(ns %(n! ,n%!r *ist ADT'
a. -rint list
b.!nsert
c..a/e empty
d.0emove
e.1e2t
f.-revious
g.3ind /th
-. What ar! th! %i))!r!nt .a#s t( i&*!!nt *ist'
a. 4imple array implementation of list
b.#in/ed list implementation of list
/. What ar! th! a%+anta0!s in th! arra# i&*!!ntati(n () *ist'
a. -rint list operation can be carried out at the linear time
b. 3ind 5th operation ta/es a constant time
1. What is a *in2!% *ist'
#in/ed list is a /ind of series of data structures, which are not necessarily
adjacent in memory. Each structure contains the element and a pointer to a record
containing its successor.
3. What is a &(int!r'
-ointer is a variable, which stores the address of the ne2t element in the list.
-ointer is basically a number.
4. What is a %(,"*# *in2!% *ist'
!n a simple lin/ed list, there will be one pointer named as *1E6T
-O!1TE0 to point the ne2t element, where as in a doubly lin/ed list, there will be
two pointers one to point the ne2t element and the other to point the previous
element location.
10. D!)in! %(,"*! $ir$,*ar*# *in2!% *ist'
!n a doubly lin/ed list, if the last node or pointer of the list, point to the first
element of the list, then it is a circularly lin/ed list.
11. What is th! n!!% )(r th! h!a%!r'
7eader of the lin/ed list is the first element in the list and it stores the
number of elements in the list. !t points to the first data element of the list.
12. List thr!! !5a&*!s that ,s!s *in2!% *ist'
a. -olynomial ADT
b.0adi2 sort
c..ulti lists
13. Gi+! s(! !5a&*!s )(r *in!ar %ata str,$t,r!s'
a. 4tac/
b.8ueue
14. What is a sta$2'
4tac/ is a data structure in which both insertion and deletion occur at one
end only. 4tac/ is maintained with a single pointer to the top of the list of
elements. The other name of stac/ is #ast,in ,3irst,out list.
1-. Writ! &(st)i5 )r( () th! !5&r!ssi(n 6A789C7D'
A,9+:,D+
1/. H(. %( #(, t!st )(r an !&t# :,!,!'
To test for an empty $ueue, we have to chec/ whether 0EAD;7EAD
where 0EA0 is a pointer pointing to the last node in a $ueue and 7EAD is a
pointer that pointer to the dummy header. !n the case of array implementation of
$ueue, the condition to be chec/ed for an empty $ueue is 0EAD<30O1T.
11.What ar! th! &(st)i5 an% &r!)i5 )(rs () th! !5&r!ssi(n'
A+9=>:,D?@>-,0?
-ostfi2 formA A9:D,=-0,@+
-refi2 formA +A@=9,:D,-0
13. E5&*ain th! ,sa0! () sta$2 in r!$,rsi+! a*0(rith i&*!!ntati(n'
!n recursive algorithms, stac/ data structures is used to store the return
address when a recursive call is encountered and also to store the values of all the
parameters essential to the current state of the procedure.
14. Writ! %(.n th! (&!rati(ns that $an "! %(n! .ith :,!,! %ata str,$t,r!'
8ueue is a first B in ,first out list. The operations that can be done with
$ueue are addition and deletion.
20. What is a $ir$,*ar :,!,!'
The $ueue, which wraps around upon reaching the end of the array is called
as circular $ueue.
Unit 1 &art 8
1. E5&*ain th! *in2!% *ist i&*!!ntati(n () *ist ADT in D!tai*'
a. Definition for lin/ed list
b. 3igure for lin/ed list
c. 1e2t pointer
d. 7eader or dummy node
e. various operations
f. E2planation
g. E2ample figure
h. :oding
2. E5&*ain th! $,rs(r i&*!!ntati(n () *in2!% *ist'
a. Definition for lin/ed list
b. 3igure for lin/ed list
c. 1e2t pointer
d. 7eader or dummy node
e. various operations
f.E2planation
g.E2ample figure
h.:oding
3. E5&*ain th! +ari(,s a&&*i$ati(ns () *in2!% *ist'
a. -olynomial ADT
Operations
:oding
3igure
b. 0adi2 4ort
E2planation
E2ample
c. .ultilist
E2planation
E2ample figure
4. E5&*ain th! *in2!% *ist i&*!!ntati(n () sta$2 ADT in %!tai*'
a. Definition for stac/
b. 4tac/ model
c.3igure
d.-ointer,Top
e.Operations
f.:oding
g.E2ample figure
-. E5&*ain th! arra# i&*!!ntati(n () :,!,! ADT in %!tai*'
a. Definition for stac/
b. 4tac/ model
c. 3igure
d. -ointer,30O1T, 0EA0
e. Operations
f.:oding
g.E2ample figure
Unit 2; 3
Part A
1. D!)in! n(n9*in!ar %ata str,$t,r!
Data structure which is capable of e2pressing more comple2 relationship
than that of physical adjacency is called non,linear data structure.
2. D!)in! tr!!'
A tree is a data structure, which represents hierarchical relationship between
individual data items.
3. D!)in! *!a)'
!n a directed tree any node which has out degree o is called a terminal node
or a leaf.
4. What is !ant "# %ir!$t!% tr!!'
Directed tree is an acyclic diagraph which has one node called its root with
in degree o while all other nodes have in degree !.
-. What is a (r%!r!% tr!!'
!n a directed tree if the ordering of the nodes at each level is prescribed then
such a tree is called ordered tree.
/. What ar! th! a&&*i$ati(ns () "inar# tr!!'
9inary tree is used in data processing.
a. 3ile inde2 schemes
b. 7ierarchical database management system
1. What is !ant "# tra+!rsin0'
Traversing a tree means processing it in such a way, that each node is
visited only once.
3. What ar! th! %i))!r!nt t#&!s () tra+!rsin0'
The different types of traversing are
a. -re,order traversal,yields prefi2 from of e2pression.
b. !n,order traversal,yields infi2 form of e2pression.
c. -ost,order traversal,yields postfi2 from of e2pression.
4. What ar! th! t.( !th(%s () "inar# tr!! i&*!!ntati(n'
Two methods to implement a binary tree are,
a. #inear representation.
b. #in/ed representation
10. D!)in! &r!9(r%!r tra+!rsa*'
-re,order traversal entails the following stepsC
a. -rocess the root node
b. -rocess the left subtree
c. -rocess the right subtree
11.D!)in! &(st9(r%!r tra+!rsa*'
-ost order traversal entails the following stepsC
a. -rocess the left subtree
b. -rocess the right subtree
c. -rocess the root node
12. D!)in! in 9(r%!r tra+!rsa*'
!n,order traversal entails the following stepsC
a. -rocess the left subtree
b. -rocess the root node
c. -rocess the right subtree
13. What is a "a*an$! )a$t(r in A<L tr!!s'
9alance factor of a node is defined to be the difference between the height
of the nodeDs left subtree and the height of the nodeDs right subtree.
14. What is !ant "# &i+(t n(%!'
The node to be inserted travel down the appropriate branch trac/ along the
way of the deepest level node on the branch that has a balance factor of +& or ,& is
called pivot node.
1-. What is th! *!n0th () th! &ath in a tr!!'
The length of the path is the number of edges on the path. !n a tree there is
e2actly one path form the root to each node.
1/. D!)in! !5&r!ssi(n tr!!s'
The leaves of an e2pression tree are operands such as constants or variable
names and the other nodes contain operators.
11. What is th! n!!% )(r hashin0'
7ashing is used to perform insertions, deletions and find in constant
average time.
13. D!)in! hash ),n$ti(n'
7ash function ta/es an identifier and computes the address of that identifier
in the hash table using some function.
14. List (,t th! %i))!r!nt t#&!s () hashin0 ),n$ti(ns'
The different types of hashing functions are,
a. The division method
b. The mind s$uare method
c. The folding method
d. .ultiplicative hashing
e. Digit analysis
20. What ar! th! &r("*!s in hashin0'
a. :ollision
b. Overflow
21. What ar! th! &r("*!s in hashin0'
Ehen two /eys compute in to the same location or address in the hash table
through any of the hashing function then it is termed collision.
Unit 2 an% 3 &art 8
1. E5&*ain th! %i))!r!nt tr!! tra+!rsa*s .ith an a&&*i$ati(n'
a. !n order
E2planation with an e2ample
3igure
b. -reorder
E2planation with an e2ample
3igure
c. -ost order
E2planation with an e2ample
3igure
2. D!)in! "inar# s!ar$h tr!!' E5&*ain th! +ari(,s (&!rati(ns .ith an !5a&*!'
a. Definition
b. 3igure for binary search tree
c. Operations
d.:odings
e.E2planation
f.E2ample
3. D!)in! A<L tr!!s' E5&*ain th! LL= RR= RL= LR $as! .ith an !5a&*!'
a. Definition
b. ##, 00, 0#, #0 case
c.3igure
d.E2ample
e.E2planation
4. D!)in! &ri(rit# :,!,!' E5&*ain th! "asi$ h!a& (&!rati(n .ith an !5a&*!'
a. Definition
b. 9asic operation
!nsert
Delmin
Delma2
c. :oding
d. E2planation
e.E2ample
-. E5&*ain an# t.( t!$hni:,!s t( (+!r$(! hash $(**isi(n'
a. 4eparate chaining
E2ample
E2planation
coding
b. Open addressing
#inear probing
8uadratic probing
Unit 4
Part A
1. D!)in! Gra&h'
A graph % consist of a nonempty set F which is a set of nodes of the graph,
a set E which is the set of edges of the graph, and a mapping from the set for edge
E to a set of pairs of elements of F. !t can also be represented as %;>F, E?.
2. D!)in! a%>a$!nt n(%!s'
Any two nodes which are connected by an edge in a graph are called
adjacent nodes. 3or E is associated with a pair of nodese2ample, if and edge 2
>u,v? where u, v F, then we say that the edge 2 connects the nodes u and v.
3. What is a %ir!$t!% 0ra&h'
A graph in which every edge is directed is called a directed graph.
4. What is a ,n%ir!$t!% 0ra&h'
A graph in which every edge is undirected is called a directed graph.
-. What is a *((&'
An edge of a graph which connects to itself is called a loop or sling.
/. What is a si&*! 0ra&h'
A simple graph is a graph, which has not more than one edge between a
pair of nodes than such a graph is called a simple graph.
1. What is a .!i0ht!% 0ra&h'
A graph in which weights are assigned to every edge is called a weighted
graph.
3. D!)in! (,t %!0r!! () a 0ra&h'
!n a directed graph, for any node v, the number of edges which have v as
their initial node is called the out degree of the node v.
4. D!)in! in%!0r!! () a 0ra&h'
!n a directed graph, for any node v, the number of edges which have v as
their terminal node is called the indegree of the node v.
10. D!)in! &ath in a 0ra&h'
The path in a graph is the route ta/en to reach terminal node from a starting
node.
11. What is a si&*! &ath'
A path in a diagram in which the edges are distinct is called a simple path.
!t is also called as edge simple.
12. What is a $#$*! (r a $ir$,it'
A path which originates and ends in the same node is called a cycle or
circuit.
13. What is an a$#$*i$ 0ra&h'
A simple diagram which does not have any cycles is called an acyclic
graph.
14. What is !ant "# str(n0*# $(nn!$t!% in a 0ra&h'
An undirected graph is connected, if there is a path from every verte2 to
every other verte2. A directed graph with this property is called strongly
connected.
1-. Wh!n is a 0ra&h sai% t( "! .!a2*# $(nn!$t!%'
Ehen a directed graph is not strongly connected but the underlying graph is
connected, then the graph is said to be wea/ly connected.
1/. Na! th! %i))!r!nt .a#s () r!&r!s!ntin0 a 0ra&h'
a. Adjacency matri2
b. Adjacency list
11. What is an ,n%ir!$t!% a$#$*i$ 0ra&h'
Ehen every edge in an acyclic graph is undirected, it is called an undirected
acyclic graph. !t is also called as undirected forest.
13. What ar! th! t.( tra+!rsa* strat!0i!s ,s!% in tra+!rsin0 a 0ra&h'
a. 9readth first search
b. Depth first search
14. What is a ini, s&annin0 tr!!'
A minimum spanning tree of an undirected graph % is a tree formed from
graph edges that connects all the vertices of % at the lowest total cost.
20. What is NP'
1- is the class of decision problems for which a given proposed solution
for a given input can be chec/ed $uic/ly to see if it is really a solution.
Unit 4 &art 8
1. E5&*ain th! +ari(,s r!&r!s!ntati(n () 0ra&h .ith !5a&*! in %!tai*'
a. Adjacency matri2
3igure
E2planation
Table
b. Adjacency list
3igure
E2planation
Table
2. D!)in! t(&(*(0i$a* s(rt' E5&*ain .ith an !5a&*!'
a. Definition
b. E2planation
c. E2ample
d. Table
e. :oding
3. E5&*ain Di>2stra?s a*0(rith .ith an !5a&*!'
a. E2planation
b. E2ample
c. %raph
d. Table
e. coding
4.E5&*ain Pri?s a*0(rith .ith an !5a&*!'
a. E2planation
b. E2ample
c. %raph
d. Table
e. :oding
-. E5&*ain @r,sha*?s a*0(rith .ith an !5a&*!'
a. E2planation
b. E2ample
c. %raph
d. Table
e. :oding
Unit <
Part A
1. Writ! %(.n th! %!)initi(n () %ata str,$t,r!s'
A data structure is a mathematical or logical way of organi"ing data in the
memory that consider not only the items stored but also the relationship to each
other and also it is characteri"ed by accessing functions.
2. What is !ant "# &r("*! s(*+in0'
-roblem solving is a creative process, which needs systemi"ation and
mechani"ation.
3. Gi+! )!. !5a&*!s )(r %ata str,$t,r!s'
4tac/s, 8ueue, #in/ed list, Trees, graphs
4. What is &r("*! %!)initi(n &has!'
The first step in solving a problem is to understand problem clearly. 7ence,
the first phase is the problem definition phase. That is, to e2tract the tas/ from the
problem statement. !f the problem is not understood, then the solution will not be
correct and it may result in wastage of time and effort.
-. D!)in! A*0(rith'
Algorithm is a solution to a problem independent of programming
language. !t consist of set of finite steps which, when carried out for a given set of
inputs, produce the corresponding output and terminate in a finite time.
/. D!)in! Pr(0ra'
4et of instructions to find the solution to a problem. !t is e2pressed in a
programming language in an e2plicit and unambiguous manner.
1. M!nti(n h(. sii*ariti!s a(n0 th! &r("*!s ar! ,s!% in &r("*! s(*+in0'
This method is used to find out if a problem of this sort has been already
solved and to adopt a similar method in solving the problem. The contribution of
e2perience in the previous problem with help and enhance the method of problem
for the current problem.
3. What is .(r2in0 "a$2.ar% )r( th! s(*,ti(n'
Ehen we have a solution to the problem then we have to wor/ bac/ward to
find the starting condition. Even a guess can ta/e us to the starting of the problem.
This is very important to systemati"e the investigation to avoid duplication of our
effort.
4. M!nti(n s(! () th! &r("*! s(*+in0 strat!0i!s'
The most widely strategies are listed below
Divide and con$uer
9inary doubling strategy
Dynamic programming
10. What is %i+i%! an% $(n:,!r !th(%'
The basic idea is to divide the problem into several sub problems beyond
which cannot be further subdivided. Then solve the sub problems efficiently and
join then together to get the solution for the main problem.
11. What ar! th! )!at,r!s () an !))i$i!nt a*0(rith'
a. 3ree of ambiguity
b.Efficient in e2ecution time
c.:oncise and compact
d.:ompleteness
e.Definiteness
f.3initeness
12. List %(.n an# )(,r a&&*i$ati(ns () %ata str,$t,r!s'
a. :ompiler design
b.Operating 4ystem
c.Database .anagement system
d.1etwor/ analysis
13. What is "inar# %(,"*in0 strat!0#'
The reverse of binary doubling strategy, i.e. combining small problems in to
one is /nown as binary doubling strategy. This strategy is used to avoid the
generation of intermediate results.
14. Wh!r! is %#nai$ &r(0rain0 ,s!%'
Dynamic programming is used when the problem is to be solved in a
se$uence of intermediate steps. !t is particularly relevant for many optimi"ation
problems, i.e. fre$uently encountered in Operations research.
1-. D!)in! t(&9%(.n %!si0n'
Top,down design is a strategy that can be applied to find a solution to a
problem from a vague outline to precisely define the algorithm and program
implementation by stepwise refinement.
1/. M!nti(n th! t#&!s () ",0s that a# aris! in a &r(0ra'
The different types of bugs that can arise in a program are
4yntactic error
4emantic error
#ogical error
11. What is &r(0ra t!stin0'
-rogram testing is process to ensure that a program solves the smallest
possible problem, when all the variables have the same value, the biggest possible
problem, unusual cases etc.
13. What is &r(0ra +!ri)i$ati(n'
-rogram verification refers to the application of mathematical proof
techni$ues, to verify that the results obtained by the e2ecution of the program with
arbitrary inputs are in accord with formally defined output 4pecifications.
14. H(. .i** #(, +!ri)# "ran$h!s .ith s!0!nts'
To handle the branches that appear in the program segments, it is necessary
to set,up and proves verification conditions individually.
20. What is &r(() () t!rinati(n'
To prove that a program accomplishes its stated objective in a finite number
of steps is called program termini nation. The prooft of termination is obtained
directly from the properties of the interactive constructs.
Unit < &art 8
1. E5&*ain t(&9%(.n %!si0n in %!tai*'
a. Definition
b.9rea/ing a problem in to sub problems
c.:hoice of a suitable data structure
d.:onstructions of loops
e.Establishing initial conditions for loops
f.3inding the iterative construct
g.Terminations of loops
2. What ar! th! st!&s ta2!n t( i&r(+! th! !))i$i!n$# () an a*0(rith'
a. Definition
b.0edundant computations
c.0eferencing array elements
d.!nefficiency due to late termination
e.Early detection of desired output conditions
f.Trading storage for efficiency gains
3. D!si0n an a*0(rith )r( sin! ),n$ti(n $(&,tati(n. E5&*ain it .ith an
!5a&*!'
a. Algorithm development
b.Algorithm description
c.-ascal implementation
d.Application
4. D!si0n an a*0(rith )(r r!+!rsin0 th! %i0it () an int!0!r. E5&*ain it .ith an
!5a&*!'
a. Algorithm development
b.Algorithm description
c.-ascal implementation
d.Application
-. D!si0n an a*0(rith )(r "as! $(n+!rsi(n. E5&*ain it .ith an !5a&*!'
Algorithm development
Algorithm description
-ascal implementation
Application
8.E A 8.T!$h DEGREE EBAMINATION=MACADUNE 200/
THIRD SEMESTER
C(&,t!r S$i!n$! an% En0in!!rin0
CS11-1 6 DATA STRUCTURES
PART A 6 E10 B 2 F 20 ar2sG
1.D!)in! ADT
An ADT is a set of operation. Abstract data types are mathematical
abstractions.Eg.Objects such as list, set and graph along their operations can be
viewed as ADTDs.
2.List (,t th! (&!rati(ns () th! *ist ADT'
!nsert an item, Delete an item, find, Display
3. D!)in! %!:,!,!.
A de$ue >short for double-ended queue? is an abstract data structure for
which elements can be added to or removed from the front or bac/. This differs
from a normal $ueue, where elements can only be added to one end and removed
from the other
4. E5&*ain th! r!&r!s!ntati(ns () &ri(rit# :,!,!.
sing 7eap structure, sing #in/ed #ist
1. C(&ar! th! +ari(,s hashin0 t!$hni:,!s.
&? 4eparate chaining B #in/ed list implementation
'? Open Addressing, Array implementation
2. List (,t th! st!&s in+(*+!% in %!*!tin0 a n(%! )r( a "inar# s!ar$h tr!!.
&. t has no right hand child node t,Gr ;; "
'. t has a right hand child but its right hand child node has no left sub tree
t,Gr,Gl ;; "
(. t has a right hand child node and the right hand child node has a left hand
child node t,Gr,Gl H; "
3. E5&*ain th! t(&(*(0i$a* s(rt.
!t is an Ordering of vertices in a directed acyclic graph such that if there is a
path from vi to vj, then vj appears after vi in the ordering.
4. D!)in! NP har%
1- is the class of decision problems for which a given proposed solutionfor a
given input can be chec/ed $uic/ly to see if it is really a solution.
-. What is "inar# h!a&
!t is a complete binary tree of height h has between '
h and
'
h+&
,& node.

The value
of the root node is higher than their child nodes.
PART 8 6 E- B 1/ F 30 ar2sG
/. EiG Writ! a*0(riths )(r ADT (&!rati(ns )(r ins!rt a n(%! t( *in2!% *ist
To insert a new item after 9A

&? .odify pointer field of 1EE to point to :
'? .odify pointer field of 9 to point to 1EE

1EE1ODE,G1E6T;9,G1E6TC
9,G1E6T;1EE1ODEC
EiiG Writ! a*0(rith )(r %!*!t! a n(%! )r( *in2!% *ist
To delete an item coming after 9,

&? .odify pointer field of 9, to point to the node pointed by pointer of O#D
'? .odify pointer field of O#D as I >not to cause problem later on?
9,G1E6T;O#D,G1E6TC
30EE>O#D?C
12. EaG Writ! ADT r(,tin!s )(r sta$2 (&!rati(n. Writ! r(,tin!s )(r !+a*,atin0
a in)i5 !5&r!ssi(n
A stac/ is a #!3O >#ast,!n@3irst,Out? data structure. !tems are ta/en out of
the stac/ in the reverse order of their insertion. Ee can write an application that
evaluates an arithmetic e2pression using the #!3O storage policy of a stac/. The
evaluation procedure consists of two partsA &? converting an infi2 e2pression to the
postfi2 e2pression and '? evaluating the postfi2 e2pression to get its value.
1. In)i5 n(tati(n +s. &(st)i5 n(tati(n
!nfi2 notation
o A common mathematical notation is an infi2 notation.
o 9inary operators, such as +, ,, =, @, come in,between their operands.
o nary operators, such as B >a unary negation?, precede their operand.
o E2ampleA A + 9 = : + D @ E , A = :
-ostfi2 notation
o Each operator appears after its operands
o -arenthesis,free notation
o Evaluation can be done by scanning an e2pression once from left to
right. Therefore, a postfi2 e2pression is easier for a calculator >or
computer? to process.
o E2ampleA A 9 : = + D E @ + A : = ,
!nfi2 to postfi2 >paper and pencil?
&. 3ully parenthesi"e the e2pression so that each operator has a pair of
parentheses surrounding its operands.
'. .ove all operators so that they replace their corresponding right
parenthesis
(. Delete all parentheses.
> > > A + > 9 = : ? ?+ > D @ E ? ? , > A = : ? ?
2. Crit!ria that %!t!rin! th! (r%!r () (&!rat(r !+a*,ati(n
-recedence of arithmetic operatorsA
Operators -receden
ce
, >unary
minus?
(
=, @ '
+, , &
-arentheses overrule the precedence of operators.
!f the order is not indicated by parentheses, operators of higher precedence
are evaluated before those of lower precedence.
Operators of e$ual precedence are evaluated from left to right.
3. In)i5 t( P(st)i5
#ets first learn how to convert an infi2 e2pression to the postfi2 notation. An
infi2'postfi2 program, the convert method of the te2tboo/ pp. 'JK, ta/es an infi2
e2pression as a parameter and returns the corresponding postfi2 notation. The
method maintains one :haracter stac/ to store operators.
&? 5ey ideas of !nfi2'-ostfi2 algorithm
a? The operands in the postfi2 e2pression have the same order as they were
in the infi2 e2pression.
oE2ampleA L=>(,M+J?@&N L ( M B J + = &N @
oOperands are appended to postfi2 as they are read in.
oAn operand stac/ is not needed.
b? All operations between a set of matching parenthesis will be together in a
group within the postfi2 e2pression.
o E2ampleA K = >( B L? K ( L B = C K = >( B L + '? K ( L B ' + =
o push > onto the stac/ and if ? is encountered, pop off only operators
that are within the pair of matching parentheses and never pop
operators that is below the >.
c? The postfi2 e2pression handles operators according to the precedence
rulesA the higher precedence operator must be written firstC operators of
e$ual precedence should be written from left to right.
o E2ampleA K = ( + L K ( = L +C K + ( = L K ( L = +C ' + ( B L '
( + L B
o The current operator will be pushed onto the stac/ anyway because
we dont /now if it has a higher precedence than the following
operator.
o 9efore pushing the current operator, pop off the stac/ until the stac/
becomes empty or '? the top operator has a lower precedence than the
current operator. Then, push the current operator to the stac/.
2G In)i52P(st)i5 a*0(rith
Algorithm
!nitiali"e postfi2 to an empty 4tring9uilder.
&. !nitiali"e a stac/ of characters to hold the operators and left parentheses.
'. .hi*! there are more to/ens in the infi2 string
O
%et the ne2t to/en.
i) >the ne2t to/en is a left parenthesis?
-ush the to/en onto the stac/. based on the idea b?
!*s! i) >the ne2t to/en is an operand?
Append it to postfi2. based on the idea a?
!*s! i) >the ne2t to/en is an operator? similar to the processOperator method
of the te2tboo/
-op operators off the stac/ and append them to postfi2 until one of the three
things occursA
&? stac/ becomes empty or
'? the top is an operator with lower precedence or
3) the top is D>D based on the idea b?
-ush the to/en onto the stac/
!*s!
Discard the ne2t to/en which should be a right parenthesis.
-op operators off the stac/ and append them to postfi2 until the top is D>D.
-op and discard D>D. >!f no left parenthesis is encountered, then print an error
message indicating unbalanced parentheses, and halt?
P @@ while
K. -op any remaining operators on the stac/ and append them to postfi2. >There
should be no remaining left parentheses, otherwise the input e2pression did not
have balanced parenthesis.?
1oteA An e2ample of the while loop in the processOperator is
while >Hoperator4tac/.isEmpty>? QQ
operator4tac/.pee/>? H; D>D QQ
precedence>operator4tac/.pee/>?? G;precedence>the current operator??
O postfi2 ; postfi2 + operator4tac/.pop>? + R RC P
operator4tac/.push>the current operator?C
(? E2ample
( = 6 + >S B &' ? B T ( 6 = S &' B + T B
3. E+a*,atin0 P(st)i5 E5&r!ssi(ns
-ostfi2 e2pressionsA
-arentheses,free.
A space between two consecutive numbers.
Evaluation re$uires only one stac/, which is a stac/ of operands.
1o operator stac/ is re$uired because each operation is done as soon as it is
read.
'? Algorithm >the eval method of the te2tboo/?
&. :reate an empty stac/ of integers.
'. while there are more to/ens
O %et the ne2t to/en.
if >the ne2t to/en is an operand?
-ush the to/en onto the stac/.
else @@ the ne2t to/en is an operator
O -op the correct number for the operator from stac/.
Evaluate the operation.
-ush the result onto the stac/.
P
P
(. -op the stac/ and return the result.
&? E2ample
L ( ' = + K B L + &'
EORG
E"G EiG Writ! r(,tin!s )(r in&,t r!stri$t!% %!:,!,!.
Three functionsA
1GIns!rt Ri0ht 2GD!*!t! Ri0ht 3G D!*!t! L!)t
insertUright>?
O
int addedUitemC
if>>left ;; N QQ right ;; .A6,&? VV >left ;; right+&??
O
printf>R8ueue OverflowWnR?C
returnC
P
if >left ;; ,&? @= if $ueue is initially empty =@
O
left ; NC
right ; NC
P
else
if>right ;; .A6,&? @=right is at last position of $ueue =@
right ; NC
else
right ; right+&C
printf>R!nput the element for adding in $ueue A R?C
scanf>RXdR, QaddedUitem?C
de$ueUarrYrightZ ; addedUitem C
P@=End of insertUright>?=@
deleteUleft>?
O
if >left ;; ,&?
O
printf>R8ueue nderflowWnR?C
return C
P
printf>RElement deleted from $ueue is A XdWnR,de$ueUarrYleftZ?C
if>left ;; right? @=8ueue has only one element =@
O
left ; ,&C
right;,&C
P
else
if>left ;; .A6,&?
left ; NC
else
left ; left+&C
P@=End of deleteUleft>?=@
deleteUright>?
O
if >left ;; ,&?
O
printf>R8ueue nderflowWnR?C
return C
P
printf>RElement deleted from $ueue is A XdWnR,de$ueUarrYrightZ?C
if>left ;; right? @=$ueue has only one element=@
O
left ; ,&C
right;,&C
P
else
if>right ;; N?
right;.A6,&C
else
right;right,&C
P@=End of deleteUright>? =@
EiiG Writ! ADT (&!rati(n )(r $ir$,*ar :,!,!
OperationsA &?!nsertion '? Deletion
void add>int item,int $YZ,int .A6,int front,int rear?
O
rear++C
rear; >rearX.A6?C
if>front ;;rear?
O
printf>R:!0:#A0 8EE 3## R?C
returnC
P
else
O
c$YrearZ;itemC
printf>R
0ear ; Xd 3ront ; Xd R,rear,front?C
P
P
int del>int $YZ,int .A6,int front,int rear?
O
int aC
if>front ;; rear?
O
printf>R:!0:#A0 4TA:5 E.-TSR?C
return >N?C
P
else
O
front++C
front ; frontX.A6C
a;c$YfrontZC
return>a?C
printf>R
0ear ; Xd 3ront ; Xd R,rear,front?C
P
P
13. EaG Writ! r(,tin!s )(r ADT (&!rati(n () A<L tr!!.
Operations &?!nsertion '? Deletion
struct node =insert >int info, struct node =pptr, int
=htUinc?
O
struct node =aptrC
struct node =bptrC
if>pptr;;1##?
O
pptr ; >struct node =? malloc>si"eof>struct node??C
pptr,Ginfo ; infoC
pptr,Glchild ; 1##C
pptr,Grchild ; 1##C
pptr,Gbalance ; NC
=htUinc ; T0EC
return >pptr?C
P
if>info < pptr,Ginfo?
O
pptr,Glchild ; insert>info, pptr,Glchild, htUinc?C
if>=htUinc;;T0E?
O
switch>pptr,Gbalance?
O
case ,&A @= 0ight heavy =@
pptr,Gbalance ; NC
=htUinc ; 3A#4EC
brea/C
case NA @= 9alanced =@
pptr,Gbalance ; &C
brea/C
case &A @= #eft heavy =@
aptr ; pptr,GlchildC
if>aptr,Gbalance ;; &?
O
printf>R#eft to #eft 0otationWnR?C
pptr,Glchild; aptr,GrchildC
aptr,Grchild ; pptrC
pptr,Gbalance ; NC
aptr,Gbalance;NC
pptr ; aptrC
P
else
O
printf>R#eft to right rotationWnR?C
bptr ; aptr,GrchildC
aptr,Grchild ; bptr,GlchildC
bptr,Glchild ; aptrC
pptr,Glchild ; bptr,GrchildC
bptr,Grchild ; pptrC
if>bptr,Gbalance ;; & ?
pptr,Gbalance ; ,&C
else
pptr,Gbalance ; NC
if>bptr,Gbalance ;; ,&?
aptr,Gbalance ; &C
else
aptr,Gbalance ; NC
bptr,Gbalance;NC
pptr;bptrC
P
=htUinc ; 3A#4EC
P@=End of switch =@
P@=End of if =@
P@=End of if=@
if>info G pptr,Ginfo?
O
pptr,Grchild ; insert>info, pptr,Grchild, htUinc?C
if>=htUinc;;T0E?
O
switch>pptr,Gbalance?
O
case &A @= #eft heavy =@
pptr,Gbalance ; NC
=htUinc ; 3A#4EC
brea/C
case NA @= 9alanced =@
pptr,Gbalance ; ,&C
brea/C
case ,&A @= 0ight heavy =@
aptr ; pptr,GrchildC
if>aptr,Gbalance ;; ,&?
O
printf>R0ight to 0ight 0otationWnR?C
pptr,Grchild; aptr,GlchildC
aptr,Glchild ; pptrC
pptr,Gbalance ; NC
aptr,Gbalance;NC
pptr ; aptrC
P
else
O
printf>R0ight to #eft 0otationWnR?C
bptr ; aptr,GlchildC
aptr,Glchild ; bptr,GrchildC
bptr,Grchild ; aptrC
pptr,Grchild ; bptr,GlchildC
bptr,Glchild ; pptrC
if>bptr,Gbalance ;; ,&?
pptr,Gbalance ; &C
else
pptr,Gbalance ; NC
if>bptr,Gbalance ;; &?
aptr,Gbalance ; ,&C
else
aptr,Gbalance ; NC
bptr,Gbalance;NC
pptr;bptrC
P@=End of else=@
=htUinc ; 3A#4EC
P@=End of switch =@
P@=End of if=@
P@=End of if=@
return>pptr?C
P@=End of insert>?=@
EORG
E"G Writ! a*0(rith )(r ADT (&!rati(n () &ri(rit# :,!,!.
Ins!rti(n

int
p$insert>struct p$ueue =$, -8DAT. d?
O
-8DAT. =tmpC
int i, newsi"eC

if >H$? return NC

@= allocate more memory if necessary =@
if >$,Gsi"e G; $,Gavail? O
newsi"e ; $,Gsi"e + $,GstepC
if >H>tmp ; realloc>$,Gd, si"eof>-8DAT.? = newsi"e??? O
return NC
PC
$,Gd ; tmpC
$,Gavail ; newsi"eC
P
@= insert item =@
i ; $,Gsi"e++C
while >i G & QQ -8-0!O>$,GdYi @ 'Z? < -8-0!O>d?? O
$,GdYiZ ; $,GdYi @ 'ZC
i @; 'C
P
$,GdYiZ ; dC
return &C
P
R!(+in0 It!s
-8DAT. =
p$remove>struct p$ueue =$, -8DAT. =d?
O
-8DAT. tmpC
int i ; &, jC

if >H$ VV $,Gsi"e ;; &? return 1##C
=d ; $,GdY&ZC
tmp ; $,GdY,,$,Gsi"eZC
while >i <; $,Gsi"e @ '? O
j ; ' = iC
if >j < $,Gsi"e QQ
-8-0!O>$,GdYjZ? < -8-0!O>$,GdYj + &Z?? O
j++C
P
if >-8-0!O>$,GdYjZ? <; -8-0!O>tmp?? O
brea/C
P
$,GdYiZ ; $,GdYjZC
i ; jC
P
$,GdYiZ ; tmpC return dC P
14. EaGWrit! h!a& s(rt r(,tin!s. Usin0 a"(+! %!si0n= s(rt th! )(**(.in0H
1-=20=10=01=11=24=-3=31=/0 EORG
E"G EiG Writ! r(,tin!s )(r :,i$2 s(rt.
EiiG E5&*ain th! !5t!rna* s(rtin0.
1-. EaGWrit! a*0(rith )(r .!i0ht!% an% ,n.!i0ht!% sh(rt!st &aths.
E5&*ain th! a"(+! a*0(riths .ith s,ita"*! !5a&*!s.
Sin0*!9S(,r$! Sh(rt!st Path (n Un.!i0ht!% Gra&hs
EI ,n.!i0ht!% sin0*!9s(,r$! sh(rt!st &ath IG
*!t +a* $A $ueue ; newU$ueue>?
+a* visitedA verte2.ap ; createUverte2.ap>?
EI +isit!% a&s +!rt!59Jint IG
),n e2pand>vA verte2? ;
*!t +a* neighborsA verte2 list ; %raph.outgoing>v?
+a* distA int ; valOf>get>visited, v??
),n handleUedge>vDA verte2? ;
$as! get>visited, vD? ()
4O.E>dD? ;G >? EI %? KF %ist71 IG
V 1O1E ;G > add>visited, vD, dist+&?C
push>$, vD? ?
in
app handleUedge neighbors
!n%
in
add>visited, vN, N?C
e2pand>vN?C
.hi*! >not >emptyU$ueue>$?? %( e2pand>pop>$??
!n%
Sin0*!9S(,r$! Sh(rt!st Path (n W!i0ht!% Gra&hs
*!t +a* $A $ueue ; newU$ueue>?
+a* visitedA verte2.ap ; createUverte2.ap>?
),n e2pand>vA verte2? ;
*!t +a* neighborsA verte2 list ; %raph.outgoing>v?
+a* distA int ; valOf>get>visited, v??
),n handleUedge>vDA verte2, weightA int? ;
$as! get>visited, vD? ()
4O.E>dD? ;G
i) dist+weight < dD
th!n add>visited, vD, dist+weight?
!*s! >?
V 1O1E ;G > add>visited, vD, dist+weight?C
push>$, vD? ?
in
app handleUedge neighbors
!n%
in
add>visited, vN, N?C
e2pand>vN?C
.hi*! >not >emptyU$ueue>$?? %( e2pand>pop>$??
!n%
This is nearly Dij/straDs algorithm, but it doesnDt wor/. To see why, consider the
following graph, where the source verte2 is v
N
; A.
EI Di>2stra?s A*0(rith IG
*!t +a* $A $ueue ; newU$ueue>?
+a* visitedA verte2.ap ; createUverte2.ap>?
),n e2pand>vA verte2? ;
*!t +a* neighborsA verte2 list ; %raph.outgoing>v?
+a* distA int ; valOf>get>visited, v??
),n handleUedge>vDA verte2, weightA int? ;
$as! get>visited, vD? ()
4O.E>dD? ;G
i) dist+weight < dD
th!n > add>visited, vD, dist+weight?C
incrUpriority>$, vD, dist+weight? ?
!*s! >?
V 1O1E ;G > add>visited, vD, dist+weight?C
push>$, vD, dist+weight? ?
in
app handleUedge neighbors
!n%
in
add>visited, vN, N?C
e2pand>vN?C
.hi*! >not >emptyU$ueue>$?? %( e2pand>pop>$??
!n%
EORG
E"G Writ! an% !5&*ain th! &riLs a*0(rith an% %!&th )irst s!ar$h
a*0(rith.
-rimDs algorithm is /nown to be a good algorithm to find a minimum spanning
tree.
&. 4et i;N, 4
N
; Ou
N
;sP, #>u
N
?;N, and #>v?;infinity for v <G u
N
. !f VFV ; & then
stop, otherwise go to step '.
'. 3or each v in FW4
i
, replace #>v? by minO#>v?, d
v
u
i
P. !f #>v? is replaced, put a
label >#>v?, u
i
? on v.
(. 3ind a verte2 v which minimi"es O#>v?A v in FW4
i
P, say u
i+&
.
K. #et 4
i+&
; 4
i
cup Ou
i+&
P.
L. 0eplace i by i+&. !f i;VFV,& then stop, otherwise go to step '.
8.E A 8.T!$h DEGREE EBAMINATION=MACADUNE 200/
THIRD SEMESTER
E*!$tr(ni$s an% C(,ni$ati(n En0in!!rin0
CS11-1 6 DATA STRUCTURES
PART A 6 E10 B 2 F 20 ar2sG
1. M!nti(n an# )(,r &r("*! s(*+in0 strat!0i!s
2. What %( #(, !an "# &r(0ra +!ri)i$ati(n
3. What is an ADT'
4. List )!. a&&*i$ati(ns () :,!,!s.
-. C(nstr,$t an !5&r!ssi(n tr!! )(r th! !5&r!ssi(n A7E89CGIDIEE7MG
/. What %( #(, !an "# &riar# $*,st!rin0'
1. Ana*#s! th! ti! $(&*!5it# () ins!rti(n s(rt a*0(rith
3. What is !5t!rna* s(rtin0'
4. D!)in! t(&(*(0i$a* s(rtin0
10.What ar! NP9$(&*!t! &r("*!s' Gi+! an !5a&*!
PART 8 6 E- B 1/ F 30 ar2sG
11. EiG With an !5a&*!= stat! an% !5&*ain th! a*0(rithA&r(0ra t( %!*!t!
an !*!!nt )r( a *!5i$a**# (r%!r!% tr!! E10G
EiiG E5&*ain th! :,a%rati$ &r("in0 hashin0 t!$hni:,! .ith an !5a&*!E/G
12.EaG E5&*ain in %!tai* th! t(& %(.n %!si0n () &r("*! s(*+in0
EORG
E"G EiG With !5a&*!s= !5&*ain h(. +!ri)i$ati(n () &r(0ra s!0!nts
.ith *((&s is %(n!
EiiG Writ! n(t!s (n (9n(tati(n
13. EaG EiG Gi+! a sin0*# *in2!% *ist= .h(s! )irst n(%! is &(int!% t( "# th!
&(int!r +aria"*! C= )(r,*at! an a*0(rithA&r(0ra t( %!*!t! th! )irst
($$,rr!n$! () B )r( th! *istE10G
EiiG With !5a&*!s= !5&*ain h(. a sta$2 $an "! ,s!% t( $(n+!rt an
in)i5 !5&r!ssi(n t( a &(st)i5 !5&r!ssi(n E/G
EORG
E"G EiG Usin0 *in2!% *ists= )(r,*at! s!&arat! r(,tin!s t( $r!at! an !&t#
sta$2 an% t( &,sh an !*!!nt (nt( a sta$2 E10G
EiiG Dis$,ss in "ri!) a"(,t th! arra# i&*!!ntati(n () :,!,!s E/G
14. EaG EiG Stat! an% !5&*ain th! a*0(rithA&r(0ra t( &!r)(r H!a& s(rt
E10G
EiiG Ana*#s! th! ti! $(&*!5it# () :,i$2 s(rt a*0(rith E/G
EORG
E"G EiG Stat! th! a*0(rithA&r(0ra t( &!r)(r sh!** s(rt. A*s(= ana*#s!
its .(rst $as! r,nnin0 ti!. E3G
EiiG E5&*ain an# (n! !5t!rna* s(rtin0 .ith an !5a&*! E3G
1-. EaG EiG With an !5a&*!= !5&*ain th! t(&(*(0i$a* s(rt E3G
EiiG Writ! th! &s!,%( $(%! )(r Di>2straLs a*0(rith. What is th!
r,nnin0 ti! () this a*0(rith' E3G EORG
E"G EiG M(r th! 0ra&h 0i+!n "!*(.= $(nstr,$t 2
4 2 10
2 1 1
3 4
- 1 /
A ini, s&annin0 tr!! ,sin0 PriLs a*0(rith. Sh(. th! ta"*! $r!at!%
%,rin0 !a$h &ass () th! a*0(rith E12G
EiiG Writ! n(t!s (n E,*!r $ir$,its E4G
1
1
2
5
3 4
6
7
8.E A 8.T!$h DEGREE EBAMINATION=NO<EM8ERADECEM8ER 2001
THIRD SEMESTER
E*!$tr(ni$s an% C(,ni$ati(n En0in!!rin0
CS11-1 6 DATA STRUCTURES
TIMEH3 Hrs MABIMUMH 100
Mar2s
ANSWER ALL NUESTIONS
PART9AE10I2F20 ar2sG
1G Wh!n .i** #(, sa# an a*0(rith !))i$i!nt' Gi+! th! n(tati(ns )(r ti!
$(&*!5it#.
2G What is t(&9%(.n %!si0n' Is C *an0,a0! a t(& %(.n %!si0n'>,sti)#
#(,r ans.!r.
3G Wh# is *in2!% *ist ,s!% )(r &(*#n(ia* arith!ti$'
4G Writ! th! r(*! () sta$2 in ),n$ti(n $a**
-G What is th! ini, n,"!r () n(%!s in an A<L tr!! () h!i0ht -'
/G What is th! ,s! () s!ntin!* +a*,! in "inar# h!a&'
1G Whi$h is th! "!st .a# () $h((sin0 th! &i+(t !*!!nt in :,i$2 s(rt
3G M!r0! s(rt is "!tt!r than ins!rti(n s(rt ..h#'
4G D!)in! a 0ra&h.h(. it %i))!rs )r( tr!!
10G What is ini, s&annin0 tr!!' Na! an# t.( a*0(riths ,s!%
t( )in% MST.
PART98E-I1/F30 ar2sG
11G EaGEiGGi+!n t.( *ists L1 an% L2= .rit! th! r(,tin!s t( $(&,t! L1
O L2 ,sin0 "asi$ (&!rati(ns.EHint H)(r !))i$i!nt &!r)(ran$!= s(rt th!
*istsG. E10G
EiiGWrit! th! r(,tin!s )(r ins!rtin0 an% %!*!tin0 !*!!nts )r( a
:,!,!.Ch!$2 )(r th! $(n%iti(ns N9!&t# an% N9),**. E/G
EOrG
E"GEiG H(. .(,*% #(, i&*!!nt a sta$2 () :,!,!s' Writ! r(,tin!s )(r
Cr!ati(n an% ins!rtin0 () !*!!nts int( it. E3G
EiiGWrit! r(,tin!s t( ins!rt h!t!r(0!n!(,s %ata int( th! *ist E3G
12 EaGEiGWrit! th! r(,tin!s t( ins!rt an% r!(+! n(%! )r( "inar#
s!ar$h tr!!.E10G
EiiGA ),** n(%! is a n(%! .ith t.( $hi*%r!n .Pr(+! that th! n,"!r
() ),** N(%!s &*,s (n! is !:,a* t( th! n,"!r () *!a+! in a "inar# tr!!.
E/G EOrG
E"GEiGSh(. th! r!s,*t () ins!rtin0 2= 1= 4= -= 4= 3= /=1int( an !&t#
A<L tr!!. E/G
EiiG Writ! th! &r($!%,r!s t( i&*!!nt sin0*! an% %(,"*!
r(tati(ns .hi*! ins!rtin0 n(%!s in an A<L tr!!. E10G
13EaG E5&*ain= .ith s,ita"*! !5a&*!s th! "asi$ h!a& (&!rati(ns an%
.rit! A*0(riths )(r th! sa! E1/G
EOrG
E"G H(. .i** #(, r!s(*+! th! $(**isi(ns= .hi*! ins!rtin0 !*!!nts int(
th! hash a"*! ,sin0 s!&arat! $hainin0 an% *in!ar &r("in0' Writ! th!
r(,tin!s )(r ins!rtin0= s!ar$hin0 an% r!(+in0 !*!!nts )r( th! hash
ta"*! ,sin0 th! a"(+! !nti(n!% t!$hni:,!.

14 EaG EiG Writ! th! r(,tin!s )(r s(rtin0 n !*!!nts in in$r!asin0 (r%!r
,sin0 H!a& S(rt. E12G
EiiG S(rt 3= 1=4=1=-=4=2=/ in %!$r!asin0 (r%!r ,sin0 h!a& s(rt. E4G
EOrG
E"GEiGE5&*ain .ith !5a&*!= a"(,t th! ins!rti(n s(rt. E/G
EiiGWhat is !5t!rna* s(rtin0' Dis$,ss th! a*0(riths .ith &r(&!r
E5a&*!s E10G
1-EaGEiGDis$,ss an% .rit! th! &r(0ra t( &!r)(r t(&(*(0i$a* s(rtin0
E/G
EiiGWhat is sin0*! s(,r$! sh(rt!st &ath &r("*!'Dis$,ss Di>i2straLs
sin0*! S(,r$! sh(rt!st &ath a*0(rith .ith an !5a&*!. E10G
EOrG
E"GEiG.rit! an a*0(rith t( )in% th! ini, $(st s&annin0 tr!! () an
,n%ir!$t!%=.!i0ht!% 0ra&h E3G
EiiGMin% MST )(r th! )(**(.in0 0ra&h E3G
8.E A 8.T!$h DEGREE EBAMINATION= NO<EM8ERADECEM8ER 2004
THIRD SEMESTER
E*!$tr(ni$s an% C(,ni$ati(n En0in!!rin0
EE2204 6 DATA STRUCTURES AND ALGORITHMS
A D
B
C
E
F
3
2
3
3
4
4
TIMEH3 Hrs MABIMUMH 100
Mar2s
ANSWER ALL NUESTIONS
PART9AE10I2F20 ar2sG
1. D!)in! A"stra$t Data T#&!.
An ADT is a set of operation. Abstract data types are mathematical
abstractions.Eg.Objects such as list, set and graph along their operations can
be viewed as ADTs.
2. C(n+!rt th! in)i5 !5&r!ssi(n EA98ACGIEDAE9MG int( a &(st)i5.
-ostfi2A A9:@,DE@3,=
3. What ar! th! st!&s t( $(n+!rt a 0!n!ra* tr!! int( "inar# tr!!'
= use the root of the general tree as the root of the binary tree
= determine the first child of the root. This is the leftmost node in the
general tree at the ne2t level
= insert this node. The child reference of the parent node refers to this
node
= continue finding the first child of each parent node and insert it below
the parent node with the child reference of the parent to this node.
= when no more first children e2ist in the path just used, move bac/ to
the parent of the last node entered and repeat the above process. !n other
words, determine the first sibling of the last node entered.
= complete the tree for all nodes. !n order to locate where the node fits
you must search for the first child at that level and then follow the
sibling references to a nil where the ne2t sibling can be inserted. The
children of any sibling node can be inserted by locating the parent and then
inserting the first child. Then the above process is repeated.
4. List th! a&&*i$ati(ns () tr!!s.
a. 9inary tree is used in data processing.
b. 3ile inde2 schemes
c.7ierarchical database management system
-. What %( #(, !an "# a h!a&'
A heap is a speciali"ed tree,based data structure that satisfies the heap
propertyA if 9 is a child node of A, then /ey >A? [ /ey>9?. This implies that an
element with the greatest /ey is always in the root node, and so such a heap is
sometimes called a ma2,heap. >Alternatively, if the comparison is reversed, the
smallest element is always in the root node, which results in a min,heap.?
/. D!)in! hashin0.
7ash function ta/es an identifier and computes the address of that identifier
in the hash table using some function
1. What is t(&(*(0i$a* s(rt'
!t is an Ordering of vertices in a directed acyclic graph such that if there is a
path from vi to vj, then vj appears after vi in the ordering.
3. D!)in! "i$(nn!$t!% 0ra&h.
A connected undirected graph is biconnected if there are no vertices whose
removal disconnects the rest of the graph.
4. Stat! th! 0r!!%# a*0(rith.
A greedy algorithm is any algorithm that follows the problem solving
metaheuristic of ma/ing the locally optimal choice at each stage with the hope
of finding the global optimum.
10.M!nti(n an# t.( %!$isi(n &r("*!s .hi$h ar! NP9C(&*!t!.
1- is the class of decision problems for which a given proposed
solution for a given input can be chec/ed $uic/ly to see if it is really a
solution.
PART98 E-I1/ F 30 Mar2sG
EM(r &a0! n,"!rs r!)!r DATA STRUCTURES AND ALGORITHM
ANALCSIS IN C "# A**!n W!issG
11. EaG E5&*ain th! )(**(.in0 (&!rati(ns in a %(,"*# *in2!% *ist. E&a0! n(H11/G
EiG Ins!rt an !*!!nt E/G
EiiG D!*!t! an !*!!nt E-G
EiiiG R!+!rs! th! *ist E-G
Or
E"G EiG Dis$,ss th! a*0(riths )(r &,sh an% &(& (&!rati(ns (n a sta$2
E&a0! n(H3/G E3G
EiiG Writ! an a*0(rith t( ins!rt an% %!*!t! a 2!# in a $ir$,*ar :,!,!
E&a0! n(H4-G
12. EaG EiG C(nstr,$t a** &(ssi"*! tr!! str,$t,r! .ith 4 n(%!s.
E3GE&a0! n(H10-G
EiiG P!r)(r &r!(r%!r= in(r%!r an% &(st(r%!r tra+!rsa*s () th! 0i+!n
tr!!.E3GE&a0! n(H101G Or
E"G E5&*ain th! )(**(.in0 (&!rati(ns (n a "inar# s!ar$h tr!! .ith
s,ita"*! A*0(riths. E&a0! n(H11/G
EiG )in% a n(%! E-G
EiiG Ins!rt a n(%! E-G
EiiiG D!*!t! a n(%! E/G
13.EaG EiG Dis$,ss h(. t( ins!rt an !*!!nt in an A<L tr!!. E5&*ain .ith
A*0(rith E&a0! n(H12/G E10G
EiiG What is 89Tr!!' E5&*ain its &r(&!rti!s. E&a0! n(H144G E/G
Or
E"G EiG D!s$ri"! th! %i))!r!nt hashin0 ),n$ti(ns .ith an !5a&*!. E&a0!
n(H1//G E3G
EiiG E5&*ain th! $((n $(**isi(n r!s(*,ti(n strat!0i!s in (&!n a%%r!ssin0
hashin0. E&a0! n(H113G
E3G
14. EaG EiG E5&*ain th! "r!a%th )irst s!ar$h a*0(rith E&a0! n(H301G
E3G
EiiG Writ! an% !5&*ain th! &ris a*0(rith .ith an !5a&*!E&a0!
n(H330GE3G Or
E"G EiG What is a str(n0*# $(nn!$t!% 0ra&h' Gi+! an !5a&*!. E&a0!
n(H244G E4G
EiiG Writ! th! a*0(rith t( $(&,t! *!n0ths () sh(rt!st &ath &a0!
n(H30/E4G
EiiiG E5&*ain th! %!&th )irst s!ar$h a*0(rith. E&a0! n(H33-G E3G
1-. EaG Min% th! (&tia* t(,r in th! )(**(.in0 tra+!*in0 sa*!s&!rs(n
&r("*! Usin0 %#nai$ &r(0rain0. E&a0! n(H341G E1/G
Or
E"G EiG E5&*ain th! !th(% () s(*+in0 N :,!!ns &r("*! "# "a$2
tra$2in0 E10G E&a0! n(H411G
EiiG Dis$,ss "ri!)*# th! +ari(,s as#&t(ti$ n(tati(ns ,s!% in
a*0(rith Ana*#sis E/G

Das könnte Ihnen auch gefallen