DSA MidTerm Exam 20202021 Sample001

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Data Structures and Algorithms – Midterm Examination 16 March 2021

University of Science & Technology Level : 2nd Level IT


Ibb Branch Semester : 2nd 2020/2021
Faculty of Computing & IT Duration : 1 Hour
IT Programs Lecturer : Dr. Redhwan Q. Shaddad

Name: ………………………………………………………………………………………..

Answer all the following questions:

Q1. a) Write a C++ function evenNo( ) to return the count of even numbers in a
8
positive integer array with n elements.

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

b) Write a code to call this function for an integer array A with 5 elements. Assign the returned value to an

integer variable x.

…………………………………………………………………………………………………………………

c) Run the code in (b); since the array A is given as: { 12, 13, 15, 3, 2}.

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………
Page 1 of
SAMPLE0
Data Structures and Algorithms – Midterm Examination 16 March 2021
University of Science & Technology Level : 2nd Level IT
Ibb Branch Semester : 2nd 2020/2021
Faculty of Computing & IT Duration : 1 Hour
IT Programs Lecturer : Dr. Redhwan Q. Shaddad

Q2. 12 For a linked list head with 5 nodes with the following information:

10.3 -2.5 13.4 25.7 -8

a) Write a definition for nodeType record which is used to declare this linked list.

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

b) Declare the linked list head.

…………………………………………………………………………………………………………………

c) Write definition of buildListBackward( ) function to create a linked list.

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

Page 2 of
SAMPLE0
Data Structures and Algorithms – Midterm Examination 16 March 2021
University of Science & Technology Level : 2nd Level IT
Ibb Branch Semester : 2nd 2020/2021
Faculty of Computing & IT Duration : 1 Hour
IT Programs Lecturer : Dr. Redhwan Q. Shaddad

d) Write a code to call the buildListBackward( ) function for the head list.

…………………………………………………………………………………………………………………

e) Write definition of Neg_to_Zero()function which resets the negative data of list nodes to zeros.

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

f) Run the following code for the given data above for head list:

head = Neg_to_Zero(head);

nodeType* current;

current=head;

while (current != NULL)

{ cout << current->info << " ";

current = current->link; }

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………

Good Luck

Page 3 of
SAMPLE0

You might also like