You are on page 1of 13

2/1/2014

First Day of Class


Syllabus Assignment0 NextWeek Chapter1 Neverattributetomalice Chapter2 thatwhichisadequately explainedbystupidity. HanlonsRazor Break Chapter3

DueNextWeek:
Assignment0 Scan/ReadChapter1and2 ReadChapter3 EspeciallyRecursionifthisisnew ReadChapter4

Your Text Book

5th Edition

Physical -- Whatever you can find it for. One time download on Wiley -- $60 CourseSmart eBook (Rental) -- $47 - $60

Syllabus
MaybeIshouldreaditaloud,linebyline Whatarequizzes? Keepupwiththereading,trytoscanthedayschapteronce throughoncebeforeclass. Myjob:highlight,clarifyandexplain Assignmentsareduebeforethestartofclassontheassigned date.Lateworkwillbepenalized. Basically:Read,ShowUp,turninyourassignmentsontime.

2/1/2014

Class structure and Success


TheBook
Read&Understand Lectureismostlyrelatedto& fromthebook Most(9095%)oftheExam material

Class structure and Success


TheAssignments
Notdirectlyrelatedtobook material ComplicatedbutShort(inLOC) BestGrades=Coloringwithinthe lines. 1javafilealways.

Assignment 0
Needleinahaystack
UsethesuppliedInput/Output formatforfullcredit. Part1 findtheNeEDle Part2 abinaryneedle00000000

2/1/2014

Chapter 1 Quick Java Review, Terminology, and pseudo code

Object thethinginRAM Type whatkindofObject Class thethingthatdefinesthetype InstanceVariables/Fields accessible aspectsofatype Classmodifiers abstract,final,public, private

Chapter 1 Quick Java Review, Terminology, and pseudo code

Base(Primitive)Typesvs.Objects
int vs Integer *Stackvs Heap

Objectcreationandreferences
IntegermyAge =newInteger(); IntegermyTwinsAge =myAge;

Enums

Chapter 1 Quick Java Review, Terminology, and pseudo code

Methods returnatypeexceptfor voidsandconstructors(constructors returntheirowntypeimplicitly) Parametersarealwayspassbyvalue


Personp=newperson(james); changeName(p); p.getName ()? changeName(personp){ Personk=newPerson(Jim); p =k;}

2/1/2014

Chapter 1 Quick Java Review, Terminology, and pseudo code

