Assignment No. 01

Semester: Spring 2016

CS502: Fundamentals of Algorithms

Total Marks: 20

Due Date:19/05/2016

Instructions

Please read the following instructions carefully before submitting assignment:

It should be clear that your assignment will not get any credit (zero marks) if:

o The assignment is submitted after due date.

o The submitted assignment is other than .doc file.

o The submitted assignment does NOT open or file is corrupted.

o The assignment is copied (from other student or ditto copy from any other source).

Objective

The objective of this assignment is to:

Learn and practice Algorithm running time analysis

Solve recurrences using iteration method

Submission

You are required to submit your solution through LMS as MS Word document.

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

GOOD LUCK

Question 1:

Analyze the running time complexity of the following piece of code. Show your working step by step.

SumOddEven(A,n) //A is array and n is size of array

{

int count, sum;

for(int i = 1; i<=n; i++) { sum_even=0; sum_odd=0; for(int j = i; j<=n; j++) { if (A[j] Mod 2 == 0) //check if number is even sum_even=sum_even+A[j] //Sum even numbers else sum_odd=sum_odd+A[j] //Sum odd numbers } cout/p>