You are on page 1of 3

MC150400452

Total Marks: 20
Assignment No. 01
SEMESTER Spring 2021 Due Date: 19-05-2021
CS502- Fundamentals of Algorithms
Instructions
Please read the following instructions carefully before solving & submitting assignment:
It should be clear that your assignment will not get any credit if:
 The assignment is submitted after due date.
 The submitted assignment does not open or file corrupt.
 The assignment is full or partially copied from (other student or ditto copy from handouts or internet).
 Student ID is not mentioned in the assignment File or name of file is other than student ID.
 The assignment is not submitted in .doc or .docx format.

Uploading instructions
Your submission must include:

 Assignment should be in .doc or .docx format.


 Save your assignment with your ID (e.g. bx180200786.doc).
 Assignment submission through email is NOT acceptable.

Objective
The objective of this assignment is
 To give basic knowledge and understanding of Algorithms.
 To be able to design simple algorithms.
 To be able to understand and calculate the complexity of algorithms.
Note:
Your answer must follow the below given specifications.
 Font style: “Times New Roman”
 Font color: “Black”
 Font size: “12”
 Bold for heading only.
 Font in Italic is not allowed at all.
 No formatting or bullets are allowed to use.
 Your answer should be precise and to the point, avoid irrelevant detail.

Lectures Covered: This assignment covers Lecture # 01 - 08


Deadline
Your assignment must be uploaded/submitted on or before 19-05-2021.
Question No 01: (Marks: 10)
Suppose that one of the largest commercial bank branch in UAE has recently experienced a significant distress due
to covid 19. A huge No. of account holders withdraws the payment from the bank. Now manager want to check
the total number of accounts those have less than 1000$.

You are required perform the following task:


A. Write only Pseudocode to check the total number of accounts, who have less than 1000$ using array list.
Start
Take _Balance and _Accounts as input
Create arraylist();
for MR=1 // to check all account holders one by one
if _Balance<1000$
arraylist(_Accounts)
Show number of total accounts
End.

B. After writing Pseudocode calculate the worst-case time complexity T(n).


T(n)=O(n)

Question No 02: (Marks: 10)


A prime number is a number that can only be divided by itself and 1. Using the following code, we can check
whether the number is prime or not. Your task is to find the time complexity of the following code with respect to
worst case.

int arr[5], j, x , y, z;
for(x=0; x<5; x++)
{
cout<<"Enter the no."<<endl;
cin>>arr[x];
}
for(x=0;x<5;x++)
{
y=0;
for(j=2; j<arr[x];j++)
{
z=arr[x]%j;
if(z==0)
{
y=1;
break;
}
}
if(y==0)
cout<<arr[x]<<endl;
}
}
Answer:
T(n)=O(n2)
=====================================Ended=======================================

For any query about the assignment, contact at CS502@vu.edu.pk

GOOD LUCK

You might also like