2c03-review - 00098

2c03-review - 00098 - exp(a,b var q ↑ celltype begin if...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
11 var p,q: position; tmp: elementtype; begin if (FIRST(L)=END(L) or NEXT(FIRST(L),L)=END(L) or NEXT(NEXT(FIRST(L),L),L)=END(L)) return; p := NEXT(FIRST(L),L); q := NEXT(p,L); while (q <> END(L)) do begin INSERT(RETRIEVE(q,L), p, L); DELETE(NEXT(p,L),L); q := NEXT(p,L) end end 9.[10] Write the most efficient pseudo-Pascal program to compute f(n) f(n) , where f(n)=n n . Hint. Do you know that n n can be implemented with O(log n) complexity?
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: exp(a,b) var q: ↑ celltype; begin if b=0 then return (1) else if b=1 then return(a) else if b mod 2 = 1 then exp(a,b):=(exp(a,b div 2)) 2 *a else exp(a,b):=(exp(a,b div 2)) 2 end Then, exp(n,n) calculate n n , and the time complexity is O(logn). F(n) begin return(exp(exp(n,n), exp(n,n))) end Then, F(n) calculate f(n) f(n) , and the time complexity is O(nlogn)....
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online