0% found this document useful (0 votes)
815 views2 pages

Bahria University, Islamabad Campus: Department of Computer Science

The document is the midterm exam paper for Data Structures and Algorithms class. It contains 3 questions. Question 1 asks to define functions for operations on linked lists representing student enrollment data. Question 2 contains parts on suitable data structures, converting infix to postfix notation, evaluating a postfix expression, and demonstrating contents of a circular queue after operations. Question 3 asks to traverse a binary tree using a given traversal function and write the output.

Uploaded by

Javed bajwa
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)
815 views2 pages

Bahria University, Islamabad Campus: Department of Computer Science

The document is the midterm exam paper for Data Structures and Algorithms class. It contains 3 questions. Question 1 asks to define functions for operations on linked lists representing student enrollment data. Question 2 contains parts on suitable data structures, converting infix to postfix notation, evaluating a postfix expression, and demonstrating contents of a circular queue after operations. Question 3 asks to traverse a binary tree using a given traversal function and write the output.

Uploaded by

Javed bajwa
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

Bahria University, Islamabad Campus

Department of Computer Science


Mid Term Examination
Class/Section: BSCS-3 (A/B)
(Spring 2021 Semester)
Paper Type: Descriptive
Course: Data Structure and Algorithm Date: 22/5/2021
Course Code: CSC 221 Time: 9:00 AM-10:30 AM
Faculty’s Name: Momina Moetesum Max Marks: 20
Time Allowed: 90 Minutes Total Pages: 2 (including this)

INSTRUCTIONS:
I. All questions are compulsory.
II. There are total four questions.
III. Answers should either be typed or handwritten, screenshots of codes on the IDE are not allowed.

Student’s Name: _____________________________Enroll No:______________________


(USE CAPITAL LETTERS)

Questi on # 1 : (6 Mar ks)


An instructor is teaching two courses in this semester. He maintains a separate list
of all the students enrolled in each course. Some of the students are enro lled in
both of his courses while some are enrolled in only one. Consider the given class
ADTs, and give function definitions of the following stand -alo ne, non-member
functions.

*Note: use the given ADT functions only.

Node Class AD T Singly Linked List Class ADT


class Node class List
{ {
public: public:
string name; Node *head;
int marks; List(); //constructor
Node *next; void insert_end(string, int); //inserts node at end
}; bool isPresent(string); //determines if a node is present
bool isEmpty(); //determines if list is empty
};

i. Node* c omStudents(N ode *h1, Node *h2): The function takes the address of
the heads of the two non-empty lists as arguments and returns the head of a
list containing the data of those students that are enrolled in both courses.

ii. void avgMarks(Node *h): The function takes the head of a non -empty list as
an argument and prints the average marks obtained by the students of the
class.

Page 1 of 2
Enrollment Number: ____________________________

iii. int count(Node *h, int m): The function returns the number of students in a
non-empty list who obtained marks equal to or greater than the value passed
as argument.

Questi on # 2 : (2+2+2+4 Marks)

Attempt eac h parts. Show worki ng steps where necessary.

i. Which data structure is suitable in the given scenario and why? To keep track
of the incoming patients as they check into a clinic and to assign them to
available doctors on first come first served basis except for when a patient
requiring emergency treatm ent checks in , then he is served first.

ii. Convert the given infix expression into its equivalent postfix expression.
(a/(b-c+d))*(e -a)*c

iii. Evaluate the given postfix expression.


5213*-6*82/1-/+

iv. Considering an empty static circular Queue ADT of size 6, show the contents
of Queue after the fo llowing code snippet is executed . Also show the final
positions of fr ont and rear.
Note*: Initially both front and rear are at 0 index

for ( i n t x = 1 ; x < = 6 ; x + + )
{
q.enqueue(x);
}
for ( i n t i = 1 ; i < = 5 ; i + + )
{
cout<<q.dequeue();
q . e n q u e u e ( q . d e q u e u e() );
}

Questi on # 3 : (4 Marks)

Traverse the given binary tree using the following traversal function and write the
output. Note*: I nitial ly the root of the tr ee is passed as an argument to the
functi on.
void Traversal(Node* temp)
{
if(t e m p = = N U L L )
return;
elseif(temp!=NULL)
{
cout<<temp->data;
Traversal(temp->left);
Tr a v e r s a l ( t e m p - > r i g h t ) ;
co u t < < t e m p - > d a t a ;
}
}
Output:

End of Question Paper


Page 2 of 2

You might also like