CSC 212 – Data Structures.  Fri., Dec. 14 th from 2:45 – 4:45PM in SH1028  Plan on exam taking full 2 hours  If major problem, come talk to me ASAP.

Slides:



Advertisements
Similar presentations
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Advertisements

CSC 212 – Data Structures. Using Stack Stack Limitations  Great for Pez dispensers, JVMs,& methods  All of these use most recent item added only 
CSC 212 – Data Structures.  Fri., Dec. 17 th from 8AM – 10AM in OM 200  Plan on exam taking full 2 hours  If major problem, come talk to me ASAP 
Problem of the Day  To get into club, must get past bouncer  Recorded correct responses of those before you  Guard said five & response was four  Guard.
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.
Problem of the Day  You are trapped alone in a dark room with:  Candle;  Wood stove; and  Gas lamp (with full tank).  You only have one match; what.
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.
Trees Chapter 8.
ITEC200 – Week08 Trees. 2 Chapter Objectives Students can: Describe the Tree abstract data type and use tree terminology such as.
CSE 143 Lecture 22: Advanced List Implementation (ADTs; interfaces; abstract classes; inner classes; generics; iterators)
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
Fall 2007CS 2251 Trees Chapter 8. Fall 2007CS 2252 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information.
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L12 (Chapter 20) Lists, Stacks,
Cmp Sci 187: Midterm Review Based on Lecture Notes.
CSC 212 – Data Structures Lecture 21: IndexList a/k/a Vector, ArrayList.
CSC 213 – Large Scale Programming Lecture 14: Sequence-based Priority Queues.
Maps A map is an object that maps keys to values Each key can map to at most one value, and a map cannot contain duplicate keys KeyValue Map Examples Dictionaries:
Trees CS /02/05 L7: Trees Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Definition.
Problem Of The Day  Decipher the following phrase: STANDS 0 _
1 Chapter 25 Trees Iterators Heaps Priority Queues.
Trees Chapter 8. 2 Tree Terminology A tree consists of a collection of elements or nodes, organized hierarchically. The node at the top of a tree is called.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Trees. Tree Terminology Chapter 8: Trees 2 A tree consists of a collection of elements or nodes, with each node linked to its successors The node at the.
1 Review of Java Higher Level Language Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – Selection –Flow of.
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.
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
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.
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
1 Heaps and Priority Queues Starring: Min Heap Co-Starring: Max Heap.
1 Chapter 17 Object-Oriented Data Structures. 2 Objectives F To describe what a data structure is (§17.1). F To explain the limitations of arrays (§17.1).
CSC 212 – Data Structures Lecture 37: Course Review.
CS 206 Introduction to Computer Science II 02 / 13 / 2009 Instructor: Michael Eckmann.
CSC 213 – Large Scale Programming Lecture 15: Heap-based Priority Queue.
CSE 143 Lecture 24 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, , slides.
CSC 212 – Data Structures Lecture 17: Stacks. Question of the Day Move one matchstick to produce a square.
Final Exam Review CS Total Points – 60 Points Writing Programs – 50 Points Tracing Algorithms, determining results, and drawing pictures – 50.
Problem of the Day  You drive a bus from Rotterdam to Delft.  At the 1 st stop, 33 people get in.  At the 2 nd stop, 7 add people & 11 passengers leave.
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.
Problem of the Day  Solve this equation by moving the numbers: 76 = 24.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 25 Trees, Iterators,
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.
Week 13 - Friday.  What did we talk about last time?  Sorting  Insertion sort  Merge sort  Started quicksort.
CSC 213 – Large Scale Programming Lecture 10: Tree & Binary Tree Implementation.
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.
CSC 212 – Data Structures.  Tues., Dec. 10 th from 8:00 – 10:ooAM in OM220  Plan on exam taking full 2 hours  If major problem, come talk to me ASAP.
Quotes “From each according to his ability, to each according to his needs” -- Karl Marx/Queue ADT “In America, first you get the sugar, then you get the.
Problem of the Day  You are trapped alone in a dark room with:  Candle;  Wood stove; and  Gas lamp (with full tank).  You only have one match; what.
Priority Queues CS 110: Data Structures and Algorithms First Semester,
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.
 Saturday, April 20, 8:30-11:00am in B9201  Similar in style to written midterm exam  May include (a little) coding on paper  About 1.5 times as long.
