Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

DATA STRUCTURES AND ALGORITHMS Short questions and answers 1. Define Abstract Data Type (ADT).

Abstract data type is a collection of value definitions and the operations on those values. Value definitions Operator definitions 2. Define a sequence. A sequence is an ordered set of elements. S=<s !s"!s#$$%sn&"' . !rite short notes on structures in ". A basic data structure in " is called as the structure. A #tructure is a $roup of items in %hich each item is identified by its o%n identifier. &'ample( stru(t na)et*+e , (har -irst." /0 int ro110 2sna)e! ena)e0 ). !hat is the difference bet%een a structure and union in ". a. #ame memory is used for all the members of union. At any time only one member can be accessed. b. *ndividual memory is used for structure members. +. Define a #tac,. A stac, is an ordered collection of items into %hich ne% items may be inserted and from %hich items may be deleted at one end called the top of the stac,. *t is also called as -ast *n .irst Out (-*.O). /. !hat are the primitive operations that are performed on a #tac,0 The primitive operations are 1ush2 insertin$ an element at the top of the stac, 1ush(s3i)4 1op 5 removin$ an element at the top of the stac, i6pop(s)4 7. 8o% do you implement the #tac, definition in ". 9se array implementation0 3de-ine STAC4SI5E stru(t sta(6 , int to+0 int ite)s.STAC4SI5E/0

20 :. !rite the steps for implementin$ the pop operation. *f the stac, is empty3 print a %arnin$ messa$e and halt e'ecution ;emove the top element from the stac,. ;eturn this element to the callin$ pro$ram <. !hat is recursive definition0 An ob=ect in terms of simpler case of itself is called recursive definition. &'amples( To find the factorial of a $iven number To print the .ibonacci series. 1>. Define a queue. A queue is a ordered collection of items from %hich itesm may be deleted at one end (called the front of the queue) and into %hich items may be inserted at the other end (called the rear of the queue). *t is also called as .irst in .irst out (.*.O). 11. 8o% the queue is represented in "0 3de-ine MA78UEUE " stru(t queue , int ite)s.MA78UEUE/0 int -ront! rear0 2q0 12. Define priority queue. !hat are the types of 1riority queue0 The priority queue is a data structure in %hich the intrinsic orderin$ of the elements does determine the results. There are t%o types ascendin$ priority queue is a collection of items into %hich items can be inserted arbitrarily and from %hich only the smallest item can be removed. descendin$ priority queue 1 . !hat is the purpose of header node0 #ometimes it is desirable to ,eep an e'tra node at the front of the list. #uch a node does not represent an item in the list and is called the header node or a list header. 1). 8o% to create and delete a dynamic variable in "0 malloc() is a function helpful for creatin$ a dynamic variable. free() is a function helpful for deletin$ a dynamic variable.

1+. 8o% to create a node of a sin$ly lin,ed list usin$ dynamic variables0 stru(t node , int in-o0 stru(t node 9ne:t0 20 t*+ede- stru(t node 9NODE;TR0 1/. 8o% to create a node of a Doubly lin,ed list usin$ dynamic variables0 stru(t node , int in-o0 stru(t node 9ne:t! 9+re<ious0 20 t*+ede- stru(t node 9NODE;TR0 17. Define a binary tree. A binary tree is a finite set of elements that is either empty or is partitioned into three dis=oint subsets. One subset is the left and one subset of the ri$ht and the third subset is the root of the tree. 1:. !hat is a strictly binary tree0 *f every non leaf node in a binary tree has nonempty left and ri$ht subtrees3 the tree is named as the strictly binary tree. 1<. Define traversal in tree and %hat is the different type of traversals in tree0 To pass throu$h the tree3 enumeratin$ each of its nodes once. Three types of traversals preorder traversal i. visit the root ii. Traverse the left subtree in preorder. iii. Traverse the ri$ht subtree in preorder inorder traversal i. Traverse the left subtree in preorder. ii. visit the root iii. Traverse the ri$ht subtree in preorder postorder traversal i. Traverse the left subtree in preorder. ii. Traverse the ri$ht subtree in preorder iii. visit the root 2>. 8o% the binary tree node is represented dynamically0 stru(t nodet*+e , int in-o0

stru(t nodet*+e 91e-t0 stru(t nodet*+e 9ri=ht0 20 21. !hat are called leaf nodes0 The nodes %hich don?t have any sons are called as leaf nodes. 22. !hat are called internal and e'ternal nodes0 The leaf nodes are called as e'ternal nodes and the non leaf nodes are called as internal nodes. 2 . Define O notation. To capture the concept of one function becomin$ proportional to another as it $ro%s3 a notation is %hich is called as O notation. 2). Define a $raph. A $raph consists of a set of nodes (or vertices) and set of arcs (or ed$es). 2+. Define %ei$hted $raph. A number is associated %ith each arc of a $raph is called a %ei$hted $raph. The number associated %ith the arc is called the %ei$ht. 2/. Define minimum spannin$ tree. @iven a connected %ei$hted $raph @3 it is often desired to create a spannin$ tree T for @ such that the sum of the %ei$hts of the tree ed$es in T is as small as possible. #uch a tree is called minimum spannin$ tree. 27. Define Depth .irst Traversal. Visits the successors of a visited node before visitin$ any of its brothers. *n D.T3 each visited node is placed in the stac, 2:. Define Areadth .irst Traversal. Visits all successors of a visited node before visitin$ any successors of any of those successors. *n A.T3 each visited node is placed on the queue. 2<. !hat are called Dynamic data structures0 #tructures %hich $ro% or shrin, as the data they hold chan$es. &'ample( -ists >. Define Ainary #earch. A technique for searchin$ an ordered list in %hich %e first chec, the middle item and 2 based on that comparison 2 BdiscardB half the data. The same procedure is then applied to the remainin$ half until a match is found or there are no more items left.

1. !hat are the advanta$es of lin,ed lists0 Overflo% can never occur unless the memory is actually full. *nsertions and deletions are easier than for conti$uous (array) lists. !ith lar$e records3 movin$ pointers is easier and faster than movin$ the items themselves. 2. !hat are the disadvanta$es of lin,ed lists0 The pointers require e'tra space. -in,ed lists do not allo% random access. Time must be spent traversin$ and chan$in$ the pointers. 1ro$rammin$ is typically tric,ier %ith pointers. . Define Ainary #earch Trees. A binary search tree is a binary tree %here each node contains a ,ey such that( All ,eys in the left subtree lesser than the ,ey in the root. All ,eys in the ri$ht subtree $reater the ,ey in the root. The left and ri$ht subtrees of the root are a$ain binary search trees. ). !hat is the difference Data types vs. Data #tructures0 A data type is a %ell2defined collection of data %ith a %ell2defined set of operations on it. A data structure is an actual implementation of a particular abstract data type.

You might also like