Chapter 12: Data Structures

Slides:



Advertisements
Similar presentations
Chapter 9: Data Structures I
Advertisements

Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 18: Stacks And Queues.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
CISH 4960 Introduction to Programming Lecture 101 Introduction to Programming Lecture 10 Recursion/Data Structures Tom Blough
Chapter 12: Data Structures
Unit 11 1 Unit 11: Data Structures H We explore some simple techniques for organizing and managing information H This unit focuses on: Abstract Data Types.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ETC - 1 What comes next? Recursion (Chapter 15) Recursive Data Structures.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Chapter 12 Collections. © 2004 Pearson Addison-Wesley. All rights reserved12-2 Collections A collection is an object that helps us organize and manage.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Odds and Ends Strings (from Chapter 9) StringTokenizer.
Stacks, Queues, and Deques
Stacks, Queues, and Deques. A stack is a last in, first out (LIFO) data structure –Items are removed from a stack in the reverse order from the way they.
Stacks, Queues, and Deques
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
Chapter 4 Linked Structures – Stacks Modified. Chapter Scope Object references as links Linked vs. array-based structures Managing linked lists Linked.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Chapter 3 Introduction to Collections – Stacks Modified
© 2006 Pearson Education Chapter 12: Data Structures Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis,
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 18 Stacks and Queues.
HIT2037- HIT6037 Software Development in Java 22 – Data Structures and Introduction.
Chapter 12 Collections. © 2004 Pearson Addison-Wesley. All rights reserved12-2 Collections A collection is an object that helps us organize and manage.
ELC 310 Day 24. © 2004 Pearson Addison-Wesley. All rights reserved12-2 Agenda Questions? Problem set 5 Parts A & B Corrected  Good results  2 A’s, 1.
COP INTERMEDIATE JAVA Data Structures. A data structure is a way of organizing a collection of data so that it can be manipulated effectively. A.
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
Stacks And Queues Chapter 18.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Stacks and Queues CMSC 201. Stacks and Queues Sometimes, when we use a data-structure in a very specific way, we have a special name for it. This is to.
Lecture 10 b Stacks b Queues. 2 Stacks b A stack ADT is linear b Items are added and removed from only one end of a stack b It is therefore LIFO: Last-In,
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 18: Stacks and Queues.
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.
Linked Structures - Stacks. Linked Structures An alternative to array-based implementations are linked structures A linked structure uses object references.
Collections (Stack, queue, tree, graph). References as Links References can be used to create a variety of linked structures, such as a linked list.
Java Software Solutions Foundations of Program Design Seventh Edition
Chapter 5: Enhancing Classes
Stack: a Linked Implementation
Queues Chapter 8 (continued)
Review Array Array Elements Accessing array elements
Chapter 4 Linked Structures.
18 Chapter Stacks and Queues
Chapter 18: Stacks and Queues.
12 Collections Software Solutions Lewis & Loftus java 5TH EDITION
G64ADS Advanced Data Structures
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Marcus Biel, Software Craftsman
Stacks and Queues.
Chapter 4: Writing Classes
Data Structures and Database Applications Linked Lists
Data Structures and Database Applications Abstract Data Types
Chapter 12 Collections.
CMSC 341 Lecture 5 Stacks, Queues
structures and their relationships." - Linus Torvalds
Stacks, Queues, and Deques
Chapter 19: Stacks and Queues.
structures and their relationships." - Linus Torvalds
Chapter 13 Collections.
Stacks, Queues, and Deques
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
Chapter 12 Collections.
Chapter 6: Arrays and Vectors
Queues cont. Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
Stacks, Queues, and Deques
structures and their relationships." - Linus Torvalds
Data Structures & Programming
Presentation transcript:

Chapter 12: Data Structures Presentation slides for Java Software Solutions Foundations of Program Design Second Edition by John Lewis and William Loftus Java Software Solutions is published by Addison-Wesley Presentation slides are copyright 2000 by John Lewis and William Loftus. All rights reserved. Instructors using the textbook may use and modify these slides for pedagogical purposes.

Data Structures We can now explore some advanced techniques for organizing and managing information Chapter 12 focuses on: dynamic structures Abstract Data Types (ADTs) linked lists queues stacks

Static vs. Dynamic Structures A static data structure has a fixed size This meaning is different than those associated with the static modifier Arrays are static; once you define the number of elements it can hold, it doesn’t change A dynamic data structure grows and shrinks as required by the information it contains

Object References Recall that an object reference is a variable that stores the address of an object A reference can also be called a pointer They are often depicted graphically: student John Smith 40725 3.57

References as Links Object references can be used to create links between objects Suppose a Student class contained a reference to another Student object John Smith 40725 3.57 Jane Jones 58821 3.72

References as Links References can be used to create a variety of linked structures, such as a linked list: studentList

Abstract Data Types An abstract data type (ADT) is an organized collection of information and a set of operations used to manage that information The set of operations define the interface to the ADT As long as the ADT accurately fulfills the promises of the interface, it doesn't really matter how the ADT is implemented Objects are a perfect programming mechanism to create ADTs because their internal details are encapsulated

Abstraction Our data structures should be abstractions That is, they should hide details as appropriate We want to separate the interface of the structure from its underlying implementation This helps manage complexity and makes the structures more useful

Intermediate Nodes The objects being stored should not have to deal with the details of the data structure in which they may be stored For example, the Student class stored a link to the next Student object in the list Instead, we can use a separate node class that holds a reference to the stored object and a link to the next node in the list Therefore the internal representation actually becomes a linked list of nodes

Book Collection Let’s explore an example of a collection of Book objects The collection is managed by the BookList class, which has an private inner class called BookNode Because the BookNode is private to BookList, the BookList methods can directly access BookNode data without violating encapsulation See Library.java (page 500) See BookList.java (page 501) See Book.java (page 503)

Other Dynamic List Implementations It may be convenient to implement as list as a doubly linked list, with next and previous references: list

Other Dynamic List Implementations It may also be convenient to use a separate header node, with references to both the front and rear of the list count: 4 front rear list

Queues A queue is similar to a list but adds items only to the end of the list and removes them from the front It is called a FIFO data structure: First-In, First-Out Analogy: a line of people at a bank teller’s window enqueue dequeue

Queues We can define the operations on a queue as follows: enqueue - add an item to the rear of the queue dequeue - remove an item from the front of the queue empty - returns true if the queue is empty As with our linked list example, by storing generic Object references, any object can be stored in the queue Queues are often helpful in simulations and any processing in which items get “backed up”

Stacks A stack ADT is also linear, like a list or queue Items are added and removed from only one end of a stack It is therefore LIFO: Last-In, First-Out Analogy: a stack of plates

Stacks Stacks are often drawn vertically: pop push

Stacks Some stack operations: push - add an item to the top of the stack pop - remove an item from the top of the stack peek - retrieves the top item without removing it empty - returns true if the stack is empty The java.util package contains a Stack class, which is implemented using a Vector See Decode.java (page 508)

Collection Classes The Java 2 platform contains a Collections API This group of classes represent various data structures used to store and manage objects Their underlying implementation is implied in the class names, such as ArrayList and LinkedList Several interfaces are used to define operations on the collections, such as List, Set, SortedSet, Map, and SortedMap