Sei sulla pagina 1di 17

DATA STRUCTURES

1. What do you mean by data structures? Data structures are 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. . !ist out the areas in which data structures are applied e"tensively? Data structure is used almost in all areas of computer science and the areas in which they are applied e"tensively are# $ompiler Design %perating &ystem Database 'anagement &ystem &tatistical analysis package (umerical Analysis )raphics Artificial *ntelligence &imulation +. What are the ma,or data structures used in the following areas# -D.'&, (etwork data model and /ierarchical data model? -D.'& 0 Array 1i.e. array of structures2 (etwork data model 0 )raph /ierarchical data model 0 3rees 4. Define stack. A stack is a list of elements in which an element can be inserted or deleted only at one end called the top of the stack. *t is also known as !*5% lists. 6ush and pop are the basic operations performed on a stack. 7. )ive some of the common applications of stacked used in the computer field. 'atching of nested parentheses in arithmetic e"pressions. 8valuation of arithmetic e"pressions. 5unction call implementation. $onversion of one form of e"pression into another form. 9. $onsider a stack implemented using an array. !ook at the following code and select the correct option. void push1 struct stack :s1, int item2 ; s1 <= top>> ? s1 <= array@topA B item? C int pop1 struct stack :s12 ; s1 <= top>>? return s1 <= array@topA?

C a2 b2 c2 d2 3he push function is incorrect. 3he pop function is incorrect. 3his combination of push and pop functions is incorrect. 3here is nothing wrong in the above code.

Answer: b2 3he pop function is incorrect. Explanation: *n the case of pop operation first we have to retrieve the element pointed by top then only we have to decrement the value of top. D. Define Eueue. A Fueue is an ordered collection of items in which the elements can be inserted at the rear end of the Fueue and elements can be deleted from the front end of the Fueue. *t is also known as 5*5% list. G. What is the minimum number of Fueues needed to implement a priority Fueue? 3wo. %ne Fueue is used for actual storing of data and another for storing priorities. H. 3he number of elements in a Fueue at any time is eFual to a2 F.rear 0 1F.front>12 b2 F.rear 0 F.front <1 c2 F.rear > F.front > 1 d2 F.rear 0 F.front > 1 Answer: d2 F.rear 0 F.front > 1 1I. 6ick out the wrong option about Fueue from the following. a2 Eueue is also known as 5*5% lists. b2 E.rear J F.front refres to the fact that the Fueue is empty. c2 An insertion into an empty Fueue will be always successful. d2 An element is removed front the front end of the list. Answer# c2 An insertion into an empty Fueue will be always successful. 11. Define priority Fueue. 6riority Fueue is a special type of Fueue in which the intrinsic ordering of the elements does determine the results of its basic operations. 1 . What are the types of priority Fueue? Ascending priority Fueue Descending priority Fueue 1+. Define circular Fueue. $ircular Fueue is a Fueue in which the elements are arranged in a circular manner where the first element of the array immediately follows the last element.

