2c03-review - 00048

# 2c03-review - 00048 - Ω(n time and each implementation...

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

4 var n : integer; begin p := L; q := p .previous; while ((p<>q) and (p .next <> q)) do begin L := p .next ; p .next .previous := p .previous; p := p .next; L .previous := q .previous; q .previous .next := nil; q := q .previous; end return(L); end For doubly linked list, no need for list header. More pointer manipulation for deletion, however, less time complexity for concatenation. 2.[20] In the question 1, no assumption about list implementation is made. It is often called ‘abstract pointer level implementation’. Redo (1) assuming some array implementation of lists. Design an array implementation which in your opinion guarantees the lowest time worst case complexity. Justify your design. [4] Due to the nature of problems, each implementation of (a) needs
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Ω (n) time and each implementation of (b) needs Ω (n+m) time. The following array implementation would guarantee O(n) for (a), O(n+m) for (b) and O(1) for (c) (O(1) is the best we can get). The elements are stored in contiguous cells of an array element [1: maxlength ], the variable last points to the last element of the list ( element [1] is always the first element). ATD list can now be represented by the following C-like structure List = structure element : array[1:maxlength] of integers last: integer end [4] procedure NO3ONLY(L: List;); var n : integer; begin L.last := L.last – (L.last div 3); for (n:=1; n<(L.last+1)) do begin L.element[n] := L.element[n+((n-1) div 2)] end...
View Full Document

## This note was uploaded on 12/10/2009 for the course CAS 2c03 taught by Professor Janicki during the Spring '03 term at McMaster University.

Ask a homework question - tutors are online