OrderedListADT. Overview OrderedListADT: not the same as linked lists The OrderedListADT: operations and sample applications An ArrayList implementation.

Slides:



Advertisements
Similar presentations
1 Lists A List ADT Types of Lists Lists in Java Collections API Using ordered lists – Tournament Maker Using indexed lists – Josephus Problem Implementing.
Advertisements

Data Structures.
Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
Chapter 6 Linked Structures © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
1 Lists A List ADT Types of Lists Lists in Java Collections API Using ordered lists – Tournament Maker Using indexed lists – Josephus Problem Implementing.
Searching and Sorting. Overview Search Analysis of search algorithms Sorting Analysis of sort algorithms Recursion p. 2 of 26.
Priority Queues and Heaps. Overview Our last ADT: PriorityQueueADT A new data structure: heaps One more sorting algorithm: heapsort Priority Queues and.
DictionaryADT and Trees. Overview What is the DictionaryADT? What are trees? Implementing DictionaryADT with binary trees Balanced trees DictionaryADT.
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
CSC 212 Vectors, Lists, & Sequences. Announcement Daily quizzes accepted electronically only  Submit via one or other Dropbox  also accepted,
Linked structures. Overview Overview of linked structures (for lists) Design decision: arrays vs. linked lists Implementing the StackADT with linked lists.
CS102 – Data Structures Lists, Stacks, Queues, Trees, Hash Collections Framework David Davenport Spring 2002.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Stacks. 2 Outline and Reading The Stack ADT (§2.1.1) Array-based implementation (§2.1.1) Growable array-based stack (§1.5) Java.util.Stack class Java.util.Vector.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
Stack Implementations Chapter 22 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 13: Queues and Vectors.
Queues. From last time: Java's built-in java.util.Stack class Consider the javadoc for Java’s built-in java.util.Stack class (
Sorted Lists and Their Implementations Chapter 12 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 20 Lists, Stacks, Queues, and Priority.
Chapter 19 Java Data Structures
Chapter 6.6, (event-driven simulation) Queues 1CSCI 3333 Data Structures.
EXPANDING STACKS AND QUEUES CS16: Introduction to Data Structures & Algorithms 1 Tuesday, February 10, 2015.
Chapter 4 Linked Structures – Stacks Modified. Chapter Scope Object references as links Linked vs. array-based structures Managing linked lists Linked.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
© 2006 Pearson Education Chapter 12: Data Structures Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis,
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Problem of the Day  What do you get when you cross a mountain climber and a grape?
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
Computer Science 209 Software Development Java Collections.
30 May Stacks (5.1) CSE 2011 Winter Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An.
Data structures Abstract data types Java classes for Data structures and ADTs.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
Queues Chapter 6. Chapter 6: Queues Chapter Objectives To learn how to represent a waiting line (queue) and how to use the five methods in the Queue interface:
15440 Distributed Systems Recitation 1 Objected-Oriented Java Programming.
Clicker questions and stuff 12/5/13 CSE 1102 Fall 2013.
LECTURE 24: STACK ADTS CSC 212 – Data Structures.
CH 6. VECTORS, LISTS, AND SEQUENCES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH,
1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
Chapter 5 Array-Based Structures © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Stack Implementations Chapter 6 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
1 Stacks (Continued) and Queues Array Stack Implementation Linked Stack Implementation The java.util.Stack class Queue Abstract Data Type (ADT) Queue ADT.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Chapter 5 Array-Based Structures © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Iterators (short version) Chapter 15 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Topic 13 Iterators. 9-2 Motivation We often want to access every item in a data structure or collection in turn We call this traversing or iterating over.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 18 List ADT Animated Version.
“The desire for safety stands against every great and noble enterprise.” – Tacitus Thought for the Day.
Click to edit Master text styles Stacks Data Structure.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
9/27/2016IT 1791 Abstraction A tool (concept) to manage complexity Hide irrelevant details; focus on the features needed Primitive date types are already.
Linked Structures - Stacks. Linked Structures An alternative to array-based implementations are linked structures A linked structure uses object references.
Prefix notation in action
Iterators.
Lists A List ADT Types of Lists Using ordered lists – Tournament Maker
CS Data Structures Chapter 8 Lists Mehmet H Gunes
Abstraction A tool (concept) to manage complexity
structures and their relationships." - Linus Torvalds
CSC 143 Queues [Chapter 7].
List Implementations Chapter 9.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
structures and their relationships." - Linus Torvalds
Presentation transcript:

OrderedListADT

Overview OrderedListADT: not the same as linked lists The OrderedListADT: operations and sample applications An ArrayList implementation and its time complexity A LinkedList implementation and its time complexity Java’s built-in implementations of OrderedListADT OrderedListADT p. 2/21

Our third ADT: OrderedListADT Consider the following operations: add(T element) // in a way that keeps the list ordered remove (T element) // wherever it is contains (T element) isEmpty() size() toString() How are these different from stacks and queues? OrderedListADT p. 3/21

