So what's next? Introduction to data structures Two Perspectives: Abstract description (capabilities) Implementation(s) For structures: Stack Queue Deque.

Slides:



Advertisements
Similar presentations
STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Advertisements

Queues and Linked Lists
Chapter 24 Lists, Stacks, and Queues
Stack & Queues COP 3502.
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
0 of 37 Stacks and Queues Lecture of 37 Abstract Data Types To use a method, need to know its essentials: signature and return type o additionally,
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.
CHAPTER 7 Queues.
1 Queues (5.2) CSE 2011 Winter May Announcements York Programming Contest Link also available from.
Chapter 5 Queues Modified. Chapter Scope Queue processing Comparing queue implementations 5 - 2Java Software Structures, 4th Edition, Lewis/Chase.
CS Data Structures II Review COSC 2006 April 14, 2017
Linked structures. Overview Overview of linked structures (for lists) Design decision: arrays vs. linked lists Implementing the StackADT with linked lists.
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.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
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 6 Stacks. 2 A stack is a linear collection whose elements are added and removed from one end The last element to be put on the stack is the first.
CS 106 Introduction to Computer Science I 12 / 13 / 2006 Instructor: Michael Eckmann.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Chapter 4 Linked Structures – Stacks Modified. Chapter Scope Object references as links Linked vs. array-based structures Managing linked lists Linked.
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
13 X 11 Java Lecture 6 CS 1311X Self-Referential Structures Building a Queue 13 X 11.
Topic 3 The Stack ADT.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Chapter 3 Introduction to Collections – Stacks Modified
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
Dr. Salah Hammami KSU-CCIS-CS Ahmad Al-Rjoub CSC 113 King Saud University College of Computer and Information Sciences Department of Computer Science Chapter.
Clicker questions 11/21/13 CSE 1102 Fall neighbors, (i,j) = (2,2) [0][0] [i][j]
© 2004 Goodrich, Tamassia Stacks. © 2004 Goodrich, Tamassia Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data.
CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 18 Stacks and Queues.
1 Chapter 7 Stacks and Queues. 2 Stack ADT Recall that ADT is abstract data type, a set of data and a set of operations that act upon the data. In a stack,
1 Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
LINKED LISTS Linear Linked List. November 1, 2005Linked Lists2 of 48 Linked Lists Like stacks and queues, linked lists are lists of nodes that point to.
Lab 7 Queue ADT. OVERVIEW The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added.
Clicker questions and stuff 12/5/13 CSE 1102 Fall 2013.
Stacks And Queues Chapter 18.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
QUEUES What are Queues? Creating a Queue Enqueuing and Dequeuing Testing for an Empty Queue.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
April 27, 2017 COSC Data Structures I Review & Final Exam
Copyright © Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by Tony.
“The desire for safety stands against every great and noble enterprise.” – Tacitus Thought for the Day.
3/3/20161 Stacks and Queues Introduction to Data Structures Ananda Gunawardena.
Chapter 4 ADTs Stack and Queue. 4-2 Formal ADT Specifications The Java interface construct lets us collect together method interfaces into a syntactic.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
1 Queues (Continued) Queue ADT Linked queue implementation Array queue implementation Circular array queue implementation Deque Reading L&C , 9.3.
Click to edit Master text styles Stacks Data Structure.
Lecture 16 Stacks and Queues Richard Gesick. Sample test questions 1.Write a definition for a Node class that holds a number. 2.Write a method that sums.
Linked Structures - Stacks. Linked Structures An alternative to array-based implementations are linked structures A linked structure uses object references.
Sections 3.4 Formal Specification
Stack: a Linked Implementation
Comprehensive Introduction to OOP with Java, C. Thomas Wu Stack ADT
QueueStack CS1020.
CSE 373: Data Structures and Algorithms
Stacks and Queues.
The Stack ADT. 3-2 Objectives Define a stack collection Use a stack to solve a problem Examine an array implementation of a stack.
Building Java Programs
CMSC 341 Lecture 5 Stacks, Queues
Queues, Deques and Priority Queues
Queues, Deques and Priority Queues
ADT list.
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Lecture 16 Stacks and Queues CSE /26/2018.
slides created by Alyssa Harding
Stacks, Queues, and Deques
Lecture 16 Stacks and Queues CSE /26/2018.
CMPT 225 Lecture 8 – Queue.
Data Structures & Programming
Presentation transcript:

So what's next? Introduction to data structures Two Perspectives: Abstract description (capabilities) Implementation(s) For structures: Stack Queue Deque (maybe)

Clicker quiz 12/3/13 CSE 1102 Fall 2013

The country with the red star on it is: A. Canada B. Sweden C. Latvia D. Finland E. None of the above