CS Prelim Review – 10/15/09  First prelim is TOMORROW at 7:30 PM  Review session – Tonight 7:30 PM, Phillips 101  Things you should do:  Review every.
LECTURE 8: EXCEPTIONS CSC 212 – Data Structures. Error Handling Goals  What should we do when an error occurs?  Should alert system to the error  May.
Final Exam Review CS Total Points – 20 Points Writing Programs – 65 Points Tracing Algorithms, determining results, and drawing pictures – 50.
Priority Queues CS /02/05 L7: PQs Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved.
Problem of the Day  Simplify this equation: (x - a) * (x - b) * (x - c) * … * (x - z)
Course: Programming II - Abstract Data Types HeapsSlide Number 1 The ADT Heap So far we have seen the following sorting types : 1) Linked List sort by.
CSC 213 – Large Scale Programming. Priority Queue ADT  Prioritizes Entry s using their keys  For Entry s with equal priorities, order not specified.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Sequences and Iterators
Lecture 15: More Iterators
Heaps © 2010 Goodrich, Tamassia Heaps Heaps
Ch. 8 Priority Queues And Heaps
A Heap Implementation Chapter 26 Adapted from Pearson Education, Inc.
Presentation transcript:

CSC 212 – Data Structures

 Fri., Dec. 14 th from 2:45 – 4:45PM in SH1028  Plan on exam taking full 2 hours  If major problem, come talk to me ASAP  Exam covers material from entire semester  Open-book & open-note so bring what you’ve got  My handouts, solutions, & computers are not allowed  Cannot collaborate with a neighbor on the exam  Problems will be in a similar style to 2 midterms Final Exam

Classes vs. Objects  Classes are blueprints describing data type static  By itself, class only used for static fields & methods  Objects are instances of a class new  New objects created (instantiated) using new  Fields describe state of an object  Object’s behavior represented by methods

static v. Instance-based  Methods that are instance-based have this  Aliased to instance on which method called  Can directly use fields & call methods in class  No this parameter in static methods  Code directly using instance-based members illegal…  … using static fields & methods perfectly legal  As always, can use object to access its members  Call static methods via class if protection allows

Abstract Methods abstract  Methods declared abstract cannot have body  IOU for subclasses which will eventually define it  abstract abstract  abstract methods only in abstract classes abstract  Cannot instantiate an abstract class  But could still have fields & (non-abstract) methods  abstract  abstract methods declared by interfaces  Interfaces cannot declare fields  public abstract  public abstract methods only in interfaces

Interfaces  Can only declare important constant fields  public static final must be used for fields  Interface declares public abstract methods  Methods must be defined by classes implementing it  But method’s body cannot be defined in interface

Interfaces CANNOT INSTANTIATE AN INTERFACE  Only classes can be instantiated

Inheritance  implements extends  implements & extends used for relationships  Both imply there exists an IS - A relationship public class Student extends Person {…} public class Cat extends Mammal { … } public class AQ implements Queue {…}

 All Java classes extend exactly 1 other class  All fields & methods inherited from the superclass  Within subclass, can access non-private members  Private methods inherited, but cannot be accessed  Classes can implement any number of interfaces  Must implement methods from the interface Inheritance

 Subclass can override/overload inherited methods  Instance’s  Instance’s type determines which method is called  Parameter list stays the same to override the method  Overload method by modifying parameter list Overriding & Hiding

 Subclass can override/overload inherited methods  Instance’s  Instance’s type determines which method is called  Parameter list stays the same to override the method  Overload method by modifying parameter list Overriding & Hiding

 Subclass can override/overload inherited methods  Instance’s  Instance’s type determines which method is called  Parameter list stays the same to override the method  Overload method by modifying parameter list Overriding & Hiding

Exceptions in Java  throw  throw an exception when an error detected  Exception s are objects - need an instance to throw  trycatch  try executing code & catch errors to handle  trycatch  try only when you will catch 1 or more exceptions catch  Do not need to catch every exception  If it is never caught, program will crash  Not a bad thing – had an unfixable error! throws  Exceptions listed in methods’ throws clause  Uncaught exception only need to be listed  Should list even if thrown by another method

 Concrete implementations used to hold data  Not ADTs  Arrays are easier to use & provide quicker access  Also are impossible to grow  Implementing ADTs harder due to lack of flexibility  Slower access & more complex to use linked lists  Implementing ADTs easier with increased flexibility  Can be singly, doubly, or circularly linked Arrays vs. Linked Lists

Stack vs. Queue Order read if Queue Order read if Stack

QueueStackDeque Simplest ADTs

D EQUE Q UEUE S TACK addFront() addLast() enqueue()push() getFront() getLast() front()top() removeFront() removeLast() dequeue()pop() ADT Operations

import java.util.Iterator; import java.lang.Iterable; public interface Iterator { E next() throws NoSuchElementException; boolean hasNext(); void remove() throws UnsupportedOperationException; } public interface Iterable { Iterator iterator(); } Iterators & Iterables

Iterable v. Iterator  Iterable class is/has data we want to use  Declaring it Iterable promises generic way to access  Does not do any work, but provides object doing work  While has access, Iterator (usually) separate class  Iterator instance returns values in other class/array  Always (almost) includes field with reference to data holder  Field (cursor) tracks next location in data to be returned

 Abstract work in processing with Iterator Iterable myList; Iterator it;... for (it = myList.iterator(); it.hasNext(); ) { Integer i = it.next();... }  Process Iterable objects in an even easier way... for (Integer i : myList) {... } More Iterator & Iterable

 Collection which we can access all elements  Add element before an existing one  Return the 3 rd element in List  Loop over all elements without removing them  L IST ADTs differ in how they provide access  I NDEX L IST uses indices for absolution positioning  Can only use relative positions in N ODE L IST  All L ISTS are I TERABLE IndexList & NodeList

