You are on page 1of 11

INDEX

Sr. Page
Date Experiment Sign Remark
No. no.
Consider telephone book database of N clients. Make
1 use of a hash table implementation to quickly look up
client‘s telephone number
Implement all the functions of a dictionary (ADT)
using hashing.
Data: Set of (key, value) pairs, Keys are mapped to
2 values, Keys must be comparable, Keys must be
unique
Standard Operations: Insert (key, value), Find(key),
Delete(key)
A book consists of chapters, chapters consist of
sections and sections consist of subsections.
3
Construct a tree and print the nodes. Find the time
and space requirements of your method.
There are flight paths between cities. If there is a
flight between city A and city B then there is an edge
between the cities. The cost of the edge can be the
time that flight takes to reach city B from A, or the
amount of fuel used for the journey. Represent this as
4
a graph. The node can be represented by airport
name or name of the city. Use adjacency list
representation of the graph or use adjacency matrix
representation of the graph. Justify the storage
representation used.
Given sequence k = k1 < … < kn of n sorted keys, with
a search probability pi for each key ki. Build the
5
Binary search tree that has the least search cost given
the access probability for each key?
A Dictionary stores keywords & its meanings. Provide
facility for adding new keywords, deleting keywords,
updating values of any entry. Provide facility to
display whole data sorted in ascending/ Descending
6
order. Also find how many maximum comparisons
may require for finding any keyword. Use Height
balance tree and find the complexity for finding a
keyword.
Implement the Heap/Shell sort algorithm
7 implemented in Java demonstrating heap/shell data
structure with modularity of programming language.
Read the marks obtained by students of second year
in an online examination of particular subject. Find
8 out maximum and minimum marks obtained in a that
subject. Use heap data structure. Analyze the
algorithm.
Department maintains a student information. The file
contains roll number, name, division and address.
Allow user to add, delete information of student.
9 Display information of particular employee. If record
of student does not exist an appropriate message is
displayed. If it is, then the system displays the student
details. Use sequential file to main the data
Construct an expression tree from the given prefix
expression eg. +--a*bc/def and traverse it using post
10
order traversal (non recursive) and delete the entire
tree.

Convert binary tree into threaded binary tree.


