1E

The dynamic set S is represented by a direct address table T of length m. To find the maximum element of S, each time get an element T[k] of the direct address table T and compare it with the variable ‘max’ (initially max have very smaller value). If T[k] is greater than the ‘max’, store it in ‘max’. Repeat this until all the elements of the direct-address table are compared with ‘max’. The last value that is left in the ‘max’ is the required maximum value.

A procedure to find the maximum element of S:

MAX-OF-SET (T, m)

// -∞ is a very small value

1. max = -∞

2. for k = 0 to m-1

3. If T[k] ≠ NIL and max < T[k]

4. max = T[k]

5. return max

If the m-1 slot is not empty, then the procedure checks all the m slots of direct address table T for maximum value.

Thus, the worst – case time complexity of the procedure is time.

2E

Consider a bit vector A of length m, which is used to direct access a table. A bit vector is an array contains either 0 or 1 as its elements.

The size of A bit vector depend on the largest element in dynamic set. The bit vector A is used to represent whether ith element is available in dynamic set or not. That is,

With the help of bit vector a table can access directly. Therefore the runtime of dictionary operation is.


Consider following example:

Suppose following elements are present in dynamic set:

Only the above blocks are allocated and rest all blocks are free. The bit vector A corresponding to dynamic set is as follows:

Key

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

bits

1

1

0

1

0

0

1

1

0

1

0

1

1

0

1

3E
(no answer available from chegg)
4E
Chegg Rip, Introduction to Algorithms, 3rd Edition. [RipVer 0.1] (index)