14. 3he condition F.front BB F.rear in a circular Fueue refers to a2 Fueue is empty b2 Eueue is full c2 .oth a and b d2 (one of the above Answer: c2 both a and b. 17. Define singly linked list. A singly linked list is a series of data items with each item containing a pointer giving the location of the ne"t immediate item in the list and these items need not necessarily be stored in contiguous memory locations. 19. *s linked<list a linear or non<linear data structure? According to access strategies linked list is a linear one. According to &torage, linked list is a (on<linear one. 1D. *f you are using $ language to implement the heterogeneous linked list, what pointer type will you use? 3he heterogeneous linked list contains different data types in its nodes and we need a link, pointer to connect them. *t is not possible to use ordinary pointers for this. &o we go for void pointer. Koid pointer is capable of storing pointer to any type as it is a generic pointer type. 1G. !ist out a few of the applications that make use of multilinked structures. &parse matri" *nde" generation 1H. Define circular linked list. A circular linked list is a type of linked list in which the last node of the list points back to the first node of the list rather than the null pointer. I. Define doubly linked list. A doubly linked list is a linked list in which each node of the list contains two pointers, one pointing to its predecessor and another pointing to its successor of the list. 1. What is called recursion? A procedure or function that can repeat or calls itself indefinitely is called recursion. . What is the data structure used to perform recursion? &tack. .ecause of its !*5% property it remembers its LcallerM? so the function knows where to return when the function has to return. -ecursion makes use of system stack for storing the return addresses of the function calls. 8very recursive function has its eFuivalent iterative 1non<recursive2 function. 8ven when such eFuivalent iterative procedures are written, e"plicit stack is to be used.

+. What are the notations used in evaluation of arithmetic e"pressions using prefi" and postfi" forms? 6olish notation -everse 6olish notations 4. $onvert the e"pression 11A > .2 : $ 0 1D 0 82 N 15 > )22 to eFuivalent 6refi" and 6ostfi" notations Prefix Notation# N < : >A.$ < D8 > 5) Postfix Notation: A. > $ : D8 < < 5) > N 7. 3raverse the following tree using inorder, preorder and postorder traversals.
A

/ *norder # 6reorder# 6ostorder# D/.8A5$*)O A.D/8$5)*O /D8.5*O)$A

9. Which among the following points is not correct about postfi" e"pressions? a2 3he postfi" form of e"pressions specifies the actual order of operations. b2 &tack is the best techniFue for evaluating postfi" e"pression. c2 6ostfi" e"pressions contain operators, operands and parentheses. d2 6ostfi" e"pressions will not contain any parentheses. Answer: c2 6ostfi" e"pressions contain operators, operands and parentheses. D. Define .inary tree. A binary tree is a finite set of elements that is either empty or is partitioned into three dis,oint subsets. 3he first subset contains a single element called the root of the tree. 3he other two subsets are themselves binary trees, called the left and right subtrees of the original tree. A left or right subtree can be empty. G. What is called the depth of a binary tree? 3he ma"imum level of any leaf in a tree is called the depth of the tree. H. When is a binary tree said to be a strictly binary tree?

A binary tree is said to be a strictly binary tree, if any of its non<leaf nodes have both left and right subtrees. +I. !ist out a few of the applications of tree data<structure in compilersPcompiler design. 3he manipulation of Arithmetic e"pression &ymbol 3able construction &ynta" analysis +1. &tate the total number of nodes in a strictly binary tree which contains 9 leaves. 11 nodes. A strictly binary tree with n leaves always contains 1 n<12 nodes. + . What is called a complete binary tree? *f all of the leaf nodes of a strictly binary tree resides at the same level d, then it is called a complete binary tree of depth d. ++. What will be the total number of leaves and non<leaf nodes if the depth of the complete binary tree is 7. + leaves and +1 non<leaf nodes. A complete binary tree of depth d will have d leaf nodes and d<1 non<leaf nodes. +4. 6re<order traversal is also known as QQQQQQQQQ and post<order traversal is also known as QQQQQQQQQ. Answer: Depth<first traversal, .readth<first traversal. +7. When a binary tree is visited based on in<order traversal, the output of the node contents will be in a2 Ascending order b2 Descending order c2 *mproper order d2 &ame as input order Answer: a2 Ascending order +9. What is called a binary search tree? A binary tree which has a property that all elements in the left sub<tree of a node LnM are less than the contents of n, and all the elements in the right sub< tree of n are greater than or eFual to the contents of n, then it is said to be a binary search tree. +D. A binary tree with I nodes has QQQQQQQQ null branches. Answer: 1 Explanation: !et us take a tree with 7 nodes 1nB72

