2c03-review - 00049

2c03-review - 00049 - L[1] := L[L.last div 2 +1]; end else...

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

View Full Document Right Arrow Icon
5 end The time complexity is O(n). [6] function C1H2H(L1, L2: List;): List; var n : integer; begin L1.last := (L1.last div 2); for (n:=1 to L1.last) do L1.element[n] := L1.element[2*n] L2.last := L2.last – (L2.last div 2); for (n:=1 to L2.last) do L2.element[n] := L2.element[2*n-1]; for (n := L1.last.+1 to L1.last+L2.laste) do L1.element[n] := L2.element[n - L.last]; L1.last := L1.last + L2.last; return(L1); end The time complexity is O(m+n). [6] function MIDDLE(L: List;): List; var L’ : List; begin if ((L.last mod 2) = 0) then begin L’.Last := 2; L’[1] := L[L.last div 2];
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: L[1] := L[L.last div 2 +1]; end else begin L.Last := 1; L[1] := L[L.last div 2+1]; e n d return(L); end The time complexity is O(1), which is faster than abstract pointer implementation 3.[8] Write a procedure to interchange the element at the position 1 with the element at the position 6, the element at the position 3 with the element at the position 8, etc., in general the element at the position number k with the element at the position k+5 in a singly linked list. Analyze the time complexity of your procedure. celltype = record of element: elementtype...
View Full Document

Ask a homework question - tutors are online