What is the OrderedListADT useful for? An example of something that could be built better using an OrderedListADT than with a stack or a queue is a structure that models: A. The undo operation in Word B. The Back button in a web browser C. the customers waiting to pay at Donovan D. a to-do list E. the computers at RIC and the network that connects them OrderedListADT p. 4/21

More applications of OrderedListADT Name five additional everyday examples of an ordered list other than those discussed in the text. OrderedListADT p. 5/21

The OrderedListADT operations The add operation is best described as which of the following: A. adds an item to the OrderedListat the front B. adds an item to the OrderedList in its place C. adds an item to the OrderedList at a random location D. adds an item to the OrderedList at the end E. none of the above OrderedListADT p. 6/21

The OrderedListADT operations (2) The remove operation is best described as which of the following: A. removes the item at the front of the List B. removes a specified item C. removes a randomly chosen item D. removes the item at the end of the list E. none of the above OrderedListADT p. 7/21

OrderedListADT vs. StackADT and QueueADT Compare and contrast the operations provided by an OrderedListADT with those provided by the StackADT and the QueueADT. What’s basically the same? What’s different? OrderedListADT p. 8/21

The OrderedListADT interface Consider the code for the ListADT interface on page 141 of your text. Why does the interface extend Iterable ? What is the effect of putting extends Iterable in the header of the interface? Rewrite the interface to create our OrderedListADT. OrderedListADT p. 9/21

Implementing OrderedListADT with arrays If we use an array to implement, the following, when (if ever) do we need to copy data? StackADT QueueADT OrderedListADT Explain with examples and diagrams. OrderedListADT p. 10/21

Understanding the array-based implementation: remove Consider the code for the remove operation for an array- based implementation (p. 155). Suppose we have a list with four elements with ID numbers 1, 3, 5, and 7, and remove is called to delete element number 5. Explain in complete sentences what happens when the code is executed, with diagrams of the array. What is the time complexity of the remove operation and why? OrderedListADT p. 11/21

Understanding the array-based implementation: contains Consider the code for the contains operation for an array-based implementation (p. 157). Suppose we have a list with four elements with ID numbers 1, 3, 5, and 7, and contains is called to determine if the list contains an element with ID number 10. Explain in complete sentences what happens when the code is executed, with diagrams of the array. What is the time complexity of the contains operation and why? OrderedListADT p. 12/21

Understanding the array- based implementation: add Consider the code for the add operation for an array- based implementation (p. 161). Suppose we have a sorted list with four elements with ID numbers 1, 3, 5, and 7, and add is called to add a new element with ID number 2. Explain in complete sentences what happens when the code is executed, with diagrams of the array. What is the time complexity of the add operation and why? OrderedListADT p. 13/21

Iterators What is an iterator? Consider the ArrayIterator code (p. 159). Suppose you used it in writing a toString method. Line by line, how would it work: A. for a queue B. for a stack C. for a list What do you think of this class? OrderedListADTs p. 14/21

Implementing OrderedListADT with linked lists If we use a linked list to implement OrderedListADT, implementing add and remove is a little more complicated than it is for a stack or a queue. Explain why, in complete English sentences (add diagrams if you like). OrderedListADT p. 15/21

Understanding the link-based implementation: remove Consider the code for the remove operation for a link- based implementation (p. 164). Suppose we have a list with four elements with ID numbers 1, 3, 5, and 7, and remove is called to delete element number 5. Explain in complete sentences what happens when the code is executed, with box and arrow diagrams of the linked list. What is the time complexity of this remove operation and why? OrderedListADTs p. 16/21

Understanding the link-based implementation: contains and add Based on the code for remove, write a link-based version of contains. Based on the code for remove, write a link-based version of add. What is the time complexity of each of your methods? Explain. OrderedListADTs p. 17/21

Understanding the link-based implementation: remove Compare the two link-based versions of remove in the text (pp. 164 and 168). What is the difference in how they handle the example discussed earlier: Suppose we have a list with four elements with ID numbers 1, 3, 5, and 7, and contains is called to determine if the list contains an element with ID number 10. Explain in complete sentences what happens when the code is executed, with diagrams of the array. What is the time complexity of the two link-based versions of remove and why? OrderedListADTs p. 18/21

Java’s Built-In Lists Consider Java’s three implementations of lists: Vector, ArrayList, and LinkedList. Do we need two add and two addAll methods? If not, which is (are) the most basic, and how could you use those to write the others? Suppose you want to implement our QueueADT. What are the disadvantages of defining a class that inherits from Vector or ArrayList ? Explain how you could use containment instead of inheritance to write an implementation of QueueADT using a Java ArrayList. OrderedListADTs p. 19/21

Coming attractions Next time we’ll review recursion, in preparation for looking at a new Abstract Datatype that uses it extensively. Homework: read Chapter 7 (or the equivalent in the earlier edition). OrderedListADTs p. 20/21