Assignment Answers
Assignment Answers
(1)Given f(x)= a0+a1 x+a2 x2+…+an xn , where ao, a1, a2, … an and x are given
positive integers. Let k be a given positive integer. Design an algorithm to calculate the value
of f(k) .Use linked list data structure to compute the value of f(k ). Analyse the time
complexity of your algorithm.
(2)Let f (n)=1+3+5+7 …+(2 n−3)+(2 n−1). Is it true that f (n)=O(n 4 )? Justify your
answer.
(3)Analyse the time complexity of the following algorithm
MMM ( int A[ ], int B[ ])
For i 1 to n
For j 1 to n
B[i]= A[i] * A[j]
End for
End for
End MMM
Design two algorithms (iterative and recursive) to print the following picture printing. Analyse the time
complexities of your algorithms.
A
BC
CDEF
DEFGHIJK
EFGHIJKLMNOPQRST