This preview shows page 1. Sign up to view the full content.
5
6.[25] Consider ADT Sets (of numbers) with the following operations: MEMBER(x),
DELETEMIN, INSERT(x), DELETEMAX, and MEDIAN, which is a function
returning the
⌈
(n+1)/2
⌉
th element in set S, where n = S, and
⌈
x
⌉
is the smallest
integer greater than or equal to x, i.e.
⌈
3.1
⌉
= 4,
⌈
4
⌉
= 4.
What model(s) would you recommend and why? Provide big O estimations of the
ADT operations for each implementation.
We can use AVL trees, redblack trees or 23 trees. We do not need to modify the
operations: MEMBER(x), DELETEMIN, and DELETEMAX. We need to add two
variables: MED, which will hold the value of median and EO which will hold 0 if median
is an even element of the set treated as an ordered list, and 1 if median is an odd element
of the set treated as an ordered list. Now each INSERT and DELETE must update the
values of MED and EO.
For INSERT(x) we need to:
(1)
insert x into an (AVL, redblack, 23) tree, according to standard procedure
(2)
update MED . We have to consider 4 cases:
This is the end of the preview. Sign up
to
access the rest of the 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.
 Spring '03
 janicki

Click to edit the document details