(ull .ranches

*t will have only 9 1i.e., 7>12 null branches. *n general, a binary tree with n nodes has e"actly n > 1 null node. +G. /ow many different trees are possible with 1I nodes? Answer: 1I14 Explanation: 5or e"ample, consider a tree with + nodes 1nB+2, it will have the ma"imum combination of 7 different 1i.e. + < + B 72 trees.

ii

iii
n

iv <n different trees.

In general: *f there are n nodes, there e"ist

+H. 3here are some G, 17, 1+, 14 nodes in 4 different trees. Which of them could have formed a full binary tree? 17. *n general, there are n<1 nodes in a full binary tree. By the method of elimination: 5ull binary trees contain odd number of nodes. &o there cannot be full binary trees with G or 14 nodes, so re,ected. With 1+ nodes you can form a complete binary tree but not a full binary tree. &o the correct answer is 17. 1Note: 5ull and $omplete binary trees are different. All full binary trees are complete binary trees but not the other way2. 4I. *n the given binary tree, using array, at which location can can you store the node 4? 1

4 7 Answer: At the location 9 Explanation: 1 + < < 4 < < 7 -oot !$1 -$1 !$ -$ !$+ -$+ !$4 -$4 where !$n means !eft $hild of node n and -$n means -ight $hild of node n.

41. Which of the following statements is wrong about binary search trees? a2 5or deletion of the root node, the entire tree needs to be reconstructed. b2 *n<order traversal always gives sorted output. c2 6ost order traversal represents the tree uniFuely. d2 .inary search property needs to be retained after each deletion. Answer: a2 5or deletion of the root node, the entire tree needs to be reconstructed. Explanation: *n the binary search trees for deletion of the root node, the entire tree needs not to be reconstructed? only the right sub tree is to be reconstructed. 4 . %f the following tree structures, which is efficient considering space and time comple"ities? a2 *ncomplete binary tree b2 $omplete binary tree c2 5ull binary tree Answer: b2 complete binary tree. Explanation: By the method of elimination: 5ull binary tree loses its nature when operations of insertions and deletions are done. 5or incomplete binary trees, e"tra storage is reFuired and overhead of (R!! node checking takes place. &o complete binary tree is the better one since the property of complete binary tree is maintained even after operations like additions and deletions are done on it. 4+. Which of the following statements is correct about binary trees? a2 An A$.3 1Almost $omplete .inary 3ree2 is always an AK! tree. b2 An AK! tree is always an A$.3. c2 A tree canMt be A$.3 as well as AK! at the same time. d2 AK! is an A$.3 which satisfies binary search properties. Answer: a2 an A$.3 1Almost $omplete .inary 3ree2 is always an AK! tree. Explanation: .y the method of elimination# AK! tree is always not ac A$.3, because the AK! tree may have right skewed right child in the leaf level. .ut a binary tree may be A$.3 as well as AK! at the same time, i.e. the leaf nodes are present in the left skewed manner. *f AK! is an A$.3 then which need not satisfies binary search properties. i.e., there is not constraint about the values present in the nodes. &o A$.3 is always an AK! tree.

44. Draw a binary 3ree for the e"pression # A : . < 1$ > D2 : 16 P E2 < :

>

47. 5or the following $%.%! code, draw the .inary tree? I1 &3RD8(3Q-8$. I (A'8. I+ 5*-&3Q(A'8 6*$ S11I2. I+ !A&3Q(A'8 6*$ S11I2. I T8A-Q%5Q&3RDT. I+ 5*-&3Q&8' 6*$ SS. I+ &8$%(DQ&8' 6*$ SS. I1 &3RD8(3Q-8$

I
(A'8

I
T8A-Q%5Q&3RDT

I+
5*-&3Q(A'8

I+
!A&3Q(A'8

I+
5*-&3Q&8'

I+
&8$%(DQ&8'

49. What are called internal and e"ternal nodes of a binary tree? *n a binary tree, leaf nodes are called e"ternal nodes and non<leaf nodes are called internal nodes.

4D. What are called threaded binary trees? 3hreaded binary trees are the trees in which a special link called thread will be pointed to an ancestor node from a descendant node, in order to simplify the traversal on binary trees. 4G. 8"plain the rule to convert a binary tree into threaded binary tree. 1. When you branch from a sub<tree node on its right side, connect its right most descendant child to the father of the node from which you started right branching. . $onnect the leaves and non<leaf nodes with no right child nodes to their immediate predecessor nodes. 4H. $onvert the following binary tree into threaded binary tree. 7I. What is called heterogeneous binary tree? *f the information stored in different nodes of a binary tree are not all of the same type, then the tree is called heterogeneous binary tree. Example: A tree representing any binary e"pression. 71. Define tree. A tree is a finite non<empty set of elements, in which one element is called the root and the remaining elements are themselves trees that may be called as sub<trees. 7 . Differentiate between trees and binary trees. Binary Tree A binary tree can be empty. Any node in a binary tree can have at most two children. All binary tree e"cept the empty binary tree is a tree. 3he left child of a parent node must be small and right side of a parent node must be larger than its parent node. Tree A tree has to be non<empty 1i.e.2 it should contain more than one node. Any node in the tree can have more than two children. (ot every tree can be a binary tree. &ince there are no left or right child concepts, the elements in a tree can be in any order.

7+. Define ordered tree. An ordered tree is defined as a tree, in which the subtrees of each node form an ordered set. 74. What is the degree of the node A,.,$ and ) for the following tree? 77. What is a forest? A forest is an ordered collection of ordered trees.

79. 8"plain the rule for converting a general tree into a binary tree. 12 3ilt the original tree by 47 degrees. 2 -emove links between father and child e"cept for the left most children. +2 Add links between each node and its immediate right child. 7D. $onstruct the binary tree after deleting the nodes containing 4G,47 and GI from the following# 7G. Define AK! tree. An AK! tree is a height balanced tree in which the left and right subtrees of the root node differ at most by 1 and again the left and right subtrees are AK! trees. 7H. AK! stands for QQQQQQQ, QQQQQQQ and QQQQQQQQQ. Answer: Adelson, Kelskii, !andis 9I. What is meant by balance factor of an AK! tree? *n an AK! tree, each node has the balance value, which is eFual to the height of its left sub<tree minus the height of its right sub<tree. 3hese balance values are said to be balance factor of an AK! tree. 91. *n an AK! tree, what is the condition for balancing to be done? 3he Lpivotal valueM 1or the Lheight factorM2 is greater than 1 or less than01. 9 . When is a tree said to be height<balanced tree? A tree is said to be height<balanced only when the balance values of each node are <1, I or 1. %therwise the tree is said to be unbalanced. 9+. Write out the algorithm for left rotation of a sub<tree rooted at p. F B right1p2 hold B left1F2 left1F2 B p right1p2 B hold 94. Write out the algorithm for right rotation of a sub<tree rooted at p. F B left1p2 hold B right1F2 right1F2 B p left1p2 B hold 97. What is the ob,ective behind the left and right rotation of a sub<tree? 3he ob,ective is to make the unbalanced tree as a balanced tree by making necessary left or right rotations. 99. Define weight of a tree. 3he number of e"ternal nodes in the tree is defined as the weight of a tree. 9D. Define multi<way search tree.

A multi<way search tree of order n is a general tree in which each node has n or few sub<trees and contains one few key than it has sub<trees. 9G. What are called full nodes in a multi<way search trees? 3he nodes which contain ma"imum number of sub<trees and the ma"imum number of keys ina multi<way search tree, then the nodes are called full nodes. 9H. Define semi<leaf. *n a multi<way<search trees a semileaf is defined as a node with at least one empty subtree. DI. When is a multi<way search tree said to be balanced? *n a multi<way search tree, when all its semileaves are at the same level, then the tree is said to be balanced. D1. What is the ma"imum number of keys a node can have in a multi<way search tree, of order G? A node can have ma"imum of 1n<12 keys in the tree. 3herefore, a node can have at most D keys or order G. D . Define .<tree. A .<tree of order n is a multi<way tree in which All leaves are on the same level. All the internal nodes e"cept the root have at most n non<empty children and at least nP non<empty children. 3he number of keys in each internal node is one less than the number of its non<empty children and these keys partition the keys in the children in the fashion of a search tree. 3he root has at most children, but may have as few if it is not a leaf or none if the tree consists of the root alone. All the keys in a node must be ordered in some fashion. D+. Draw the .<tree of order + created by inserting the following data arriving in seFuence 0 H 4 9 D 11 G 4 7 19 1H I DG
11

<

1H

<

<

<

19

<

DG

D4. $onstruct a .<tree of order 7 for the following input#

D7. .riefly e"plain about .> tree. .> tree is a variation of . tree in which all keys are maintained in leaves and keys are replicated in non<leaf nodes to define paths for locating individual records. 3he leaves are linked together to provide a seFuential path for traversing the keys in the tree. D9. What is the ma,or advantage of .> tree over . tree? . tree allows only rapid random access property, whereas the .> tree allows both rapid random access and rapid seFuential properties. DD. *n -D.'&, what is the efficient data structure used in the internal storage representation? .> tree. .ecause in .> tree, all the data are stored only in leaf nodes, that makes searching easier. 3his corresponds to the records that shall be stored in leaf nodes. DG. What is meant by digital search tree. Digital search tree is a form of general tree that is built based on the symbols of which the keys are composed. DH. $onstruct a digital search tree for the following keys# GI. What is a spanning 3ree? A spanning tree is a tree associated with a network. All the nodes of the graph appear on the tree once. A minimal spanning tree is a spanning tree organized so that the total edge weight between nodes is minimized. G1. Does the minimal spanning tree of a graph give the shortest distance between any specified nodes? Answer: (o. Explanation: 'inimal spanning tree assures that the total weight of the tree is kept at its minimum. .ut it doesnMt mean that the distance between any two nodes involved in the minimum<spanning tree is minimum. G . $onvert the given graph with weighted edges to minimal spanning tree
9II

1
41I

91
HG7 14 1

+
+1I

II

7
4II

3he eFuivalent minimal spanning tree is# 1 +

41I

91

+1I 4

II 7

G+.

What is meant by hashing? /ashing is a searching techniFue, which uses hash function to directly find out the location of a record in a constant search time, irrespective of where the record is in the file. A function that transforms a key into a table inde" is called a hash function. (ame some of the popular collision resolving techniFues. !inear probing Euadratic probing -ehashing $haining What is meant by linear probing and e"plain its disadvantages. *t is a type of collision resolving techniFue in which the colliding element will be placed in the ne"t available space in the bucket. 3he main disadvantage of this method is that records tend to cluster, when the table is about half full. -ehashing is also known as QQQQQQQQQQ. Answer# Double hashing.

G4.

G7.

G9. GD.

What is the bucket size, when overlapping and collision occur at the same time? %ne. *f there is only one entry possible in the bucket, when the collision occurs, there is no way to accommodate the colliding value. 3his results in the overlapping of values. GG. $lassify the hashing functions based on the various methods by which the key value is found. Direct method, &ubtraction method, 'odulo<Division method, Digit<8"traction method, 'id<&Fuare method, 5olding method, 6seudo<random method. GH. What are the types of $ollision -esolution 3echniFues and the methods used in each of the type? %pen addressing 1closed hashing2. 3he methods used include overflow blocks. $losed addressing 1open hashing2

3he methods used include linked list, binary tree etc. HI. 8"plain Double hashing method for resolving collision? Rsing this techniFue, when a hash function produces a collision, then the hash value is given as input to a rehash function and then the new hash value is computed. 3his techniFue also leads to clustering problem. 8"plain Fuadratic probing collision resolving techniFue. *n this method, the clustering problem is avoided by means of forcing the problemt key to move Fuickly a considerable distance from the initial collision. When a key value hashes, it applies the rehash function. .riefly e"plain chaining method of dealing collision. Rnlike other methods, this method does not makes use of the hash value as the actual location of the record, instead it is used as an inde" into an array of pointers. 8ach pointer accesses a chain of records that share the same hash location. What are the important characteristic features for a hash function to be good? *t must not be comple". *t must be Fuick to compute. *t should minimize the number of collisions. *t should distribute the records uniformly throughout the array. Which among the following is the best sorting method for the utilization of virtual memory environment? a2 .ubble sort b2 Euick sort c2 *nsertion sort d2 'erge sort e2 /eap sort Answer# b2 Euick sort Which among the following is the best for e"ternal file sorting? a2 .ubble sort b2 Euick sort c2 *nsertion sort d2 &election sort e2 'erge sort Answer# e2 'erge sort Which sorting method will you select for the given set of input data# 7,1I, 7,+7,+I,47,DI,7I,GI,H7,1II a2 .ubble sort b2 Euick sort c2 *nsertion sort d2 'erge sort Answer# *nsertion sort 8"planation# *nsertion sort is best for almost sorted data.

H1.

H .

H+.

H4.

H7.

H9.

HD. &orting is not possible by using which of the following methods? a2 *nsertion b2 &election c2 8"change d2 Deletion Answer: d2 deletion Explanation: Rsing insertion we can perform insertion sort, using selection we can perform selection sort, using e"change we can perform the bubble sort 1and other similar sorting methods2. .ut no sorting method can be done ,ust using deletion. HG. &ort the given values using Euick &ort? 97 DI D7 GI G7 9I 77 7I 47 &orting takes place from the pivot value, which is the first value of the given elements, this is marked bold. 3he values at the left pointer and right pointer are indicated using ! and - respectively. 65 DI! D7 GI G7 9I 77 7I 47&ince pivot is not yet changed the same process is continued after interchanging the values at ! and - positions 65 47 D7 ! GI G7 9I 77 7I - DI 65 47 7I GI ! G7 9I 77 - D7 DI ! 65 47 7I 77 G7 9I GI D7 DI 65 47 7I 77 9I - G7 ! GI D7 DI When the ! and - pointers cross each other the pivot value is interchanged with the value at right pointer. *f the pivot is changed it means that the pivot has occupied its original position in the sorted order 1shown in bold italics2 and hence two different arrays are formed, one from start of the original array to the pivot position<1 and the other from pivot position>1 to end. 60 ! 55 ! 50 ! 47 47 47 7I 7I 55 77 60 60 65 65 65 85 ! 70 70 GI GI ! GI ! D7 D7 D7 DI 85 85

*n the ne"t pass we get the sorted form of the array. 45 HH. 50 55 60 65 70 75 80 85

What is meant by internal and e"ternal searching? When the records to be searched resides in the main memory, then it is said to be internal searching. When the records to be searched resides fully in the secondary storage or part of the records resides in main memory and the remaining part resides in secondary storage, then it is said to be e"ternal searching.

1II.

QQQQQQQQQQQ and QQQQQQQQQQ are the two seFuential searching methods available to reduce the number of comparison and retrieving the records faster. Answer# 'ove<to<front and 3ransposition 1I1. 8"plain about move<to<front and transposition techniFues. *n the move<to<front method, whenever the desired record is located, it will be placed at the beginning of the list. *n the transposition techniFue, the record located will be interchanged with the record that precedes it. 1I . What are the methods available in storing seFuential files? &traight merging, (atural merging, 6oly<phase sort, Distribution of *nitial runs. 1I+. Which is the simplest file structure? seFuential inde"ed random Answer: a2 seFuential

8"ercises# Write an eFuivalent one line statement for the following test of Fueue to be empty. if1F.front BB F.rear2 returns 13-R82 else return 15A!&82 . 3he condition F.rear J F.front in a Fueue refers to 1

1. Eueue is full . Eueue is empty +. (one of the above +. -epresent the following binary tree using array.

Potrebbero piacerti anche