13 views

Uploaded by Pushpa Ramakrishnan Iyer

- mcq
- data stucture and algorithm questions
- 2IL65 Assignment 6 Khanh
- Rao Lecture 8
- tu5
- Trees
- binart tree
- Unit 5final
- Operations on Binary Search Tree
- C88-2147.pdf
- Data Structure
- qbOBJORIENTPROGDS
- 07_PriorityQueues
- Lecture 06 Ch6.Trees(1)
- General Ledger Power Point Presentation
- gudlecture11
- Treap_report
- Slicing and Non Slicing Floor Planning
- Tabla Articulos
- Lect 9 Heaps

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

- mcqUploaded byAnam Siddiqui
- data stucture and algorithm questionsUploaded byAnmol Rajat
- 2IL65 Assignment 6 KhanhUploaded byhpkhanh
- Rao Lecture 8Uploaded bySakura2709
- tu5Uploaded byham1988riz
- TreesUploaded byShashwat Jha
- binart treeUploaded byRaven Sarita
- Unit 5finalUploaded byrammar147
- Operations on Binary Search TreeUploaded byM Abdullah
- C88-2147.pdfUploaded byhaliane
- Data StructureUploaded byPradeep Tiwari
- qbOBJORIENTPROGDSUploaded byAjay Ganesan
- 07_PriorityQueuesUploaded byMinh Hung Nguyen
- Lecture 06 Ch6.Trees(1)Uploaded byAnkita Patel
- General Ledger Power Point PresentationUploaded bykmkasanga
- gudlecture11Uploaded bysagargupta012
- Treap_reportUploaded byitzmanohar_bhat
- Slicing and Non Slicing Floor PlanningUploaded bySurbhi Singh
- Tabla ArticulosUploaded byAndres Suarez
- Lect 9 HeapsUploaded byAthanasious Ramsis
- 4AI_N1Uploaded byenggeng7
- Chen Main Josh iUploaded bybobster124u
- venkatesanUploaded byPrabhu Jaysus
- C ProgramUploaded byprabu1928
- MC80Uploaded byAshay Sawant
- Data Structures Cheat SheetUploaded byOmer Shapira
- c Language Basic Programs Which Used for BigginnersUploaded byRavikumar Vendi
- Parallel NotesUploaded byAmaresh Maurya
- KiwiUploaded byPraveen Munagapati
- Improved kinetic Monte Carlo simulationUploaded byEsteban

- Avl TreesUploaded bySoumyadeep Ghosh
- Lecture More AVL TreesUploaded byRam C. Gudavalli
- M3_Non Linear Data StructuresUploaded byresmi_ng
- Space & Time Complexity ChartUploaded bymanan00
- CS301 Final Term MAGA File.. All Paperz Are in 1 File.Uploaded byanumnasik
- AVL TREEUploaded byAnand Yadav
- Data StructuresUploaded byPulkit Kumar
- 081-2008 Many-To-Many Merges in the DATA StepUploaded bymohaha_true
- Introduction-of-AVL-Tree.pdfUploaded byRajContent
- CS301 Midterm Papers Collection Shared by Sweet SoulUploaded byAamir Amin
- AVL B Tree Treap SplayUploaded bySunil Kumar
- Data Structures and AlgorithmsUploaded byDavid Mihai
- AVL_TREESUploaded byGióng Thánh
- TreesUploaded byGamindu Udayanga
- Dynamic Practice 2Uploaded byHemesh Singh
- Threaded Binary TreeUploaded bypramodsoni0007
- Advanced Data Structure IT-411Uploaded byRajesh Krishnamoorthy
- Data Structures PPTUploaded byGuru Samy
- UNIT III.docxUploaded byJayakumar Loganathan
- CSE-II-I-DS-UNIT-6.pdfUploaded bybskc_sunil
- Data Structures Question Bank (2)Uploaded byLn P Subramanian
- DOC-20161217-Uploaded byDV Krish
- Class 21jjUploaded bykazi wahex
- cs301MCQSBYMOAZUploaded byMuhammad Rameez Khalid
- Splay TreesUploaded byEssirahc Lamigo
- OOP & Data structure conceptsUploaded byFahad Mustafa
- AvlUploaded byshaileshkhapre
- PDS IIUploaded bytbuvaneswari2176
- Tutorial 2Uploaded byMiguel Dirane
- avl-treeUploaded bySuruttaiyan Suru