preview

Nt1330 Unit 1 Assignment

Decent Essays

In the case of T(n) = n, say O(n), and n is 1000, then on the old computer 1 minute and the new one, 1/1000 minute
For T (n) =n3, the size will be 1000^3 = 1000,000,000 which takes 1000,000 minutes on the old computer and 1000 on the new one
For T(n)=10n Because of the limited space, I won�t write
1000 ZEROs here, instead it�s clear that it takes 10^997 minutes on the old computer, and 10^994 minutes on the new one.
CIS 360- Algorithms and Data Structures- Homework 1
Submitted by Arsalan Hafiz (01498800)
DATE: 9/15/2014
1. Write an algorithm that finds the m smallest numbers in a list of n numbers.
(Chapter 1, Exercise 2)

Solution:

FOR EACH i in A[i]

j = i + 1

FOR EACH j in A[j]

IF A[i] < A[j] THEN temp = A[i]
A[i] = A[j] …show more content…

Algorithm 2:
• Definition of Basic Operation:
We are using two FOR Loop to traverse the input and create a 2 dimensional array for printing the output.
• Every-Case Time Complexity: Yes this algorithm does have an every case time complexity, it is // *n for each for loop T (n) = n + n = 2n = n (ignoring the constant)

4. Compare algorithms. Chapter 1, Exercise 14, page 44.
Algorithm 1:
• To run the algorithm once The fixed cost would be: 4 hours * $20/hour = $80
• The cost of running the program (CPU Cost): n2 microsecond = (500)2 microsecond = 250,000 microsecond = 250 second We need to change seconds in to minutes to get runtime cost in min/hour ((250seconds * 1min) / (60seconds)) * $50/min = $208
• Run the algorithm n times Q₁ (n) = 80 + (250/60) * 50n

Algorithm 2:
• To run the algorithm once Fixed cost: 15 hours * $20/hour = $300
• The Cost of CPU Runtime: 100n (logn) = 100 * 500 * (log500) = 134948 microseconds = 135 seconds We need to change seconds into minutes to get runtime cost in min/hour ((135 seconds*1min) / (60 seconds)) * $50/min = $112.5
• Run the algorithm n times Q₂ (n) = 300 + (135/ 60) * 50x Q₁ (n) = Q₂ (n) 80 + 208n = 300 + …show more content…

5. Group the functions by complexity category. Find the complexity category for each function and sort the categories by increasing growth rate.
Solution:
Complexity category for functions and Sorting the categories by increasing growth rate from Low to High:
• O((Log n)2)
• O(n) , O (n)
• O(n log (n))
• O( √n

Get Access