21
CSC 212 – Data Structures Lecture 37: Course Review

CSC 212 – Data Structures Lecture 37: Course Review

Embed Size (px)

Citation preview

Page 1: CSC 212 – Data Structures Lecture 37: Course Review

CSC 212 –Data Structures

Lecture 37:

Course Review

Page 2: CSC 212 – Data Structures Lecture 37: Course Review

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

Page 3: CSC 212 – Data Structures Lecture 37: Course Review

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

Page 4: CSC 212 – Data Structures Lecture 37: Course Review

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

Page 5: CSC 212 – Data Structures Lecture 37: Course Review

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

Page 6: CSC 212 – Data Structures Lecture 37: Course Review

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

Page 7: CSC 212 – Data Structures Lecture 37: Course Review

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

Page 8: CSC 212 – Data Structures Lecture 37: Course Review

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

Page 9: CSC 212 – Data Structures Lecture 37: Course Review

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();}

Page 10: CSC 212 – Data Structures Lecture 37: Course Review

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) { ...}

Page 11: CSC 212 – Data Structures Lecture 37: Course Review

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

Page 12: CSC 212 – Data Structures Lecture 37: Course Review

How Computer Normally Works

I’ll have a ManhattanNo problem.That’ll be $2 billion

Page 13: CSC 212 – Data Structures Lecture 37: Course Review

Working With Map & Dictionary

I’ll have a ManhattanNo problem.That’ll be $2 billion

key

value

Page 14: CSC 212 – Data Structures Lecture 37: Course Review

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

Page 15: CSC 212 – Data Structures Lecture 37: Course Review

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)

Page 16: CSC 212 – Data Structures Lecture 37: Course Review

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

Page 17: CSC 212 – Data Structures Lecture 37: Course Review

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

Page 18: CSC 212 – Data Structures Lecture 37: Course Review

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

Page 19: CSC 212 – Data Structures Lecture 37: Course Review

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

Page 20: CSC 212 – Data Structures Lecture 37: Course Review

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?

Page 21: CSC 212 – Data Structures Lecture 37: Course Review

Before Next Lecture…

CSC212 Final Exam:Fri., Dec. 15 from 3:15–5:15 in OM 205

Bring 1 (or more) pencils to the exam Do well on all your finals Have a good Christmas break Get ready for new term of challenges & fun