Let L be a doubly linked list of length n stored in arrays key, prev, and next

Question:

Let L be a doubly linked list of length n stored in arrays key, prev, and next of length m. Suppose that these arrays are managed by ALLOCATE-OBJECT and FREE-OBJECT procedures that keep a doubly linked free list F. Suppose further that of the m items, exactly n are on list L and m - n are on the free list. Write a procedure COMPACTIFY-LIST (L,F) that, given the list L and the free list F, moves the items in L so that they occupy array positions 1, 2, . . . ,n and adjusts the free list F so that it remains correct, occupying array positions n + 1, n + 2, . . . ,m. The running time of your procedure should be Θ(n), and it should use only a constant amount of extra space. Argue that your procedure is correct.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  answer-question

Introduction to Algorithms

ISBN: 978-0262033848

3rd edition

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

Question Posted: