Assignment No. 01
Fall 2023
CS502- Fundamentals of Algorithms
Total Marks: 20
Due Date: 13-11-2023
Instructions
Please read the following instructions carefully before solving & submitting assignment:
It should be clear that your assignment will not get any credit (zero marks) if:
The assignment is submitted after due date.
The submitted assignment is other than MS Word file.
The submitted assignment does NOT open or file is corrupted.
The assignment is copied (from other student or ditto copy from handouts or internet).
List data in Question 2 is not your ID’s digits
Uploading instructions
For clarity and simplicity, you are required to upload/submit only one .doc/docx file.
Objectives
The objectives of this assignment are;
To be able to understand and calculate the time complexity of code.
To be able to understand the concept of Algorithm working and pseudo code generation.
For any query about the assignment, contact at [email protected]
Good Luck!
Question No. 1 Marks: 10
An Arithmetic Progression (AP) is a sequence of numbers or variables in which the common difference between consecutive terms is the same. There can be an infinite number of terms in an AP. If a is the first term of AP, d is common differene and n is the nth term, then the AP is as follow:
a, a + d, a + 2d, a + 3d, a + 4d, ………. ,a + (n – 1) d
You are required to design (write) a simple algorithm (Only Pseudo code) to:
1. Generate an AP having n terms
2. Find the nth term of the AP
3. Calculate the sum of the n terms.
Note: You can read about Arithemitc progression on the following link:
https://www.cuemath.com/algebra/nth-t...
Question No. 2 Marks: 10
Find the running time complexity of the following piece of pseudocode and show your working step by step.
for i = 1 to n: // Outermost loop, increments 'i'
for j = 1 to 4 // Middle loop, increments 'j'
for k =10; k 0 ; k -= 2 // Innermost loop, decrements 'k'
print(i , j , k) // Display i, j & k
In the above code:
• The outermost loop increments i from 1 to 5.
• The middle loop, which is inside the outermost loop, increments j from 1 to 3 for each value of i.
• The innermost loop, which is inside both the outermost and middle loops, decrements k from 10 to 2 with a step size of -2 for each combination of i and j.
This results in a set of nested loops where i, j, and k are changing their values, with i incrementing, j incrementing, and k decrementing, and the code prints the values of these variables at each step.
Lectures Covered: Lecture No. 01 to 8.
Deadline: Your assignment must be uploaded / submitted on or before Novermber 13, 2023
Total Marks: 20