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

DSA-Class-Assignment 3

This document contains an assignment for a data structures and algorithms course. It includes 4 questions: 1) Analyzing a recursive function that calculates the sum from 0 to a given number. 2) Writing a recursive function to generate a pattern of stars of a given number of lines. 3) Sorting a given list using quicksort, using the middle element as the pivot. 4) Sorting another given list using quicksort, using the median of the first, last, and middle elements as the pivot.

Uploaded by

dayij11605
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)
49 views2 pages

DSA-Class-Assignment 3

This document contains an assignment for a data structures and algorithms course. It includes 4 questions: 1) Analyzing a recursive function that calculates the sum from 0 to a given number. 2) Writing a recursive function to generate a pattern of stars of a given number of lines. 3) Sorting a given list using quicksort, using the middle element as the pivot. 4) Sorting another given list using quicksort, using the median of the first, last, and middle elements as the pivot.

Uploaded by

dayij11605
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

The University of Lahore

Department of CS & IT
Data Structure and Algorithms (Theory Class)
Assignment# 3
Instructor Name: Miss Kashmala Pervaiz 15th December, 2023
Course Title: Object Oriented Programming
Course Code:
Deadline: 22nd December, 2023 Total Marks: 10
Student Name: University ID:

1. Consider the following recursive function:


int mystery(int number) //Line 1
{ //Line 2
if (number == 0) //Line 3
return number; //Line 4
else //Line 5
return(number + mystery(number - 1)); //Line 6
} //Line 7
a. Identify the base case.
b. Identify the general case.
c. What valid values can be passed as parameters to the function mystery?
d. If mystery(0) is a valid call, what is its value? If not, explain why.
e. If mystery(5) is a valid call, what is its value? If not, explain why.
f. If mystery(-3) is a valid call, what is its value? If not, explain why.
2. Write a recursive a function to generate the following pattern of stars:
*
* *
* * *
* * * *
* * *
* *
*
Also, write a program that prompts the user to enter the number of lines in the pattern and uses
the recursive function to generate the pattern. For example, specifying 4 as the number of lines
generates the preceding pattern.
3. Assume the following list of keys: 16, 38, 54, 80, 22, 65, 55, 48, 64, 95, 5, 100, 58, 25, 36 This list is
to be sorted using quicksort as discussed in this chapter. Use pivot as the middle element of the
list.
a. Give the resulting list after one call to the partition procedure.
b. Give the resulting list after two calls to the partition procedure.
4. Assume the following list of keys: 18, 40, 16, 82, 64, 67, 57, 50, 37, 47, 72, 14, 17, 27, 35 This list is
to be sorted using quicksort as discussed in this chapter. Use pivot as the median of the first, last,
and middle elements of the list.
a. What is the pivot?
b. Give the resulting list after one call to the partition procedure.

You might also like