First Semester 2014 - 2015: Department: Computer Engineering Al-Farabi University College
First Semester 2014 - 2015: Department: Computer Engineering Al-Farabi University College
Q.1/ Draw the binary search tree for the following sequence of keys:
85, 10, 44, 25, 30, 8, 96, 70, 90, 33, 100
And perform the following operations in sequence
1- Insert 73, 18
2- Show the order in which the keys in the tree are processed by an inorder and postorder
3- Delete 44, 8, 100
4- Write a function in C++ to find key 85 in a tree
Q.2/A/ Find a path between two nodes of the graph below (Austin and Washington) by using
Depth-First-Search (DFS)
Q.2/B/ Assume that the vertex index requires four bytes, a pointer requires six bytes, and an
edge weight requires four bytes. What is the memory required by the adjacency matrix and
adjacency list for the above graph.
Q.4/A/ Compare between Bubble and Insertion sort. Explain that with example.
Q.4/B/ Write a C++ program to store the following message in word file.
"You are a good student"
Q.4/ What is the output of the following C++ programs? Show that in sequence.
1-2
a. b. #include <iostream>
class Link using namespace std;
{ public: #define MAX 5
class queue
int iData;
{
double dData; private:
Link* pNext; int t[MAX]; int al; int dl;
Link(int id, double dd) : public:
iData(id), dData(dd), pNext(NULL) queue()
{ dl=-1; al=-1; }
{}
void del()
void displayLink() { int tmp;
{ if(dl==-1)
cout << “{“ << iData << “, “ << dData << “} “; } }; { cout<<"Queue is Empty";}
class LinkList else
{ private: { for(int j=0;j<=al;j++)
{ if((j+1)<=al)
Link* pFirst; { tmp=t[j+1];
public: t[j]=tmp;
LinkList() : pFirst(NULL) }
{} else
bool isEmpty() { al--;
if(al==-1)
{ return pFirst==NULL; }
dl=-1;
void insertFirst(int id, double dd) else
{ Link* pNewLink = new Link(id, dd); dl=0;
pNewLink->pNext = pFirst; }}}}
pFirst = pNewLink; void add(int item)
{ if(dl==-1 && al==-1)
}
{ dl++;
Link* getFirst() al++; }
{ return pFirst; } else
void removeFirst() { al++;
{ Link* pTemp = pFirst; if(al==MAX)
pFirst = pFirst->pNext; { cout<<"Queue is Full\n";
al--; }}
delete pTemp; t[al]=item; }
} void display()
void displayList() { if(dl!=-1)
{ { for(int i=0;i<=al;i++)
cout << “List (first-->last): “; cout<<t[i]<<" "; }
else
Link* pCurrent = pFirst;
cout<<"EMPTY";
while(pCurrent != NULL) } };
{ int main()
pCurrent->displayLink(); { queue a;
pCurrent = pCurrent->pNext; } int data[5]={32,23,45,99,24};
cout<<"Queue before adding Elements: ";
cout << endl; } };
a.display();
int main() cout<<endl<<endl;
{ for(int i=0;i<5;i++)
LinkList theList ; theList.insertFirst(40, 4); {
theList.insertFirst(20, 2) ; theList.insertFirst(50, 5); a.add(data[i]);
theList.insertFirst(70, 7) ; theList.displayList(); cout<<"Addition Number : "<<(i+1)<<" : ";
a.display();
while( !theList.isEmpty() ) cout<<endl; }
{ cout<<endl;
Link* pTemp = theList.getFirst(); cout<<"Queue after adding Elements: ";
cout << “Removing link with key “ << pTemp->iData << a.display();
endl; cout<<endl<<endl;
for(int i=0;i<5;i++)
theList.removeFirst();}
{ a.del();
theList.displayList(); cout<<"Deletion Number : "<<(i+1)<<" : ";
return 0; a.display();
} cout<<endl; }
return 0;}