11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

12Lists <strong>and</strong> Arrays RevisitedSimple lists <strong>and</strong> arrays are the right tools for the many applic<strong>at</strong>ions. Other situ<strong>at</strong>ionsrequire support for oper<strong>at</strong>ions th<strong>at</strong> cannot be implemented efficiently by thest<strong>and</strong>ard list represent<strong>at</strong>ions of Chapter 4. This chapter presents a range of topics,whose unifying thread is th<strong>at</strong> the d<strong>at</strong>a structures included are all list- or array-like.These structures overcome some of the problems of simple linked list <strong>and</strong> contiguousarray represent<strong>at</strong>ions. This chapter also seeks to reinforce the concept oflogical represent<strong>at</strong>ion versus physical implement<strong>at</strong>ion, as some of the “list” implement<strong>at</strong>ionshave quite different organiz<strong>at</strong>ions internally.Section 12.1 describes a series of represent<strong>at</strong>ions for multilists, which are liststh<strong>at</strong> may contain sublists. Section 12.2 discusses represent<strong>at</strong>ions for implementingsparse m<strong>at</strong>rices, large m<strong>at</strong>rices where most of the elements have zero values. Section12.3 discusses memory management techniques, which are essentially a wayof alloc<strong>at</strong>ing variable-length sections from a large array.12.1 MultilistsRecall from Chapter 4 th<strong>at</strong> a list is a finite, ordered sequence of items of the form〈x 0 , x 1 , ..., x n−1 〉 where n ≥ 0. We can represent the empty list by null or 〈〉.In Chapter 4 we assumed th<strong>at</strong> all list elements had the same d<strong>at</strong>a type. In thissection, we extend the definition of lists to allow elements to be arbitrary in n<strong>at</strong>ure.In general, list elements are one of two types.1. An <strong>at</strong>om, which is a d<strong>at</strong>a record of some type such as a number, symbol, orstring.2. Another list, which is called a sublist.A list containing sublists will be written as〈x1, 〈y1, 〈a1, a2〉, y3〉, 〈z1, z2〉, x4〉.405

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!