Sequence ADT  Combines D EQUE, I NDEX L IST, & P OSITION L IST  Includes all methods defined by these interfaces  Adds 2 methods to convert between systems  Get Position at index using atIndex(i)  indexOf(pos) returns index of a Position

Sequence ADT  Combines D EQUE, I NDEX L IST, & P OSITION L IST  Includes all methods defined by these interfaces  Adds 2 methods to convert between systems  Get Position at index using atIndex(i)  indexOf(pos) returns index of a Position

Trees vs. Binary Trees  Both represent parent-child relationships  Both consist of single "root" node & its descendants  Nodes can have at most one parent  Root nodes are orphans -- do not have a parent must  All others, the non-root nodes must have parent  Children not required for any node in the tree  No limit to number of children for non-binary trees  2 children for node in binary tree is the maximum

Traversal Methods  Many traversals, differ in order nodes visited  Do parent then do each kid in pre-order traversal

Traversal Methods  Many traversals, differ in order nodes visited  Do parent then do each kid in pre-order traversal  Post-order traversal does kids before doing parents

Traversal Methods  Many traversals, differ in order nodes visited  Do parent then do each kid in pre-order traversal  Post-order traversal does kids before doing parents  Do left kid, parent, then right kid in in-order traversal

Traversal Methods  Many traversals, differ in order nodes visited  Do parent then do each kid in pre-order traversal  Post-order traversal does kids before doing parents  Do left kid, parent, then right kid in in-order traversal  Really, really, really simple to record what is done  Follow simple algorithm to see how it works

Traversal Methods  Many traversals, differ in order nodes visited  Do parent then do each kid in pre-order traversal  Post-order traversal does kids before doing parents  Do left kid, parent, then right kid in in-order traversal  Really, really, really simple to record what is done  Follow simple algorithm to see how it works  Took CSC212 before you were born & I need to trace it

Traversal Methods  Many traversals, differ in order nodes visited  Do parent then do each kid in pre-order traversal  Post-order traversal does kids before doing parents  Do left kid, parent, then right kid in in-order traversal  Really, really, really simple to record what is done  Follow simple algorithm to see how it works  Took CSC212 before you were born & I need to trace it  Pro tip: Just trace it on paper

Tree D Visualization of Tree B D A CE F B AF CE Tree root size  6 

BinaryTree   Picturing Linked BinaryTree B C A D   BACD BinaryTree root size  4

Priority Queue ADT  Priority queue uses strict ordering of data  Values assigned priority when added to the queue completely biased order  Priorities used to process in completely biased order First you get the sugar, then you get the power, then you get the women

Priority Queue ADT  PriorityQueue yet another Collection  Prioritize each datum contained in the collection  PQ is organized from lowest to highest priority  Access smallest priority only sort of like Queue  min() & removeMin() return priority & value  Implementation not defined: this is still an ADT  Remember that organization & order is theoretical only

 PriorityQueue yet another Collection  Prioritize each datum contained in the collection  PQ is organized from lowest to highest priority  Access smallest priority only sort of like Queue  min() & removeMin() return priority & value  Implementation not defined: this is still an ADT  Remember that organization & order is theoretical only Priority Queue ADT order is theoretical only

Entry s in a PriorityQueue  PriorityQueues use Entry to hold data  As with Position, implementations may differ  Entry has 2 items that define how it gets used  PQ will only use key – the priority given to the Entry  Value is important data to be processed by program

Sequence -based Priority Queue

Heaps  Binary-tree based PQ implementation  Still structured using parent-child relationship  At most 2 children & 1 parent for each node in tree  Heaps must also satisfy 2 additional properties  Parent at least as important as its children  Structure must form a complete binary tree

Hints for Studying  Will NOT require memorizing:  ADT’s methods  Node implementations  Big-Oh time proofs  (Memorizing anything)

(& be ready to look up):  You should know (& be ready to look up):  How ADT implementations work (tracing & more)  For each method what it does & what it returns  Where & why each ADT would be used  For each ADT implementations, its pros & cons  How to compute big-Oh time complexity Hints for Studying

1. What does the ADT do? Where in the real-world is this found? 2. How is the ADT used? What are the applications of this ADT? How is it used and why? 3. How do we implement the ADT? Given the implementation, why do we do it like that? What tradeoffs does this implementation make? Studying For the Exam

“Subtle” Hint

Final Exam Schedule  Lab Mastery Exam is: Tues., Dec. 11 th from 3:45 – 4:45PM in SH1008  Final Exam is: Fri., Dec. 14 th from 2:45 – 4:45PM in SH1028