CSC 212 Sequences & Iterators. Announcements Midterm in one week  Will cover through chapter 5 of book  Midterm will be open book, open note (but, closed.

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
CSC 212 – Data Structures Lecture 22: PositionList.
Iterators and Sequences1 © 2010 Goodrich, Tamassia.
© 2004 Goodrich, Tamassia Vectors1. © 2004 Goodrich, Tamassia Vectors2 The Vector ADT (“Vector” = “Array List” in §6.1) The Vector ADT extends the notion.
© 2004 Goodrich, Tamassia Sequences and Iterators1.
1 Queues (5.2) CSE 2011 Winter May Announcements York Programming Contest Link also available from.
CHAPTER 4 Queues. Queue  The queue, like the stack, is a widely used data structure  A queue differs from a stack in one important way  A stack is.
CHAPTER 4 Queues MIDTERM THURSDAY, OCTOBER 17 IN LAB.
CSC 212 – Data Structures. Using Stack Stack Limitations  Great for Pez dispensers, JVMs,& methods  All of these use most recent item added only 
Problem of the Day  What do you get when you cross a mountain climber and a grape?
Problem of the Day  At low tide, a ship docks in the harbor  Ship is 9’ above the water line when it docks  Over the side hangs a rope ladder w/ rungs.
Java Collections Framework COMP53 Oct 24, Collections Framework A unified architecture for representing and manipulating collections Allows collections.
Exam Review 2 Chapter 5 – 9 CSC212 RS March 31, 2011, CS Dept, CCNY.
CSC 212 Vectors, Lists, & Sequences. Announcement Daily quizzes accepted electronically only  Submit via one or other Dropbox  also accepted,
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
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.
CSC 212 Stacks & Queues. Announcement Daily quizzes accepted electronically only  Submit via one or other Dropbox  Cannot force you to compile & test.
© 2004 Goodrich, Tamassia Vectors1 Lecture 03 Vectors, Lists and Sequences Topics Vectors Lists Sequences.
Cmp Sci 187: Midterm Review Based on Lecture Notes.
Chapter 3: Arrays, Linked Lists, and Recursion
© 2004 Goodrich, Tamassia Sequences and Iterators1.
Stacks, Queues, and Deques
CSC 212 – Data Structures Lecture 13: Linked Lists.
1 Collection, Iterable, and Iterator Interfaces The Collection Interface and its Hierarchy The Iterable and Iterator Interfaces For-each Loops with Iterable.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Review for Midterm Chapter 1-9 CSc 212 Data Structures.
Data Structures and Programming.  Today:  Administrivia  Introduction to 225, Stacks  Course website: 
Problem of the Day  Rich old man tells his 2 children he will hold a race to decide who gets his fortune. SLOWEST  Winner is one who owns SLOWEST horse.
Problem of the Day  What do you get when you cross a mountain climber and a grape?
Information and Computer Sciences University of Hawaii, Manoa
Midterm Review CSE 2011 Winter October 2015.
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.
LECTURE 26: QUEUES CSC 212 – Data Structures. Using Stack.
LECTURE 34: MAPS & HASH CSC 212 – Data Structures.
CSC 212 – Data Structures Lecture 37: Course Review.
CSC 212 – Data Structures Lecture 17: Stacks. Question of the Day Move one matchstick to produce a square.
CS-2852 Data Structures Week 5, Class 2 – Testing and Stacks Announcement: Lab Demos - 2/3 & 4 on Friday Testing  Definitions, Example  (tentative) Testing.
Week 4 - Monday.  What did we talk about last time?  Queues  Implementing queues with circular arrays.
Problem of the Day  Simplify this equation: (x - a) * (x - b) * (x - c) * … * (x - z)
Question of the Day  Two English words change their pronunciation when their first letter is capitalized. What are they?
Question of the Day  Three people check into a hotel for which they pay the manager $30. The manager finds out the rate is $25 and gives $5 to the bellboy.
Vectors, Lists, Sequences. Vectors Linear sequence s of n elements e rank – number of elements before e in s Vector supports access to elements via their.
LECTURE 27: DEQUES CSC 212 – Data Structures. Roses are red and violets are blue Implement push, pop, & top And you’re a Stack too! Stack & ADT Memory.
Problem Of The Day  Two missiles speed directly toward each other  One goes 9,000 miles per hour  Other goes 21,000 miles per hour.  If they start.
CS1020 Data Structures and Algorithms I Lecture Note #14
CSC 212 Trees & Recursion. Announcements Midterm grades were generally good  Wide distributions of scores, however  Will hand back at end of class 
CSC 212 – Data Structures Lecture 23: Iterators. Question of the Day Thieves guild states it will sell to members: lock picking kits  $0.67 each 40’
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
© 2006 Pearson Addison-Wesley. All rights reserved5 B-1 Chapter 5 (continued) Linked Lists.
Sequences1 Vectors Positions Lists General Sequences Bubble Sort Algorithm.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
April 27, 2017 COSC Data Structures I Review & Final Exam
Exam Review 2 Chapter 5 – 9 CSC212 FG CS Dept, CCNY.
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
CS Fall 2012, Lab 04 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /29/2016 Changes of Office Hours  Monday.
“The desire for safety stands against every great and noble enterprise.” – Tacitus Thought for the Day.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.
Sequences and Iterators
Lists and Sequences 9/21/2018 7:21 PM Sequences Sequences
Sequences and Iterators
THURSDAY, OCTOBER 17 IN LAB
Lists and Sequences 12/8/2018 2:26 PM Sequences Sequences
Dynamic Data Structures and Generics
Chapter 4 Queues.
Midterm Review CSE116A,B.
Presentation transcript:

CSC 212 Sequences & Iterators

Announcements Midterm in one week  Will cover through chapter 5 of book  Midterm will be open book, open note (but, closed computer) Will not be at office hours tomorrow  Or at next 3 lectures (lucky you!)  Will hold all-day office hours Tuesday

Sequences Sequences combine List and Vector ADTs Also enables conversion between the two  atRank – returns the position object for a given rank  rankOf – given a position, returns its rank public interface Sequence extends List, Vector { public Position atRank(int r) throws public int rankOf(Position p) throws }

Implementing Sequences Like all ADTs, Sequences do not require any specific implementation  We discuss 2 implementations today: Array-based Sequences Doubly linked list-based Sequences

Linked-list base Sequence Node class implements Position interface  Makes position based calls simple  Using/finding rank requires searching through list nodes/positions elements

Array-based Sequence Ranks are easy to use  But, must create class implementing Position Use array in circular manner  Just like with queues 0123 positions elements S lf

Group Work public class Node implements Position { protected Object elem; protected Node prev; protected Node next;... } public class LLSequence implements Sequence { protected Node head; protected int size;... } public class ArrPos implements Position { protected Object elem; protected int rank;... } public class ArrSequence implements Sequence { protected ArrPos arr[]; protected int first; protected int last;... } Write atRank(r) & rankOf(p) for each class:

Iterator ADT Often process data in a collection in order  Position defines current element  But need collection to get next item  Cannot easily determine when end is reached Cannot iterate through data without accessing the list/sequence  Limits modularity & reusability

Iterator Interface public interface Iterator { boolean hasNext(); Object next(); } Must call next() to get initial item  Future calls to next() step through items Should either of these throw an exception?

Getting Iterators Extend the List (and therefore Sequence) ADT with two methods: /** Iterate through the * positions in the list */ public Iterator positions(); /** Iterate through elements in * the list */ public Iterator elements();

Using Iterators Loops can now rely on using Iterators  Improves modularity As long as new collection provides an iterator, can change ADT used for collection at will  Improves reuse Code relies only on iterator existence and not on any specific implementation details

Review Material for the Midterm Topics we have discussed:  Programming in Java  Class hierarchy and inheritance Field hiding, method overriding, method chaining What assignments are legal and when is typecasting needed  Big-Oh notation Constant, Linear, and Logarithmic time  Recursion

Review Material for the Midterm More topics:  Writing/Using Linked Lists  Stacks & Queues Differences between LIFO and FIFO  Vectors, Lists, & Sequences How rank and position works Iterators

Ideas for Reviewing (Re-)Read book sections you do not understand Look over daily quizzes and the solutions  Make sure you understand why the answers are what they are

Ideas for Reviewing Will post practice midterm on course webpage  Will update with more questions on Saturday  Practice contains questions that could be on an actual midterm  Also posting (separate) answer key

Daily Quiz Due Friday at 4PM me a question you think would be good for the midterm and its solution  I usually include questions from students  Provides a good focus for your studying