Attribution Non-Commercial (BY-NC)

13 views

Attribution Non-Commercial (BY-NC)

- American Computer Science League (ACSL) Rules and Handbook
- Amcat Sample Questions 5
- ISROTechnicalPaper2009
- Trees (1)
- Shortest path algorithms, Java collections framework and AVL tree
- MCA programming and c++ note
- (www.entrance-exam.net)-ISRO Sample Paper 6
- Data Structures
- Stc
- ds
- Improving Multicast Tree
- Model View 2
- Report Study on Cooperative Data Dissemination_153903015.pdf
- analyser
- LSD
- AVL
- heap sort
- GraphPresentation
- Mapping Contoured Terrain_A Comparison of SLAM Algorithms for RAdioControlled Helicopters
- 15 Union Find

You are on page 1of 10

Two mark questions and Answers- Tree Structures Djikstra s Algorithm Prim s Algorithm Pushpa Savithri.R 9/12/2011

Two marks

1) What is non-linear data structure? The data structure in which the data is arranged in a linear or in straight order is said to be linear data structure. 2) Define the term tree. Give one example. Tree is a collection of two sets: vertices and edges. There is one special node in trees which is called root. For example,

a b c

3) Define binary tree. Binary tree is a tree in which no node can have more than two children. Maximum number of nodes at level i of a binary tree is 2^i+1 example:

b D e f A

4)

Struct Treenode { int element; struct TreeNode *left; struct TreeNode *right; 2

Two marks

};

5)

Compare general tree and binary tree: GENERAL TREE BINARY TREE It has not more than two children. Example:

15

y y

15

18

20

10

20

25

6) What are the two ways of implementing the binary tree? y y Linear representation Linked representation

7) Compare full binary tree and complete binary tree *Full binary tree of height h has 2^n+1-1 node. * A complete binary tree of height h has between 2^n and 2^n-1 nodes. *Each node should have two children. *In the bottom level element should be filled from left to right. *A full binary tree can be a complete binary tree. Example:

A

A

8) How you will represent a binary tree using linear representation? The elements are represented using arrays. For any element in position i , the left child is in position 2i, the right child is in position (2i+1),

Two marks

A

A

D E F G

B 2

C 3

D 4

E 5

F 6

G 7

9) How will you represent a binary tree using linked representation? The elements are represented using pointers.Each node in linked representation has three fields namely, *pointer to the left subtree *data field *pointer to the right subtree.

A

10) Define expression tree y y Expression tree is a binary tree in which the leaf node are operands and the interior nodes are operators. Like binary tree,expression tree can also be traversed by inorder, preorder and postorder traversal.

11) What are rules for constructing the expression tree? y y Read one symbol at a time from the postfix expression. Check whether the symbol an operator or operand. (a)If the symbol is an operand , create a one-node tree and push a pointer on to the stack.

Two marks

(b) If the symbol is an operand pop two pointers from the stack namely T1 and T2 and from a new tree with root as the operators and T2 as a left child and T1 as a right child . A pointer to this new tree is then pushed onto the stack.

12) Define binary search tree. Binary search tree is a binary tree in which for every node X in the tree , the values of all the keys in its left subtree are smaller than the key value in X , and the values of all the keys in its right subtree are larger than the key value in X.

19

10

22

20

13) Compare binary tree and binary search tree. BINARY TREE *A tree is said to be a binary tree if it has atmost two children . BINARY SEARCH TREE *A binary search tree is a binary tree in which the key values in the left node is less than the root and the key values in the right node is greater the root. 4

4

10

10

12

12

14) write the declaration for binary search tree. Struct treenode; Typedef struct treenode *searchtree; Searchtree insert(int x, searchtree T); 5

Two marks

Searchtree delete(int x, searchtree T); Int find(int x, searchtree T); Int findmin(seachtree T); Int findmax(searchtree T); Searchtree makeempty(searchtree T); Struct treenode { Int element; Searchtree left; Searchtree right; };

15) Create a routine to make an empty tree. Searchtree makeempty(searchtree T) { If(T!=NULL) { Makeempty(T->left); Makeempty(T->right); Free(T); } Return NULL; }

16) create a routine for find operation. Int find(int x, searchtree T) { If(T=NULL) 6

Two marks

Return NULL; If(x<T->element) Return find(x,T->left); Else If(x<T->element) Return find(x,T->right); Else Return T; }

17) Write a routine for find min. //RECURSIVE: Int findmin(searchtree T) { If(T=NULL) Return NULL; Else if(T->left==NULL) Return T; Else Return findmin(T->left); } //NON RECURSIVE: Int findmin(searchtree T) { If(T!=NULL) While(T->left!=NULL) T=T->left; Return T; 7

Two marks

18) Write a routine for findmax. //RECURSIVE: Int findmin(searchtree T) { If(T=NULL) Return NULL; Else if(T->right==NULL) Return T; Else Return findmax(T->right); } //NON RECURSIVE: Int findmin(searchtree T) { If(T!=NULL) While(T->right!=NULL) T=T->right; Return T; }

19) What are the various traversals of binary tree? Inorder traversal Preorder traversal Postorder traversal 20) Define AVL tree 8

Two marks

