13 views

Uploaded by Pushpa Ramakrishnan Iyer

- Comp 272 Notes
- Top 15 Data Structures and Algorithms Interview Questions
- Compact Scan Mask for 3-D Connected Components Labeling
- Avl Tree
- Fibonacci Heaps Sample
- quiz6
- FP Tree Example
- Decision Tree Analysis
- decision trees
- 22-huffman
- Linked Lists Questions
- Mapping Contoured Terrain_A Comparison of SLAM Algorithms for RAdioControlled Helicopters
- hi
- Descision Tree
- Data Structures Interview Questions
- Technical Aptitude Questions.pdf
- Java Lists
- Final_COS_329_A__Nov_2008
- Les07
- 10.1.1.44

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

- Comp 272 NotesUploaded byqqq wweeew
- Top 15 Data Structures and Algorithms Interview QuestionsUploaded byHector Triana
- Compact Scan Mask for 3-D Connected Components LabelingUploaded byPhaisarn Sutheebanjard
- Avl TreeUploaded byKunal Sekhri
- Fibonacci Heaps SampleUploaded byHebrew Johnson
- quiz6Uploaded byMamta Yadav
- FP Tree ExampleUploaded byAnbuselvan Sangodiah
- Decision Tree AnalysisUploaded bydzuleffendi
- decision treesUploaded bySaiindra Reddy
- 22-huffmanUploaded bymanishbhardwaj8131
- Linked Lists QuestionsUploaded byNeeraj Chaudhary
- Mapping Contoured Terrain_A Comparison of SLAM Algorithms for RAdioControlled HelicoptersUploaded byGeoFurriel
- hiUploaded byCrystal Robinson
- Descision TreeUploaded bylakshay212
- Data Structures Interview QuestionsUploaded bySahil Parmar
- Technical Aptitude Questions.pdfUploaded byPerumal Namasivayam
- Java ListsUploaded byBhaskar Naidu
- Final_COS_329_A__Nov_2008Uploaded bySiti Sarah Buniyami
- Les07Uploaded byClaudian Paduraru
- 10.1.1.44Uploaded byEce Er Arpit Agarwal
- Unit 2 DAAUploaded bySatyanshu Srivastava
- SSRN-id1004460Uploaded bykesk32
- Indexing SchemesUploaded bypoimandres
- W3-4Uploaded byGökhan
- Hierarchical key management v1-3-25Uploaded byc2011Ek7
- Complete Syllabus 2nd Year Non-Credit - CopyUploaded byanishkl
- Year 2012Uploaded byMaajith Marzook
- Data Structure FileUploaded bypankajparashar
- Technical Questions PlacementUploaded byArvind Upadhyay
- TreeUploaded byFreedom Storm

- 06_MIDIUploaded byGourav Agarwal
- Scapulothoracic dissociation_ An emerging high-energy trauma in medical literature _[PAUTHORS], Journal of Emergencies, Trauma, and Shock (JETS).pdfUploaded byTruly Wulandari
- SIALOGRAPHYUploaded byMithun Jith
- (Core Textbook)Teaching ESL Composition-purpose, Process, PracticeUploaded byDanh Vu
- A 2-EEL306Uploaded bySiddhartha Das
- Biapps With OdiUploaded byamoyeed
- sol4_99Uploaded byHossain
- Coleman - Beyond Inclusive Legal PostivismUploaded byAxel Sol
- Fusarium and Verticillium WiltsUploaded bycresdumayac
- Top 50 Questions to Ask Before You Get EngagedUploaded byAnubhav Srivastava
- Rt Toolbox.bfp a8090jUploaded byNur Zaidan
- Power Trex Mv SolutionsUploaded byAurel Dedu
- aiello molly- sas lesson plan 9 - 1-22-16Uploaded byapi-315574774
- Lodbrock Launches First Erotic Fantasy World CollectionUploaded byPR.com
- EDA585 School Excellence Plan All Parts ArguellesUploaded bypatrickarguelles
- Snakes and MysticismUploaded bycharan74
- Non Ossifying FibromaUploaded byGaby Gomez
- a3 syllabusUploaded byapi-285897975
- Roman Celeia of NoricumUploaded bySlovenian Webclassroom Topic Resources
- Trematode sUploaded byWalter Cusihuallpa Auccatinco
- Kripps Newsletter 5Uploaded bysuckerx
- adria-2019-vans-catalogue.pdfUploaded byAnonymous d1KLF1
- katherine lockwood resumeUploaded byapi-330467499
- Part 5 - HTML 5 Drag and Drop, GeoLocationUploaded bySteve Fort
- Installation Guide for Oracle f 3 Ssc sUploaded byJuan Aguilar
- Asch, M., Levi-Strauss and the Political. The Elementary Structures of Kinship and the Resolution of Relations between Indigenous People and Settler states.docUploaded bymiguel_henriques1112
- Legrand USB SeriesUploaded byChoy Ren Yu
- Biological Warfare — Central Intelligence AgencyUploaded byIam
- Soil Microorganism – ActinomycetesUploaded byShailendra Yadav
- ConnectorsUploaded bykabshiel