A. "Finland" B. "is" C. "my" D. "home" E. None of the above Suppose I have a stack s that can store Strings, and I execute the following statements starting with an empty stack : 1. s.push("Finland"); 2. s.push("is"); 3. s.push("my"); 4. String w = s.peek(); 5. String x = s.pop(); 6. s.push("home"); 7. String y = s.pop(); 8. String z = s.pop(); What is the value of z?

A. "Sweden" B. "is" C. "my" D. "neighbor" E. None of the above Suppose I have a queue q that can store Strings, and I execute the following statements starting with an empty queue : 1. q.enqueue("Sweden"); 2. q.enqueue("is"); 3. q.enqueue("my"); 4. String w = q.dequeue(); 5. String x = q.peek(); 6. q.enqueue("neighbor"); 7. String y = q.dequeue(); 8. String z = q.dequeue(); What is the value of z?

Clicker questions and stuff 12/3/13 CSE 1102 Fall 2013

Abstract Data Types (1970s) Description of a data structure that includes only its operations, not its implementation In Java, ADTs are best modeled by interfaces

Example ADT: Stack Operations: push(element) – adds element to "top" of the stack pop – returns the top element of the stack, which is removed from the stack peek – returns the top element of the stack without changing the stack isEmpty – returns true if stack is empty, false otherwise

Stack intuitions examples in the world uses in computing

A. "Iceland" B. "cool" C. true D. false E. None of the above Suppose I have a stack S that can store Strings, and I execute the following statements starting with an empty stack : 1. S.push("Iceland"); 2. S.push("is"); 3. String w = S.peek(); 4. String x = S.pop(); 5. S.push("cool"); 6. String y = S.pop(); 7. boolean z = S.isEmpty(); What is the value of z?

Example ADT: Queue Operations: enqueue(element) – adds element to "back" of the queue dequeue – returns the "front" element of the queue, which is removed from the queue front – returns the front element of the queue without changing the queue isEmpty – returns true if queue is empty, false otherwise

Queue intuitions examples in the world uses in computing

A. "Sweden" B. "is" C. "my" D. "neighbor" E. None of the above Suppose I have a queue q that can store Strings, and I execute the following statements starting with an empty queue : 1. q.enqueue("Sweden"); 2. q.enqueue("is"); 3. q.enqueue("my"); 4. String w = q.dequeue(); 5. String x = q.peek(); 6. q.enqueue("neighbor"); 7. String y = q.dequeue(); 8. String z = q.dequeue(); What is the value of z?

Suppose we have a class that acts as a Holder for Colors: public class ColorHolder { private Color _myColor; public ColorHolder(Color color) { _myColor = color; } public Color getValue(){ return _myColor; } public void setColor (Color col) { _myColor = col; } It might be useful to have a more general version, that could hold anything. Quick Topic 1: Generics

Java allows us to define a class generically, with type declared at instantiation time: public class Holder { private ValType _myValue; public Holder(ValType value) { _myValue = value; } public ValType getValue(){ return _myValue; } public void setValue (ValType value) { _myValue = value; } To use this class, you need to declare and instantiate object with actual type: Holder currentColor; currentColor = new Holder (Color.red); More examples in Chapter 14!

Example: Node class holds an element of some type, plus another Node of the same sort. public class Node { private ValType _myValue; private Node _next public Node(ValType value) { _myValue = value; _next = null; } public ValType getValue(){ return _myValue; } public void setValue (ValType value) { _myValue = value; } public Node getNext(){ return _next; } Since _next is a Node of the same sort, we can chain instances of these together.

Suppose we want to diagram a set of instances and their relationships Answer: object (or instance) diagram Quick Topic 2: Object Diagrams For example, a sequence of two Nodes whose elements are Cars

"syntax"

Topic 3: Are you on this list? Bidhan Adhikari Devin Delaney Erming Gao Christopher Lawrence Jeffrey Metter Jonathan Rarey

ADT: defined by capabilities In Java: a natural fit to Interfaces, e.g. public interface StackADT { void push(ElementType t); ElementType pop(); ElementType peek(); boolean isEmpty(); }

So let's use Nodes to implement a Stack One instance variable, _top, which refers to a Node Stack fred = new Stack (); // create empty Stack // now add some stuff fred.push(new Car(Color.RED)); fred.push(new Car(Color.BLUE));

So let's use Nodes to implement a Stack ctd. One instance variable, _top, which refers to a Node // now pop something Car ethyl = fred.pop(); // what actually happens is this

So let's use Nodes to implement a Stack public class Stack implements StackADT { private Node _top; public Stack() { _top = null; } public void push(EiType value) { Node nodeToPush = new Node (value); nodeToPush.setNext(_top); _top = nodeToPush; } public EiType pop() { EiType retVal = _top.getValue(); _top = _top.getNext(); return retVal; } public boolean isEmpty(){ return _top == null; }