1 / 18

Sorted Lists

Sorted Lists. Chapter 13. Slides by Steve Armstrong LeTourneau University Longview, TX ã 2007, Prentice Hall. Chapter Contents. Specifications for the ADT Sorted List Using the ADT Sorted List A Linked Implementation The Method add The Efficiency of the Linked Implementation

ailis
Download Presentation

Sorted Lists

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sorted Lists Chapter 13 Slides by Steve ArmstrongLeTourneau UniversityLongview, TX ã 2007,Prentice Hall

  2. Chapter Contents • Specifications for the ADT Sorted List • Using the ADT Sorted List • A Linked Implementation • The Method add • The Efficiency of the Linked Implementation • An Implementation that Uses the ADT List • Efficiency Issues Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-237045-X

  3. Specifications for the ADT Sorted List 2 • Data • A collection of objects in sorted order, same data type • The number of objects in the collection • Operations • Add a new entry * • Remove an entry * • Getposition of the entry * • Check if a certain value is contained in the list • Clear the list • Return the length of the list • Check if list is empty or full • Display the list Note: a sorted list will not let you add or replace an entry by position Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-237045-X

  4. Specifications for the ADT Sorted List • View SortedListInterface • Note methods • add • remove • getPosition • Other methods from Segment 4.10 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-237045-X

  5. A Linked Implementation 7 • View linked implementation of ADT sorted list • Note • addmethod • If list is in ascending order, insert new entry just before first entry not smaller than new entry • Private getNodeBefore • Need two nodes – node before and node after where new node goes Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-237045-X

  6. The Method add Fig. 13-1 Insertion points of names into a sorted chain of linked nodes. Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-237045-X

  7. The Method add 12 Fig. 13-2 Recursively adding Luke to a sorted chain of names Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-237045-X

  8. The Method add 13 Fig. 13-3 Recursively adding a node at the beginning of the chain … continued → Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-237045-X

  9. The Method add Fig. 13-3 (ctd) Recursively adding a node at the beginning of the chain. Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-237045-X

  10. The Method add 15 Fig. 13-4 Recursively adding a node between existing nodes in a chain … continued → Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-237045-X

  11. The Method add Fig. 13-4 (ctd) Recursively adding a node between existing nodes in a chain. Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-237045-X

  12. Efficiency of the Linked Implementation 18 Fig. 13-5 The worst-case efficiencies of the operations on the ADT sorted list for two implementations Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-237045-X

  13. An Implementation That Uses the ADT List 19 • View class SortedList • Note • Use of generic type T • Implements interface SortedListInterface • Assume class LList from chapter 6 & 7 is implementation of interface ListInterface Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-237045-X

  14. An Implementation That Uses the ADT List Fig. 13-6 An instance of a sorted list that contains a list of its entries. Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-237045-X

  15. An Implementation That Uses the ADT List Fig. 13-7 A sorted list in which Jamie belongs after Carlos but before Sarah. Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-237045-X

  16. Efficiency Issues 26 Fig. 13-8 The worst-case efficiencies of selected ADT list operations for array-based and linked implementations Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-237045-X

  17. Efficiency Issues Fig. 13-9 The worst-case efficiencies of the ADT sorted list operations when implemented using an instance of the ADT LIST Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-237045-X

  18. Efficiency Issues • When you use an instance of an ADT list to represent entries in ADT sorted list • Must use the list's operations to access sorted lists entries • Do not access them directly • Direct access leads to inefficient implementation of sorted list • Underlying list uses a chain of linked nodes to store entries Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-237045-X

More Related