0% found this document useful (0 votes)
35 views

First Semester 2014 - 2015: Department: Computer Engineering Al-Farabi University College

This document contains an exam for a data structures and algorithms class. It has 4 questions. Question 1 deals with binary search trees and includes drawing a tree from a sequence of keys and performing some operations on it. Question 2 involves using depth-first search to find a path between two nodes in a graph and calculating the memory requirements for adjacency matrices and lists. Question 3 covers object-oriented programming and differences between arrays, linked lists, and trees. Question 4 compares bubble and insertion sort, writes a C++ program to store a message in a word file, and analyzes the output of two C++ programs - one implementing a queue with an array and the other showing queue operations. The exam is out of 25 total marks and wishes

Uploaded by

Gafeer Fable
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

First Semester 2014 - 2015: Department: Computer Engineering Al-Farabi University College

This document contains an exam for a data structures and algorithms class. It has 4 questions. Question 1 deals with binary search trees and includes drawing a tree from a sequence of keys and performing some operations on it. Question 2 involves using depth-first search to find a path between two nodes in a graph and calculating the memory requirements for adjacency matrices and lists. Question 3 covers object-oriented programming and differences between arrays, linked lists, and trees. Question 4 compares bubble and insertion sort, writes a C++ program to store a message in a word file, and analyzes the output of two C++ programs - one implementing a queue with an array and the other showing queue operations. The exam is out of 25 total marks and wishes

Uploaded by

Gafeer Fable
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Al-Farabi University College

Department: Computer Subject: Data Structures and


Engineering Algorithms
Attempt: Class: 2nd Class
Examiner: Asst. Lect. Qasim Hadi Date:
Time: 3:00 hour
First semester
2014 - 2015
Notes: Answer four questions. Marks are distributed as follow: 13 marks for section A and 12 marks for section B.

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.3/A/ Write an object oriented (OO) program to represent simple constructor.


Q.3/B/ Answer the following:
1- What are the differences between arrays and linked lists.
2- What are the differences between linked list and trees.

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;}

Head of Department Good Luck Lecturer


2-2

You might also like