Problem of the Day  What do you get when you cross a mountain climber and a grape?

Slides:



Advertisements
Similar presentations
Topic 12 The List ADT. 9-2 Objectives Examine list processing and various ordering techniques Define a list abstract data type Examine various list implementations.
Advertisements

Linked Lists Linear collections.
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Section 2.5 Single-Linked Lists. A linked list is useful for inserting and removing at arbitrary locations The ArrayList is limited because its add and.
1 Lists A List ADT Types of Lists Lists in Java Collections API Using ordered lists – Tournament Maker Using indexed lists – Josephus Problem Implementing.
David Weinberg presents Linked Lists: The Background  Linked Lists are similar to ArrayLists in their appearance and method of manipulation  They do.
CSC 212 – Data Structures Lecture 22: PositionList.
Iterators and Sequences1 © 2010 Goodrich, Tamassia.
CSC 212 – Data Structures. Using Stack Stack Limitations  Great for Pez dispensers, JVMs,& methods  All of these use most recent item added only 
CSC 205 – Java Programming II Lecture 25 March 8, 2002.
Lecture 8 CS203. Implementation of Data Structures 2 In the last couple of weeks, we have covered various data structures that are implemented in the.
An Array-Based Implementation of the ADT List public class ListArrayBased implements ListInterface { private static final int MAX_LIST = 50; private Object.
Lists and Iterators CSC311: Data Structures 1 Chapter 6 Lists and Iterators Objectives Array Lists and Vectors: ADT and Implementation Node Lists: ADT.
CHAPTER 8 Lists. 2 A list is a linear collection Adding and removing elements in lists are not restricted by the collection structure We will examine.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
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.
CSC 212 – Data Structures Lecture 21: IndexList a/k/a Vector, ArrayList.
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.
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?
(c) University of Washington14-1 CSC 143 Java Collections.
Problem of the Day Bezout acquired 19 camels through his trading skill, “Of the collected camels,” it said in the late merchant’s will, “Exactly half go.
LinkedList Many slides from Horstmann modified by Dr V.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
LECTURE 26: QUEUES CSC 212 – Data Structures. Using Stack.
LECTURE 34: MAPS & HASH CSC 212 – Data Structures.
LECTURE 24: STACK ADTS CSC 212 – Data Structures.
2013-T2 Lecture 18 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, and John.
Problem of the Day  Simplify this equation: (x - a) * (x - b) * (x - c) * … * (x - z)
Interfaces, Classes, Collections School of Engineering and Computer Science, Victoria University of Wellington COMP T2 Lecture 3 Thomas Kuehne.
Question of the Day  Two English words change their pronunciation when their first letter is capitalized. What are they?
(c) University of Washington16-1 CSC 143 Java Linked Lists Reading: Ch. 20.
(c) University of Washington16-1 CSC 143 Java Lists via Links Reading: Ch. 23.
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.
CSS446 Spring 2014 Nan Wang.  To understand the implementation of linked lists and array lists  To analyze the efficiency of fundamental operations.
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.
Ordered Linked Lists using Abstract Data Types (ADT) in Java Presented by: Andrew Aken.
Lecture Objectives  Linked list data structures:  Singly-linked (cont.)  Doubly-linked  Circular  Implementing the List interface as a linked list.
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.
1 CMPSCI 187 Computer Science 187 Introduction to Introduction to Programming with Data Structures Lecture 8 Lists, Iterators, and Doubly Linked Lists.
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.
COM S 228 Collections and Iterators Instructor: Ying Cai Department of Computer Science Iowa State University Office: Atanasoff 201.
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.
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.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
List Interface and Linked List Mrs. Furman March 25, 2010.
Recursive Objects (Part 2) 1. Adding to the front of the list  adding to the front of the list  t.addFirst('z') or t.add(0, 'z') 2 'a' 'x' LinkedList.
Interfaces, Classes, Collections School of Engineering and Computer Science, Victoria University of Wellington COMP T2 Lecture 3 Marcus Frean.
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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 18 List ADT Animated Version.
Question of the Day  What three letter word completes the first word and starts the second one: DON???CAR.
1 CMPSCI 187 Computer Science 187 Introduction to Introduction to Programming with Data Structures Lecture 9 Doubly Linked Lists and Ordered Lists Lecture.
Problem of the Day  Simplify this equation: (x - a) * (x - b) * (x - c) * … * (x - z)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by.
CSC 212 – Data Structures Lecture 28: More Hash and Dictionaries.
CSCI 62 Data Structures Dr. Joshua Stough September 23, 2008.
The List ADT.
Single-Linked Lists.
Ch7. List and Iterator ADTs
Announcements & Review
Lecture 23: Doubly Linked List
Top Ten Words that Almost Rhyme with “Peas”
Collections Framework
Building Java Programs
TCSS 143, Autumn 2004 Lecture Notes
Presentation transcript:

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?  Nothing, you cannot cross a scalar.

CSC 212 – Data Structures

public interface List extends Collection { public E removeFirst() throws EmptyCollectionException; public E removeLast() throws EmptyCollectionException; public E remove(E elem) throws ElementNotFoundException; public E first() throws EmptyCollectionException; public E last() throws EmptyCollectionException; public boolean contains(E elem); public get(int i) throws EmptyCollectionException; } List Interface

public interface OrderedList extends List { public void add(E elem); } public interface UnorderedList extends List { public void addToFront(E elem); public void addToRear(E elem); public void addAfter(E elem, E tgt) throws ElementNotFoundException; } List Subinterfaces

Array-based List.addAt()  addAt( i, e ) “shifts” elements to make space  Needs to make hole in array to place element  Can take O(n) time for this shifting  When adding list’s end may take O(1) time, but…  Constant time amortizes cost of growing array 012 e n-1 i

Array-based List.remove()  remove( e ) “shifts” elements down to fill hole  Not only way, but other options are difficult & slow  O(n) time required in the general case  But for specific situations could take only O(1) time  But must consider worst case when computing big-Oh 012 e n-1 i

Something About L IST ’s Methods

What They Have In Common  All methods first search through the L IST  Searching differs if L IST ordered or unordered  Each method has different action with found element  Could  Could rewrite code, but want to be VERY lazy  Use private method that returns index where found  All (public) methods then rely upon this private one

What They Have In Common  All methods first search through the L IST  Searching differs if L IST ordered or unordered  Each method has different action with found element  Could  Could rewrite code, but want to be VERY lazy  Use private method that returns index where found  All (public) methods then rely upon this private one

What They Have In Common

What Does find() Do?  find() returns location element found  Array organized via indices, so returning int logical  Linked list has no indices & not centrally organized  Must we write separate find() methods?

What Does find() Do?  find() returns location element found  Array organized via indices, so returning int logical  Linked list has no indices & not centrally organized  Must we write separate find() methods?  The different L IST implementations not related  All of the code rewritten between types of L IST s  This duplication is not & should not be a surprise

What Does find() Do?  find() returns location element found  Array organized via indices, so returning int logical  Linked list has no indices & not centrally organized  Node s organize data held within a linked list  In linked list-based L IST, find() returns Node  Can move forward & backward if doubly-linked  If element not in L IST, method can return null  Bigger generalization from this discussion  Node in linked list equivalent to index in array

Key Concept For Rest of Week Node in linked list equivalent to index in array

What About add*() Methods?  Work similar among these methods, too  All of these methods must create new Node  Update size field in each of these  Would still like to avoid having to duplicate code  Difference is WHERE node will be needed  addFirst() & addRear() work at L IST ’s ends  Middle of L IST used (usually) by add() & addAfter()

What About add*() Methods?  Work similar among these methods, too  All of these methods must create new Node  Update size field in each of these  Would still like to avoid having to duplicate code  Difference is WHERE node will be needed  addFirst() & addRear() work at L IST ’s ends  Middle of L IST used (usually) by add() & addAfter()  Must write each; little overlapping code here  prev & next set differently; bulk of code is there

ArrayList v. LinkedList MethodArrayListLinkedList removeFirst() O(n)O(n)O(1) removeLast() O(1) addToFront() O(n)O(n)O(1) addToRear() O(1) (amortized)O(1) addAfter() O(n)O(n)O(n)O(n) first(), last() O(1) add(), contains(), remove() O(n)O(n)O(n)O(n)

ArrayList v. LinkedList MethodArrayListLinkedList removeFirst() O(n)O(n) removeLast() addToFront() O(n)O(n) addToRear() O(1) (amortized) addAfter() O(n)O(n)O(n)O(n) first(), last() O(1) add(), contains(), remove() O(n)O(n)O(n)O(n)

ArrayList v. LinkedList MethodArrayListLinkedList removeFirst() O(n)O(n) removeLast() addToFront() O(n)O(n) addToRear() O(1) (amortized) addAfter() O(n)O(n)O(n)O(n) first(), last() O(1) add(), contains(), remove() O(n)O(n)O(n)O(n) get(), addAt() O(n)O(n)

 Collection which we can access all elements  Add element after an existing one  Collection can remove any element it contains  Loop over all elements without removing them  L IST ADTs differ in how they provide access  A RRAY L IST ’s indices give quick access to specific position  Good at working at relative location with LinkedList L IST ADT

Does Absolute Position Matter?

Relativity Can Be Important

Your Turn  Get into your groups and complete activity

For Next Lecture  Read section 7.1 – 7.2 for Wednesday’s lecture  What is an Iterator and what does it do?  How do we connect ideas of Iterable & L IST ?  What are for-each loops & why do they make life easy?  Week #10 assignment  Week #10 assignment posted to Angel  As usual, will be due tomorrow