Operators + /*etc ==!=<=<>>=?: Rememberthis?


int a=8; int b=8; Integerc=newInteger(8); Integerd=newInteger(8); a==b? c==d?

Chapter 1 Quick Java Review, Terminology, and pseudo code

Casting whenyouchangeatypeto somethingbiggerorsmallerinthe sameline


Reallywheneveryouareconverting betweencompatibletypes.
int a=8; floatb=a; int c=b;//Errorhere int c=(int)b;//better

Chapter 1 Quick Java Review, Terminology, and pseudo code

Controlflow
If,Else while,Do while For Switch

RemembertheseIhopeso
Break/continue

2/1/2014

Chapter 1 Quick Java Review, Terminology, and pseudo code

Arrays 0based Arraysareobjects,soitworkslike objects


int[]a=newint[10]; b=a; a[3]=39; b[3]?

Chapter 1 Quick Java Review, Terminology, and pseudo code

Pseudocode
ItsJava,butitsnotJava

Thebookisconsistentwithitself,but WhenIwriteontheboard theremightnotbe goodbracing,indentation,orthecorrectform foroperators. BegeneroustomeandIwillbegenerousto you

Chapter 2 OO Design

Abstraction

2/1/2014

Chapter 2 OO Design Inheritance(extends)


IsA
Specialization Extension

HasA
containment

Overriding methods
Refinement replacement

Chapter 2 OO Design Exceptions


Exception(al)cases
Notforthingsthatshouldbeexpected Wouldthecallerwanttohandlethismost ofthetime?
Rememberabstraction(encapsulation)

RememberThrows,TryCatch,etc.

Chapter 2 OO Design Interfaces


TypeSafety/StrongTyping/CompilerAuto complete Inheritanceisalsoaninterface
Andalittlemore

Definesasetofmethodsignaturesthat mustbeimplemented. Canimplement manyinterfaces Interfacescanimplementotherinterfaces andextendasingleotherinterface.

2/1/2014

Chapter 2 OO Design Casting(Alittlemore)


Widening(upcasting)
Carc=newCar(); Vehiclev=(Vehicle)t; Vehiclev=c; CrushVehicle(v);

Narrowing(downcasting)
Vehiclev=newVehicle(); Truckt =v;//Compile ERROR Truckt=newTruck(); v=t; //Ok,seeabove LoadTruckBed (v);//CompileErrorvisnotatruck LoadTruckBed ((Truck)v);//ok,butonlybecausevisreallyatruck!

Chapter 2 OO Design Generics


Astructurethatallowsthingsthatare similartobeimplementedwiththesame code,eventhoughthetypesaredifferent. Easier(thoughslightlyincorrect) thinkof anarray
Storesmultiplethingswithafew methodssuchasindexof,length,etc. Butthethingisspecifiedwhenyoucreate thearray

Break
Syllabus Assignment0 NextWeek Chapter1 Chapter2 Break Chapter3 Assignment1 TwoWeeks

2/1/2014

Chapter 3 Part 1 ArraysandArraylists Applications


Directapplications
Sortedcollectionofobjects(elementarydatabase) Orinthecaseofthebook,highscores

Indirectapplications
Auxiliarydatastructureforalgorithms Componentofotherdatastructures

Singly Linked List ( 3.2)


Asinglylinkedlistisa concrete datastructure consistingofasequence of nodes Eachnodestores
element linktothenextnode elem next

node

23

Inserting at the Head


1. Allocateanewnode 2. Insertnewelement 3. Havenewnodepoint tooldhead 4. Updateheadtopoint tonewnode

24

Linked Lists

Linked Lists

2/1/2014

Removing at the Head


1. Updateheadtopoint tonextnodeinthe list 2. Allowgarbage collectortoreclaim theformerfirstnode

Linked Lists

25

Inserting at the Tail


1. Allocate a new
node

2. Insert new element 3. Have new node


point to null

4. Have old last node


point to new node

5. Update tail to point


to new node
Linked Lists

26

Removing at the Tail


Removingatthetailof asinglylinkedlistis notefficient! Thereisnoconstant timewaytoupdate thetailtopointtothe previousnode

Linked Lists

27

2/1/2014

NodesimplementPositionandstore:
element linktothepreviousnode linktothenextnode

prev

next

header

nodes/positions

trailer

elements

WevisualizeoperationinsertAfter(p,X),whichreturnspositionq

A p A p A

B X q B X

AlgorithmaddAfter(p,e): Createanewnodev v.setElement(e) v.setPrev(p) {linkvtoitspredecessor} v.setNext(p.getNext()) {linkvtoitssuccessor} (p.getNext()).setPrev(v) {linkpsoldsuccessortov} p.setNext(v) {linkptoitsnewsuccessor,v} returnv {thepositionfortheelemente}

Lists

2010 Goodrich, Tamassia

Insertion Algorithm

Lists

2010 Goodrich, Tamassia

Insertion

Lists

Specialtrailerandheadernodes

elem

node

2010 Goodrich, Tamassia

Doubly Linked List

28

29

30

10

2/1/2014

Wevisualizeremove(p),wherep=last()

p C C D

A A

B B

p D

Algorithmremove(p): t=p.element {atemporaryvariabletoholdthe returnvalue} (p.getPrev()).setNext(p.getNext()) {linkingoutp} (p.getNext()).setPrev(p.getPrev()) p.setPrev(null) {invalidatingthepositionp} p.setNext(null) returnt

Circularly Linked List


Asinglylinkedbutthelast nodedoesnotpointtonull, itpointstothefirstnode. Thereisntahead
Thereisacurrentorcursor next

Singleinthebook,butcouldbe double

elem

node

33

Linked Lists

Lists

2010 Goodrich, Tamassia

Deletion Algorithm

Lists

2010 Goodrich, Tamassia

Deletion

31

32

11

2/1/2014

Algorithmremove(p): t=p.element {atemporaryvariabletoholdthe returnvalue} (p.getPrev()).setNext(p.getNext()) {linkingoutp} (p.getNext()).setPrev(p.getPrev()) p.setPrev(null) {invalidatingthepositionp} p.setNext(null) returnt

Circularly Linked List


Asinglylinkedbutthelast nodedoesnotpointtonull, itpointstothefirstnode. Thereisntahead
Thereisacurrentorcursor next

Singleinthebook,butcouldbe double

elem

node

35

Next time on DS&A: Chapter 3 & 4


Ourfirstalgorithmicpattern Recursion
Linear Binary Multiple

AnalysisofAlgorithms

Linked Lists

Lists

2010 Goodrich, Tamassia

Deletion Algorithm

34

12

2/1/2014

My Availability
Syllabus Assignment0 NextWeek Chapter1 Chapter2 Break Chapter3
Questions?Help?
Cell:262.320.7778 Email:sartoa@uwp.edu

DueNextWeek:
Assignment0 Scan/ReadChapter1and2 ReadChapter3 EspeciallyRecursionifthisisnew ReadChapter4

13