Fundamentals of Algorithms (CS502)

Assignment # 01

Spring 2018

                                                                                                                          Total marks = 20

                                                                                                                           Deadline = 10/05/18

 Lectures Covered: This assignment covers Lecture # 1 to 7.

Objectives:

Objectives of this assignment are:

  • To understand line by line analysis of an algorithm
  • To understand how to calculate running time of an algorithm
  • To perform comparison of different algorithms

 

Instructions:

Please read the following instructions carefully before solving & submitting the assignment:

  1. The assignment will not be accepted after due date.
  2. Zero marks will be awarded if the assignment does not open or the file is corrupt.
  3. The assignment file must be an MS Word (.doc/.docx) file format; Assignment will not be accepted in any other format.
  4. Zero marks will be awarded if assignment is copied (from other student or copied from handouts or internet).
  5. Zero marks will be awarded if Student ID is not mentioned in the assignment file.

 

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

Please do not post queries related to assignment on MDB.


 

 

Question # 1:                                                                              10   Marks

 

For the following code segment, provide line-by-line analysis and construct function T(n) that give the runtime of this code as a function of "n".  Also determine the big-O for this code segment.                 [Marks: 5+3+2]

 

 

Code segment                                                  Cost

 

i = 1                                                   

j = 1                                                    

k = 1                                                                   

while (i <= n)                                       

          i = i + 1                                       

          while (j < n)                             

                  a = 2 + g                            

                  j = j + 1                               

if (k <= n)                                            

          a = 2                                                   

else

          a = 3                                                              

 

 

Question # 2:                                                                         5   Marks

Which of the following two functions is faster? 

  1. f1 = 10n2
  2. f2 = n3

 

 

 

 

Question # 3:                                                                                  5   Marks

 

In the context of 2D Maxima problem, Brute Force algorithm runs in Θ(n2) time and Plane-Sweep algorithm runs in Θ(nlog2n) time. For n = 500,000, if Plane-Sweep takes 1 second, how much time (in hours) Brute Force algorithm will take? Calculate and show all the steps.

Note: Base of log is 2 (e.g. log210 = 3.321928095)

 

 

 

 

 

 

Good Luck

Views: 465

Replies are closed for this discussion.

Replies to This Discussion

Ideal Solution...!!!

Attachments:

RSS

Discussion Forum

CS502 Finalterm Papers from Sep 1st to 13th, 2018

Started by + caмe4ѕтυdιeѕ.
Last reply
by + caмe4ѕтυdιeѕ Sep 4. 1 Reply

cs502 gdb

Started by +s@m@n j@nn@t+ Aug 6. 0 Replies

CS502 GDB Last Date: 7th Aug, 2018

Started by + caмe4ѕтυdιeѕ.
Last reply
by +s@m@n j@nn@t+ Aug 6. 1 Reply

CS502 Assign # 3 Due Date: 27th July, 2018

Started by + caмe4ѕтυdιeѕ.
Last reply
by Cute S@mra Jul 22. 2 Replies

cs502 assignment no 2 2018

Started by Muhammad Hasan.
Last reply
by +.ïɳnόϲϵᴎԎ ɖόІІ.+ May 30. 1 Reply

SPONSORED LINKS

© 2018   Created by Muhammad Anwar Tahseen.   Powered by

Badges  |  Report an Issue  |  Terms of Service