Mid Term Exam of Data Structures Spring 2012, Exams of Data Structures and Algorithms

The mid-term exam questions for the data structures course during spring 2012. The exam covers various topics such as graph traversal, binary trees, binary search trees, and stacks. Students are required to implement functions and explain concepts related to these data structures.

Typology: Exams

2011/2012

Uploaded on 07/11/2012

dhanyaa
dhanyaa 🇮🇳

4.7

(3)

60 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name: Reg. No: ___
Midd Term Exam of Data Structures Spring 2012 Page 1 of 2
CS2143-2144 Data Structures Time 90 Minutes
Max. Marks 50
Note: Carefully understand the questions and give to the point answers. Write neat and
clear so that one can understand. Do not split the code to more than one page. Write all
the assumption, if you have made, before writing the code.
1. [10] For the following graph class, implement the function, void DFS (int v), to print all the
vertices of the graph in depth first traversal order starting from vertex v. Assume that all the
other methods given in the class have been implemented.
2. [10] For the following binary tree class (not a BST), implement the functions / methods
given in the class.
3. [10] For the following binary search class, implement the insert and search methods.
class graphWithArrays
{
protected:
int **G;
unsigned int size;
int *visit;
public:
graphWithArrays(unsigned int x);
void storeGraph();
void printGraph();
void DFS (int v);
};
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 Find(int v); // Find value element v node in the binary tree. if found
//return the index of the location where it is found. Otherwise, return -1
int findCousine(int v) // find index of the cousin of the node with index v (whose
//grandparent is same
PostOrderVisit (int v) // A function to visit the tree in post order, starting from
//node with index v,
};
Docsity.com Docsity.com
pf2

Partial preview of the text

Download Mid Term Exam of Data Structures Spring 2012 and more Exams Data Structures and Algorithms in PDF only on Docsity!

Name: Reg. No: ___

Midd Term Exam of Data Structures Spring 2012 Page 1 of 2

CS2143-2144 Data Structures Time 90 Minutes

Max. Marks 50

Note: Carefully understand the questions and give to the point answers. Write neat and

clear so that one can understand. Do not split the code to more than one page. Write all

the assumption, if you have made, before writing the code.

1. [10] For the following graph class, implement the function, void DFS (int v), to print all the

vertices of the graph in depth first traversal order starting from vertex v. Assume that all the

other methods given in the class have been implemented.

2. [10] For the following binary tree class (not a BST), implement the functions / methods

given in the class.

3. [10] For the following binary search class, implement the insert and search methods.

class graphWithArrays { protected: int **G; unsigned int size; int *visit; public: graphWithArrays(unsigned int x); void storeGraph(); void printGraph(); void DFS (int v); }; 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 Find(int v); // Find value element v node in the binary tree. if found //return the index of the location where it is found. Otherwise, return - 1 int findCousine(int v) // find index of the cousin of the node with index v (whose //grandparent is same PostOrderVisit (int v) // A function to visit the tree in post order, starting from //node with index v, };

Docsity.comDocsity.com

Name: Reg. No: ___

Mid Term Exam of Data structures Spring 2012 Page 2 of 2

4. [20] Briefly Explain the answer to the following questions:

a. How a stack implemented as an array is different from a normal array?

b. Give atleast one good example of the use of a FIFO queue.

c. Draw a sample binary tree with atleast 7 nodes whose preorder traversal is the same

as post order traversal.

d. What is a complete binary tree?

e. What is an almost complete binary tree?

f. What are the differences between a tree and a graph?

g. What is a simple graph?

h. What are the issues when we try to rotate a binary search tree which is implemented

as an array?

i. What is a balanced binary search tree?

j. What are the advantages of a balanced binary search tree as compare to the

unbalanced binary search tree.

class bstree { protected: int *p; // array of values int *f; // array of flag unsigned int size; public: bstree(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 BST, and return 1 if it is inserted properly //otherwise return 0 int search(int v); // search value element v at the proper position in BST. if found //return the index of the location where it is found. Otherwise, return - 1 };

Docsity.comDocsity.com