CS2143-2144 Data Structures Quiz 5: Binary Tree Implementation, Exercises of Data Structures and Algorithms

The instructions for quiz #5 of the cs2143-2144 data structures course for spring 2012. Students are required to implement certain functions for a binary tree class, including insertion, finding values, checking if a node is a leaf, finding the height, finding a parent node, and finding a cousin node.

Typology: Exercises

2011/2012

Uploaded on 07/11/2012

dharanidhar
dharanidhar 🇮🇳

4.2

(6)

58 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS2143-2144 Data Structures Spring 2012
Quiz # 5(22 March 2012)
Time 10 Minutes
Max. Marks 10
Name: Reg. No: ___
For the following binary tree class (not a BST), implement the functions / methods
given in the class.
class btree
{
protected:
int *p; // array of values
int *f; // array of flag
unsigned int size;
public:
btree(unsigned int s)
{ int i;
p = new int [s];
f = new int [s];
size = s;
for (i=0; i<s; ++i)
f[i] = 0;
}
int insert(int v); //insert value v in the first available empty node of the tree, and
// return 1 if it is inserted properly, otherwise return 0
int Find(int v); // Fin value element v node in the binary tree. if found
//return the index of the location where it is found. Otherwise,
//return -1
int isLeaf(int i); // return TRUE (1) if the node with index i is a leaf, otherwise
// return FALSE (0)
int Height() // find and return height of the tree which has been built
int findParent(int v) // find the index of the parent node of the node with index v,
//return -1 if the node does not have a parent.
int findCousine(int v) // find index of the cousin of the node with index v (whose
// grandparent is same (grand parent of v and its cousins
//will be same. it means maximum a node in binary tree
//can have three cousins.
};
Docsity.com

Partial preview of the text

Download CS2143-2144 Data Structures Quiz 5: Binary Tree Implementation and more Exercises Data Structures and Algorithms in PDF only on Docsity!

CS2143-2144 Data Structures Spring 2012

Quiz # 5(22 March 2012)

Time 10 Minutes

Max. Marks 10

Name: Reg. No: ___

For the following binary tree class (not a BST), implement the functions / methods

given in the class.

class btree { protected: int *p; // array of values int *f; // array of flag unsigned int size;

public: btree(unsigned int s) { int i; p = new int [s]; f = new int [s]; size = s; for (i=0; i<s; ++i) f[i] = 0; }

int insert(int v); //insert value v in the first available empty node of the tree, and // return 1 if it is inserted properly, otherwise return 0 int Find(int v); // Fin value element v node in the binary tree. if found //return the index of the location where it is found. Otherwise, //return - int isLeaf(int i); // return TRUE (1) if the node with index i is a leaf, otherwise // return FALSE (0) int Height() // find and return height of the tree which has been built

int findParent(int v) // find the index of the parent node of the node with index v, //return -1 if the node does not have a parent. int findCousine(int v) // find index of the cousin of the node with index v (whose // grandparent is same (grand parent of v and its cousins //will be same. it means maximum a node in binary tree //can have three cousins. };

Docsity.com