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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4Lists, Stacks, <strong>and</strong> QueuesIf your program needs to store a few things — numbers, payroll records, or job descriptionsfor example — the simplest <strong>and</strong> most effective approach might be to putthem in a list. Only when you have to organize <strong>and</strong> search through a large numberof things do more sophistic<strong>at</strong>ed d<strong>at</strong>a structures usually become necessary. (We willstudy how to organize <strong>and</strong> search through medium amounts of d<strong>at</strong>a in Chapters 5, 7,<strong>and</strong> 9, <strong>and</strong> discuss how to deal with large amounts of d<strong>at</strong>a in Chapters 8–10.) Manyapplic<strong>at</strong>ions don’t require any form of search, <strong>and</strong> they do not require th<strong>at</strong> any orderingbe placed on the objects being stored. Some applic<strong>at</strong>ions require processingin a strict chronological order, processing objects in the order th<strong>at</strong> they arrived, orperhaps processing objects in the reverse of the order th<strong>at</strong> they arrived. For all thesesitu<strong>at</strong>ions, a simple list structure is appropri<strong>at</strong>e.This chapter describes represent<strong>at</strong>ions for lists in general, as well as two importantlist-like structures called the stack <strong>and</strong> the queue. Along with presenting thesefundamental d<strong>at</strong>a structures, the other goals of the chapter are to: (1) Give examplesof separ<strong>at</strong>ing a logical represent<strong>at</strong>ion in the form of an ADT from a physical implement<strong>at</strong>ionfor a d<strong>at</strong>a structure. (2) Illustr<strong>at</strong>e the use of asymptotic analysis in thecontext of some simple oper<strong>at</strong>ions th<strong>at</strong> you might already be familiar with. In thisway you can begin to see how asymptotic analysis works, without the complic<strong>at</strong>ionsth<strong>at</strong> arise when analyzing more sophistic<strong>at</strong>ed algorithms <strong>and</strong> d<strong>at</strong>a structures.(3) Introduce the concept <strong>and</strong> use of dictionaries.We begin by defining an ADT for lists in Section 4.1. Two implement<strong>at</strong>ions forthe list ADT — the array-based list <strong>and</strong> the linked list — are covered in detail <strong>and</strong>their rel<strong>at</strong>ive merits discussed. Sections 4.2 <strong>and</strong> 4.3 cover stacks <strong>and</strong> queues, respectively.Sample implement<strong>at</strong>ions for each of these d<strong>at</strong>a structures are presented.Section 4.4 presents the Dictionary ADT for storing <strong>and</strong> retrieving d<strong>at</strong>a, which setsa context for implementing search structures such as the Binary Search Tree ofSection 5.4.93

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

Saved successfully!

Ooh no, something went wrong!