12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

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 <strong>to</strong> s<strong>to</strong>re a few things — numbers, payroll records, or jobdescriptions for example — the simplest <strong>and</strong> most effective approach might be <strong>to</strong>put them in a list. Only when you have <strong>to</strong> organize or search through a large numberof things do more sophisticated data structures usually become necessary. (We willstudy how <strong>to</strong> organize <strong>and</strong> search through medium amounts of data in Chapters 5,7, <strong>and</strong> 9, <strong>and</strong> discuss how <strong>to</strong> deal with large amounts of data in Chapters 8–10.)Many applications don’t require any form of search, <strong>and</strong> they do not require thatany ordering be placed on the objects being s<strong>to</strong>red. Some applications requireprocessing in a strict chronological order, perhaps processing objects in the orderthat they arrived, or perhaps processing objects in the reverse of the order that theyarrived. For all these situations, a simple list structure is appropriate.This chapter describes representations for lists in general, as well as two importantlist-like structures called the stack <strong>and</strong> the queue. Along with presenting thesefundamental data structures, the other goals of the chapter are <strong>to</strong>: (1) Give examplesof separating a logical representation in the form of an ADT from a physical implementationfor a data structure. (2) Illustrate the use of asymp<strong>to</strong>tic analysis in thecontext of some simple operations that you might already be familiar with. In thisway you can begin <strong>to</strong> see how asymp<strong>to</strong>tic analysis works, without the complicationsthat arise when analyzing more sophisticated algorithms <strong>and</strong> data structures.(3) Introduce the concept <strong>and</strong> use of dictionaries.We begin by defining an ADT for lists in Section 4.1. Two implementations forthe list ADT — the array-based list <strong>and</strong> the linked list — are covered in detail <strong>and</strong>their relative merits discussed. Sections 4.2 <strong>and</strong> 4.3 cover stacks <strong>and</strong> queues, respectively.Sample implementations for each of these data structures are presented.Section 4.4 presents the Dictionary ADT for s<strong>to</strong>ring <strong>and</strong> retrieving data, which setsa context for implementing search structures such as the Binary Search Tree ofSection 5.4.99

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

Saved successfully!

Ooh no, something went wrong!