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

DSA V4 Lab Final Paper

This document contains instructions and questions for a Data Structures and Algorithms exam. It provides 3 questions to test knowledge of recursive functions, circular doubly linked lists, and binary search trees. Students are asked to implement functions to find the second largest element in an array recursively, create a circular doubly linked list class, and start building a binary search tree class to store student records. The exam allows 3 hours and is out of 100 total marks.

Uploaded by

Ahmad Dawood
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)
83 views

DSA V4 Lab Final Paper

This document contains instructions and questions for a Data Structures and Algorithms exam. It provides 3 questions to test knowledge of recursive functions, circular doubly linked lists, and binary search trees. Students are asked to implement functions to find the second largest element in an array recursively, create a circular doubly linked list class, and start building a binary search tree class to store student records. The exam allows 3 hours and is out of 100 total marks.

Uploaded by

Ahmad Dawood
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/ 3

University of Management and Technology, Lahore Campus

Terminal Examination – FALL 2020


Credit
Course Title: Data Structure and Algorithm Lab Course Code: CC2042L 1
Hrs:
Course Programme
Muhammad Waheed Waqar BSCS
Instructor/s: Name:

Semester: 3rd Batch: SP19 Section: Date: 10th Feb, 2021


V4

Time Allowed: 3 Hr. Maximum Marks: 100

Student’s Name: Reg. No.

Important Instructions / Guidelines:


● All questions are compulsory. Manage time properly and try to attempt easy problems first.
● Questions understanding is the part of exam.
● Cheating will result in negative marking.
Best of Luck!!!

Question No. Obtained Marks Maximum Marks


1 20

2 40

3 40

100

Page | 1
Question #1
Implement a recursive C++ function which takes an array of integers (arr) and the starting
(start) and ending (end) indices of a portion (part) of this array, and returns the index of the
second largest element present in that portion of array arr. The prototype of your function
should be:
int findSecondLargest (int* arr, int start, int end)
For example, the function call findSecondLargest(arr,3,8) should determine and return the
index of the second largest element present in the array arr between the indices 3 and 8 (both
inclusive).

Question #2
Implement a class for Circular Doubly Linked List (with a dummy header node) which
stores integers in unsorted order. Your class definitions should look like as shown below:

class CDLinkedList;
class DNode {
friend class CDLinkedList;
private:
int data;
DNode* next;
DNode* prev;
};
class CDLinkedList {
private:
DNode head; // Dummy header node
public:
CDLinkedList(); // Default constructor
bool insert (int val); // Inserts val into the linked list. Time complexity: O(1)
bool removeLastValue (int v);
//Note: Remove the last val from the linked list. Time complexity: O(1)

void findMiddleValue(); // find middle value of the linklist and delete it.
void display(); // Displays the contents of linked list on screen …
};

Question #3
In this lab you are going to start implementing a class for creating and storing Binary Search
Trees (BST). Each node of this BST will store the roll number, name and CGPA of a
student. The class definitions will look like:

class StudentBST;
class StudentNode {
friend class StudentBST;
private:
Page | 2
int rollNo; // Student’s roll number (must be unique)
string name; // Student’s name
double cgpa; // Student’s CGPA
StudentNode* left; // Pointer to the left subtree of a node
StudentNode* right; // Pointer to the right subtree of a node
};

class StudentBST {
private:
StudentNode* root; // Pointer to the root node of the tree
public:
StudentBST(); // Default constructor
};

bool insert (int, string, double)


This function will insert a new student’s record in the BST. The 3 arguments of this function
are the roll number, name, and CGPA of this new student, respectively. This function will
check whether a student with the same roll number already exists in the tree. If it does not
exist, then this function will make a new node for this new student, insert it into the tree at its
appropriate location, and return true. If a student with the same roll number already exists,
then this function should return false.
bool search (int)
This function will search the BST for a student with the given roll number. If such a student
is found, then this function should display the details (roll number, name, and CGPA) of this
student and return true. If such a student is not found then this function should display an
appropriate message and return false.
void displayInRange (double cgpaStart, double cgpaEnd)
This function will search the BST for those students whose CGPA is between cgpaStart and
cgpaEnd (both inclusive). The records of all such student should be displayed in ascending
order of their Roll Numbers.
Hint: You may need to implement one or more helper functions.

Page | 3

You might also like