CSC 212 – Data Structures Lecture 22: PositionList.

Slides:



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

Linked Lists Chapter 4.
Queues and Linked Lists
© 2004 Goodrich, Tamassia Node-Lists1 6.2 Node Lists.
Lists1 © 2010 Goodrich, Tamassia. Position ADT The Position ADT models the notion of place within a data structure where a single object is stored It.
1 Array-based Implementation An array Q of maximum size N Need to keep track the front and rear of the queue: f: index of the front object r: index immediately.
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.
Queue & List Data Structures & Algorithm Abstract Data Types (ADTs) ADT is a mathematically specified entity that defines a set of its instances,
Queues 4/14/2017 5:24 PM 5.2 Queues Queues Dr Zeinab Eid.
CSC 212 – Data Structures. Using Stack Stack Limitations  Great for Pez dispensers, JVMs,& methods  All of these use most recent item added only 
Data Structures: A Pseudocode Approach with C
CS Data Structures II Review COSC 2006 April 14, 2017
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.
Data Structures Lecture 4 Fang Yu Department of Management Information Systems National Chengchi University Fall 2010.
Lists and Iterators CSC311: Data Structures 1 Chapter 6 Lists and Iterators Objectives Array Lists and Vectors: ADT and Implementation Node Lists: ADT.
Lists and Iterators (Chapter 6) COMP53 Oct 22, 2007.
1 Problem Solving Abstraction Oftentimes, different real-world problems can be modeled using the same underlying idea Examples: Runtime storage, Undo operation.
CSC 212 Vectors, Lists, & Sequences. Announcement Daily quizzes accepted electronically only  Submit via one or other Dropbox  also accepted,
© 2004 Goodrich, Tamassia Vectors1 Lecture 03 Vectors, Lists and Sequences Topics Vectors Lists Sequences.
CSC 212 – Data Structures Lecture 21: IndexList a/k/a Vector, ArrayList.
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data.
CSC 212 – Data Structures Lecture 13: Linked Lists.
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Problem Of The Day  Decipher the following phrase: STANDS 0 _
CSC 212 – Data Structures Lecture 20: Deques. Question of the Day How did the clerk know that the man telling the following story is a fraud? I hope you.
October 18, Algorithms and Data Structures Lecture V Simonas Šaltenis Nykredit Center for Database Research Aalborg University
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?
Problem of the Day  What do you get when you cross a mountain climber and a grape?
LECTURE 36: DICTIONARY CSC 212 – Data Structures.
LECTURE 26: QUEUES CSC 212 – Data Structures. Using Stack.
CSC 212 – Data Structures Lecture 37: Course Review.
CS 221 Analysis of Algorithms Data Structures Vectors, Lists.
CS261 – Data Structures Iterator ADT Dynamic Array and Linked List.
CSC 212 – Data Structures Lecture 17: Stacks. Question of the Day Move one matchstick to produce a square.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Lecture 3 Queues Queues1. queue: – Retrieves elements in the order they were added. – First-In, First-Out ("FIFO") – Elements are stored in order of insertion.
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.
Lecture5: Linked Lists Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
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.
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.
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.
© 2004 Goodrich, Tamassia Lists1. © 2004 Goodrich, Tamassia Lists2 Position ADT (§ 5.2.2) The Position ADT models the notion of place within a data structure.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Introduction Dynamic Data Structures Grow and shrink at execution time Linked lists are dynamic structures where data items are “linked up in a chain”
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.
Lists1 © 2010 Goodrich, Tamassia. Position ADT  The Position ADT models the notion of place within a data structure where a single object is stored 
Problem of the Day  Simplify this equation: (x - a) * (x - b) * (x - c) * … * (x - z)
Linked List, Stacks Queues
Lists and Iterators 5/3/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Double-Ended Queues Chapter 5.
Ch7. List and Iterator ADTs
Sequences and Iterators
COMP9024: Data Structures and Algorithms
Week 3 - Friday CS221.
Ch7. List and Iterator ADTs
Lists and Iterators 3/9/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Queues 11/22/2018 6:47 AM 5.2 Queues Queues Dr Zeinab Eid.
" A list is only as strong as its weakest link. " - Donald Knuth
Recall What is a Data Structure Very Fundamental Data Structures
Linked Lists & Iterators
CS210- Lecture 6 Jun 13, 2005 Announcements
CS210- Lecture 7 Jun 14, 2005 Agenda Practice Session Vector
Abstract Data Types Stacks CSCI 240
Presentation transcript:

CSC 212 – Data Structures Lecture 22: PositionList

Question of the Day On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door, the host, opens another door which has a goat. He then asks, "Do you change your selection?” Should you?

List ADT Accesses all elements in a Collection  Add new element before existing one  Get the 3 rd element in the Collection  Loop over all elements without removing them  Cannot be done with Stack, Queue & Deque List ADTs differ how they provide access

IndexList != array Extends idea of an array, but…  Does not have constant size  Elements’ ranks may change over time Abstracts away implementation details  Could be done using college students!

Insertion add( r, e ) “shifts” elements to make space Can take O(n) time  True for array or linked list implementation S 012n r S 012n r S 012n e r

Deletion remove( r ) “shifts” remaining elements to fill hole Also takes O(n) time S 012n r S 012n r S 012n r

PositionList ADT Abstracts idea of a linked list  No ranks or numerical ordering of data Access elements in relative terms  Work from first() & last() elements in list  Travel to next() & prev() elements Insert elements based on relative location  addFirst(e), addLast(e) -- add e as expected  addBefore(p,e), addAfter(p,e) -- add e relative to the existing position p remove() & set() works as normal

insertAfter(p, X) ABXC ABC p ABC p X p headertrailer headertrailer header

remove(p) ABC p headertrailer X ABC headertrailer ABXC p header

PositionList Problem For speed, want to use actual Nodes  Implementation may use trained monkeys  Do not want to expose implementation details Solution: use Position Interface public interface Position { public E element(); } Node class can implement Position  But so can other classes  Hides exact implementation details

Converting Position to Node private Node checkPosition(Position p) throws InvalidPositionException { if (p == null) { throw new InvalidPositionException(); } if (!(p instanceof Node)) { throw new InvalidPositionException(); } return (Node )p; }

Your Turn Get back into groups and do activity

Before Next Lecture… Keep up with your reading! Finish Week #9 Assignment Work on Programming Assignment #2