CSC 212 – Data Structures
-
Upload
rudyard-bentley -
Category
Documents
-
view
35 -
download
0
description
Transcript of CSC 212 – Data Structures
Final Exam
Friday, Dec. 15 from 3:15 – 5:15 in OM 205 Plan for exam to take full 2 hours
Talk to me if this is a major problem Exam covers material from entire semester
Format like 2 midtermsStill open-book, open-note, closed-computer
Design computational solutions Decompose a problem into logically grouped subprograms Develop and analyze algorithms
Program well Code in a high-level language Debug a program Write and use a test plan Document a program Work independently
Organize data for effective use Use fundamental data structures Implement data structures
Understand the role of computing and the computer professional Present or explain ideas Weigh different solutions and explain or argue why one was preferable
Objectives Met in CSC212
Design computational solutions Decompose a problem into logically grouped subprograms Develop and analyze algorithms
Program well Code in a high-level language Debug a program Write and use a test plan Document a program Work independently
Organize data for effective use Use fundamental data structures Implement data structures
Understand the role of computing and the computer professional Present or explain ideas Weigh different solutions and explain or argue why one was preferable
What Gets Inherited and How
All fields & methods (members) inherited Public members accessed as if declared in subclass
(but they should not be!) Private members cannot be accessed Protected members used as if subclass declared
them as private (but, do not do this!)
Subclasses can override/overload method Call method defined for instance’s type
Subclasses can hide field Use the field defined for variable’s type
Exceptions in Java
Throw exception when problem detectedMust instantiate instance before throwing
Handle by catching exceptionOnly catch exceptions you want to handle
Method lists exceptions thrown via throws Include any exception not caughtDoes not matter if method was originator
Abstract methods cannot have a body IOU that subclasses will define the method
Class with abstract methods is abstractCannot be instantiated, but can be extendedCan have fields & methods
Interface declares abstract methodsAll methods are public abstract methods
Abstract Methods
Arrays vs. Linked Lists
Two alternate ways to hold dataNot ADTs, but specific implementations
Arrays generally offer quick access times, but hard to maintain and resize
Linked lists offer flexible sizing, but access times can be slowCan be singly, doubly, or circularly linked
Queues, Stacks, & Deques
Offer simple means of tracking elementsLike a line, Queues are first-in, first-out Stacks are last-in, first-outDeques can be accessed from either end
Cannot access interior elementsNo way of searching for an element either
Implemented with either array or linked listArrays can violate unlimited space guarantee
Iterators & Iterables
Important interfaces defined by Java:import java.util.Iterator;import java.lang.Iterable;
public interface Iterator<E> { E next(); boolean hasNext() throws NoSuchElementException; void remove() throws UnsupportedOperationException;}
public interface Iterable<E> { Iterator<E> iterator();}
More Iterator & Iterable
Use Iterator to abstract processingIterator<Integer> it;...for (it = myList.iterator(); it.hasNext(); ) { Integer i = it.next(); ...}
Process Iterable objects in an even easier way...for (Integer i : myList) { ...}
Lists
List is Iterable collection of elementsCan now access any element in collectionDifferent lists provide other accessor methods
IndexList access using 0-based ranksNot the same as array -- ranks can change
PositionList access via relative positionRelies on Position ADT to hold elements
Sequence combines two lists & Deque
Maps & Dictionaries
Rely on Entry ADT -- key & value pair Maps have at most 1 Entry with any key
New Entry replaces previous Entry with keyRemove Entry by specifying its key
Entrys in Dictionary can share keyNew Entry does not affect others with that keyRemove Entry by specifying key AND value
Map & Dictionary Implementation
Many possible implementations possibleSequence with elements kept in sorted orderSequence with elements kept in unsorted
orderHash Table (which is not an ADT)
Hash table stores all of the EntrysHash function uses key to compute integer
from 0 to size of table - 1Goal is storing entry (k, v) at index h(k)
Collisions
When implemented with hash table & two Keys share hash code
Three commonly used handling schemesSeparate chaining: table contains Lists of
entries hashed to that indexLinear probing: loop through array looking for
first open array locationDouble hashing: plug key into another hash
function to find empty array location
Sets & Partitions
Sets implement at least three operationsintersect, union, & subtractConstructor others depend on how Set used
Set’s operations rely on instances of subclasses of Merge
Partition is first use of Set Instances hold collection of disjoint SetsSet’s constructor must take single element
Quick-Select & Pattern Matching Quick-Select finds nth element in SequenceUses divide-and-conquer for speedHonestly, not a lot to ask about it
Know the pattern matching algorithmsWhen & why we may want to use one over
the othersAlso know how to perform their actions --
mostly “trained monkey” work
Hints for Studying
The exam will NOT require:Memorizing ADT’s methodsMemorizing Node implementationsMemorizing big-Oh time proofs(Recursion)
The exam WILL require:Knowing what the methods doBe able to implement the methodsComputing big-Oh time complexity
Studying For the Exam
1. What does the ADT do? What are real-world analogues for it?
2. How is the ADT used? What applications use this ADT? How do they use it and why?
3. Can you explain examples’ answers? Keep reviewing material until you can do this cold
4. How do we implement the ADT? Why is it implemented in that way? What are the performance tradeoffs?