* AVL Tree is named after its inventors Adelson-Velskill and LANDIS *An AVL tree is an binary search tree except that for every node in the tree , the height of the left and right subtrees can differ by atmost 1. *The height of the empty tree is defined to be -1.

21) When the tree causes imbalance? Case 1: An insertion into the left subtree of the left child of node a. Case 2: An insertion into the right subtree of the left child of node a. Case 3: An insertion into the left subtree of the right child of node a. Case 4: An insertion into the right subtree of the right child of node a.

22) How will you overcome the imbalances in an AVL Tree? y y Single rotation Double rotation

23) What is priority queue? A priority queue is a special kind of queue data structure which will have precedence over jobs. Basic operations performed by priority queue are: y y Insert operarion DeleteMin operation

24) What is need for priority queue? In multiuser environment, the operating system scheduler must decide which of several processes to run. The scheduler will take the first job on the queue and allow it to run until either it finishes or its time limit its up. Generally a process is allowed to run only for a fixed period of time. It can be overcome by using priority queue in which short jobs are assigned a higher precedence. 25) What are the implementation methods of priority queue? y y Linked list binary search tree 9

Two marks

binary heap.

26) Define binary heap. The efficient way of implementing the priority queue is the binary heap. Heap have two properties namely Structure property Heap order property Structure property where the tree must be complete binary tree Heap order property where the root node must the minimum node.

27) What are other heap operations? y y y y Decrease key Increase key Delete Build heap

28) What is build heap? The build Heap operations takes as input N keys and places them into an empty heap by maintaining structure property and heap order property.

10

- American Computer Science League (ACSL) Rules and HandbookUploaded bybellataco
- Amcat Sample Questions 5Uploaded byYekanth Kola
- ISROTechnicalPaper2009Uploaded byypragati
- Trees (1)Uploaded byshillusingh
- Shortest path algorithms, Java collections framework and AVL treeUploaded bySayyid Fatmi
- MCA programming and c++ noteUploaded byAmit Jaju
- (www.entrance-exam.net)-ISRO Sample Paper 6Uploaded byMradul Saxena
- Data StructuresUploaded byMuhammad Ali
- StcUploaded byHoàng Công
- dsUploaded byVivek Gupta
- Improving Multicast TreeUploaded byJebakumar Gomer Rajadurai
- Model View 2Uploaded bynishantapatil
- Report Study on Cooperative Data Dissemination_153903015.pdfUploaded byWahab Kukaswadia
- analyserUploaded bymrvinodk
- LSDUploaded bymeisamtey
- AVLUploaded byepanicu2000
- heap sortUploaded byhari
- GraphPresentationUploaded bynagarajuvcc123
- Mapping Contoured Terrain_A Comparison of SLAM Algorithms for RAdioControlled HelicoptersUploaded byGeoFurriel
- 15 Union FindUploaded byPequeño Cerz
- je25Uploaded bykracha82
- data structureUploaded byAkash Madan
- b+ tree insertion & deletionUploaded bySubhash Singh
- Chapter 11 ProjectsUploaded byDeepakKattimani
- heapsort1Uploaded byMohammed Jeelan
- Review_8Uploaded byWalid_Sassi_Tun
- Recognition of 3D ObjectsUploaded byDan
- 2solUploaded byAditya Mishra
- Lesson 7Uploaded byAnonymous iUW0JL6O5
- Carpeta Digital.docxUploaded byJuandi RV

- Design and Analysis of Algorithms 2 Marks and 16 MarksUploaded bymiraclesuresh
- MCS-021 Solved Assignment 2015-16Uploaded byAnonymous Qnf6YdFX
- Data StructuresUploaded bySwati Sukhija
- Spell CheckerUploaded byوقاص وکی
- Data Structure mcqsUploaded byRizwan Ali
- hash DSUploaded bysj819
- MIT6_006F11_lec06Uploaded byximbica
- AVL TreesUploaded byHanadi Dkheel
- Lecture12-4Uploaded byJohnathan Hok
- AVL trees.pptUploaded byVinay Yadav
- Data Structures and AlgorithmsUploaded byabhi
- Data Structures and AlgorithmsUploaded byabhi
- quiz1-solUploaded byJoe Knut Ant
- avl treesUploaded bysaiteja1234
- CS6301-Programming and Data Structures-IIUploaded bySriRithanya
- AVL-Tree-Properties.pdfUploaded byRajContent
- Sem II & IIIUploaded byAnsari Sharique
- Dynamic Practice 2Uploaded byHemesh Singh
- DS LAB MANUAL(B.E)Uploaded bypitchrks19841
- DSA interview questions QuestionUploaded byChirag
- MCQsUploaded bysaimanobhiram
- CS301 Midterm Papers Collection Shared by Sweet SoulUploaded byAamir Amin
- Cs9215 Datastructures Lab Manual Usingj AvaUploaded bymanimaran
- EE2204 DSA 100 2marksUploaded byVinod Deenathayalan
- UNIT III.docxUploaded byJayakumar Loganathan
- Avl TreeUploaded byKunal Sekhri
- AVLTreesUploaded byGirlscoutcookie
- Advanced Data Structures NotesUploaded byChinkal Nagpal
- Advanced Data Structure IT-411Uploaded byRajesh Krishnamoorthy

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.