11
Analyze time and space complexity of algorithm
Program: 10
#include<string>
#include <iostream>
using namespace std;
class node_cls;
class tree_cls;
const int MAX=50;
 class Data_stck
{
 int top;
 node_cls *info[MAX];
public:
 Data_stck()
{
 top=-1;
 }
 void push(node_cls *cnode_cls)
 {
 top=top+1;
 info[top]=cnode_cls;
 }
 node_cls *Top()
 {
 return info[top];
 }
 node_cls * pop()
 {
 if(!empty())
 {
 return info[top--];
 }
 return NULL;
 }
 bool empty()
 {
 if(top==-1)
 return true;
 else
 return false;
 }
 bool isFull()
 {
 if(top==MAX-1)
 return true;
 else
 return false;
 }
};
class node_cls
{
 node_cls *left,*right;
 char data;
public:
 node_cls()
{
 left=right=NULL;
}
 node_cls(char ch)
 {
 left=right=NULL;
 data=ch;
  }
 friend class tree_cls;
};
class tree_cls
{

public:
 node_cls *root;
 tree_cls()
{
 root=NULL;
}
 void create(string str);
 void inorder_rec(node_cls *rnode_cls);
 void postorder_rec(node_cls *rnode_cls);
 void inorderNonRec();
void postorder()
 {
 postorder_rec(root);
 }
 void inorder()
 {
 inorder_rec(root);
 }
 int priority(char ch);
 void deleteTree(node_cls* node)
{
 if (node == NULL) return;
 /* first delete both subtrees */
 deleteTree(node->left);
 deleteTree(node->right);

 /* then delete the node */


 cout << "\n Deleting node: " << node->data;
 delete node;
}
};
int tree_cls::priority(char ch)
{
 switch(ch)
 {
 case '+':
 case '-':
 return 0;
 break;
  case '*':
 case '/':
 return 1;
 break;
 case '^':
 return 2;
 break;
 }
 return -1;
}
void tree_cls::inorderNonRec()
{
 node_cls *ptr=root;
 Data_stck s1;
 X:while(ptr!=NULL)
 {
 s1.push(ptr);
 ptr=ptr->left;
 }
 ptr=s1.pop();
 while(ptr!=NULL)
 {
 cout<<" "<<ptr->data;
 if(ptr->right!=NULL)
 {
 ptr=ptr->right;
 goto X;
 }
 ptr=s1.pop();
 }
}
void tree_cls::inorder_rec(node_cls *rnode_cls)
{
 if(rnode_cls)
 {
 inorder_rec(rnode_cls->left);
 cout<<" "<<rnode_cls->data;
 inorder_rec(rnode_cls->right);
 }
}
void tree_cls::postorder_rec(node_cls *rnode_cls)
{
 if(rnode_cls)
 {
 postorder_rec(rnode_cls->left);
 postorder_rec(rnode_cls->right);
 cout<<" "<<rnode_cls->data;
 }
}
void tree_cls::create(string str)
{
 Data_stck s1,s2;
 int i=0;
 char ch;
 while(str[i]!='\0')
 {
 //cout<<"in create()";
 ch=str[i];
 if(isalpha(ch)) //s1 operand data_stck and s2===operator
 {
 node_cls *temp=new node_cls(ch);
 s1.push(temp);
 }
 else //operator
 {
 //cout<<"in operator block()";
 if(s2.empty())
 {
 node_cls *temp=new node_cls(ch);
 s2.push(temp);
 }
 else if(priority(ch)>priority(s2.Top()->data))
 {
 node_cls *temp=new node_cls(ch);
 s2.push(temp);
 }
 else
 {
 while(!s2.empty()&&priority(ch)<=priority(s2.Top()->data) )
 {
 node_cls *op=s2.pop();
 node_cls *rchild=s1.pop();
 node_cls *lchild=s1.pop();
 op->right=rchild;
 op->left=lchild;
 s1.push(op);
 }
 s2.push(new node_cls(ch)); //push operand at last
 }
 }
 i++;
 //cout<<" i "<<i;
 }
 while(!s2.empty()) //pop() until operator data_stck is not empty
 {
 node_cls *op=s2.pop();
 node_cls *rchild=s1.pop();
 node_cls *lchild=s1.pop();
 op->right=rchild;
 op->left=lchild;
 s1.push(op);
 }
 //set the root element to s1->top()
 root=s1.pop();
}
int main() {
 cout << "" << endl; // prints
 tree_cls t1;
 string exp="+--a*bc/def";
 cout<<"\nOriginal Expression: "<<exp;
 t1.create(exp);
 cout<<"\nInorder Traversal Recursive: ";
 t1.inorder();
 cout<<"\nInorder Non-Recursive: ";
 t1.inorderNonRec();
 cout<<"\nPostorder Traversal recursive: ";
 t1.postorder();
 cout<<"\nDeleting Tree : ";
 t1.deleteTree(t1.root);
 cout<<"\nEntire tree is deleted..";
 return 0;
}

Output:
Program: 11
#include <iostream>
#include <queue>
using namespace std;
struct Node {
 int key;
 Node *left, *right;
 bool isThreaded;
};
void setQ(Node* root, std::queue<Node*>* q){
 if (root == NULL)
 return;
 if (root->left)
 setQ(root->left, q);
 q->push(root);
 if (root->right)
 setQ(root->right, q);
}
void generate_thrdtre(Node* root, std::queue<Node*>* q){
 if (root == NULL)
 return;
 if (root->left)
 generate_thrdtre(root->left, q);
 q->pop();
 if (root->right)
 generate_thrdtre(root->right, q);
 
 else {
     root->right = q->front();
 root->isThreaded = true;
 }
}

void createThreaded(Node* root){


 std::queue<Node*> q;
 setQ(root, &q);
 generate_thrdtre(root, &q);
}
Node* leftMost(Node* root){
 while (root != NULL && root->left != NULL)
 root = root->left;
 return root;
 }
 void inOrder(Node* root){
 if (root == NULL)
 return;
 Node* cur = leftMost(root);
 while (cur != NULL) {
 cout << cur->key << " ";
 if (cur->isThreaded)
 cur = cur->right;
 else
 cur = leftMost(cur->right);
 }
 }
 Node* createND(int key){
 Node* temp = new Node;
 temp->left = temp->right = NULL;
 temp->key = key;
 return temp;
}
int main(){
    Node* root = createND(1);
 root->left = createND(2);
 root->right = createND(3);
 root->left->left = createND(4);
 root->left->right = createND(5);
 createThreaded(root);
 cout << "Threaded tree : ";
 inOrder(root);
 return 0;
}
Output:

You might also like