English Conundrum s In English, add “s” to end of word to make plural s But for 1 special...
-
Upload
asher-mosley -
Category
Documents
-
view
218 -
download
0
Transcript of English Conundrum s In English, add “s” to end of word to make plural s But for 1 special...
English Conundrum
In English, add “s” to end of word to make plural
But for 1 special word, adding an “s” at the end: Makes word go from plural to singular Makes masculine word into a feminine one
What is this special word?
English Conundrum
In English, add “s” to end of word to make plural
But for 1 special word, adding an “s” at the end: Makes word go from plural to singular Makes masculine word into a feminine one
What is this special word?
princes princess
Announcements
If you need more review of Java… I have lots of good resources – talk to me Use “Additional Help” link on webpage
Weekly assignments problems due before class
Problems NOT optional Get back into coding & remove rust from
summer If cannot solve in 10 minutes, talk to me
ASAP
Primitives vs. References
Primitive Variables Reference Variables
Variables hold actual value Assignment copies
value Update variable being
assigned only
Aliased with assignments Both refer to same
instance Both see updates to
object Re-assigning variable
does not update aliases
Array Variables
Can be set to null to mark there is no array
Cannot use until after have instantiated arrayint[] bob = new int[30];Car[] parkingLot = new Car[300];
Variables aliased by any assignments Can deduce, array variables always
references May hold primitive data, but these are
separate issue
Array Variables
Can be set to null to mark there is no array
Cannot use until after have instantiated arrayint[] bob = new int[30];Car[] parkingLot = new Car[300];
Variables aliased by any assignments Can deduce, array variables always
references May hold primitive data, but these are
separate issue
Memory Trace Example
int[] data = new int[3];int[] al = data;for (int i = 0; i < data.length; i++) { data[i] = i * 2;}al[0] = 5;al = new int[1];al[0] = 7;
Entries Are Variables, Too!
Within an array entries like individual variablesint[] bob = new int[30];Car[] parkingLot = new Car[300];
bob’s entries would be primitive variables parkingLot’s entries refer to instances
Entries initialized like variable when array created bob’s entries would all be set to 0 null stored in all entries in parkingLot
Memory Trace Example
Car[] data = new Car[3];Car[] al = data;for (int i = 0; i < data.length; i++) { data[i] = new Car(); }al[0] = new Car();al = new Car[1];al[0] = data[0];data[0] = data[1];
Higher-Dimension Arrays
Arrays instantiated with any dimension desired 2-d array is table identifying entries by row
& columnint[][] pixels = new int[20][100];pixels[1][18] = 32;
Higher-Dimension Arrays
Arrays instantiated with any dimension desired 2-d array is table identifying entries by row
& columnint[][] pixels = new int[20][100];pixels[1][18] = 32;
Higher-Dimension Arrays
Arrays instantiated with any dimension desired 2-d array is table identifying entries by row
& columnint[][] pixels = new int[20][100];pixels[1][18] = 32;
Entries stored in virtual cube with 3-d arrayint[][][] bert = new int[60][4][10];bert[45][3][7] = 42;
Rare to use higher dimensions, but is possible
Computer Professor
Memory Huge (> 250GB) Can’t remember 18 names
Computingspeed
Fast (> 2 billion/second)
Slow (needs fingers & toes)
Takes direction
Does exactly as told Leaves toilet seat up
Speed of updates
Nearly instantaneous Wears t-shirts from 1989
Ability to plan & reason
Cannot make plans; No reasoning skills;Lacks common sense
Makes (semi-)complicated plans; Good reasoning skills;Lacks common sense
Computer vs. Professor
People are very good at reasoning & analyzing Slow computing outcome of each potential decision Considering every possible data combinations hard Trouble when lots of data available to be examined
Computers can perform simple tasks quickly Maintain billions of data items within memory Very good when at performing simple operations Cannot create plan since lacks concept of future To do any task, must be given specific instructions
People vs. Computers
Computers best processing huge data sets Perform specific tasks and output results:
College’s students’ transcripts availableCompute & print receipt for groceries
Filter & provide few items for user to choose fromPersonalized recommendations from AmazonGoogle’s list of matching web pages
Most of year examines how to organize data How data used determines structures selected
Computers Use Collections
How Could We Do This?
Know simple way to organize data: array Entries refer to another array to create
matrices Many limitations arise when using
arrays Must specify unchangeable size when
createdPirate[] rum = new Pirate[1];Pirate[] h2o = new Pirate[variable];rum = new Pirate[60]; // old array was lost!h2o = rum; // h20 now alias to rum’s instance
Waste memory requiring maximum size for array/* Each Amazon.com customer uses 400+MB of RAM! */Rating[] hertz = new Rating[100000000];
Often need to keep values ordered or organized Alphabetical list of names & phone
numbers Keep list of job bids from smallest to largest Web pages ordered from most to least
important Desired index’s not just assigned new
value
Inserting into an Array
1 2 n
e
0
Often need to keep values ordered or organized Alphabetical list of names & phone
numbers Keep list of job bids from smallest to largest Web pages ordered from most to least
important Desired index’s not just assigned new
value Lose current value stored at that index
Inserting into an Array
1 2 n
e
0
Often need to keep values ordered or organized Alphabetical list of names & phone
numbers Keep list of job bids from smallest to largest Web pages ordered from most to least
important Desired index’s not just assigned new
value Lose current value stored at that index Instead, must first shift values within array
Inserting into an Array
1 2 n
e
0
Often need to keep values ordered or organized Alphabetical list of names & phone
numbers Keep list of job bids from smallest to largest Web pages ordered from most to least
important Desired index’s not just assigned new
value Lose current value stored at that index Instead, must first shift values within array
Inserting into an Array
1 2 n
e
0
Often need to keep values ordered or organized Alphabetical list of names & phone
numbers Keep list of job bids from smallest to largest Web pages ordered from most to least
important Desired index’s not just assigned new
value Lose current value stored at that index Instead, must first shift values within array
Inserting into an Array
1 2 n
e
0
Often need to keep values ordered or organized Alphabetical list of names & phone
numbers Keep list of job bids from smallest to largest Web pages ordered from most to least
important Desired index’s not just assigned new
value Lose current value stored at that index Instead, must first shift values within array
Inserting into an Array
1 2 n
e
0
Often need to keep values ordered or organized Alphabetical list of names & phone
numbers Keep list of job bids from smallest to largest Web pages ordered from most to least
important Desired index’s not just assigned new
value Lose current value stored at that index Instead, must first shift values within array
Inserting into an Array
1 2 n
e
0
Often need to keep values ordered or organized Alphabetical list of names & phone
numbers Keep list of job bids from smallest to largest Web pages ordered from most to least
important Desired index’s not just assigned new
value Lose current value stored at that index Instead, must first shift values within array
Inserting into an Array
1 2 n
e
0
Often need to keep values ordered or organized Alphabetical list of names & phone
numbers Keep list of job bids from smallest to largest Web pages ordered from most to least
important Desired index’s not just assigned new
value Lose current value stored at that index Instead, must first shift values within array
Inserting into an Array
1 2 n
e
0
Often need to keep values ordered or organized Alphabetical list of names & phone
numbers Keep list of job bids from smallest to largest Web pages ordered from most to least
important Desired index’s not just assigned new
value Lose current value stored at that index Instead, must first shift values within array
Inserting into an Array
1 2 n
e
0
Often need to keep values ordered or organized Alphabetical list of names & phone
numbers Keep list of job bids from smallest to largest Web pages ordered from most to least
important Desired index’s not just assigned new
value Lose current value stored at that index Instead, must first shift values within array
Inserting into an Array
1 2 n
e
0
Still need to keep values ordered or organized
Removing a value presents own set of problems Could simply assign null
Removing From an Array
0 1 2 n
Still need to keep values ordered or organized
Removing a value presents own set of problems Could simply assign null, but that creates
a gap Finding start & end of data hard once gaps
allowed
Removing From an Array
0 1 2 n
Still need to keep values ordered or organized
Removing a value presents own set of problems Could simply assign null, but that creates
a gap Finding start & end of data hard once gaps
allowed Instead, must shift values to fill in all gaps
that exist
Removing From an Array
0 1 2 n
Still need to keep values ordered or organized
Removing a value presents own set of problems Could simply assign null, but that creates
a gap Finding start & end of data hard once gaps
allowed Instead, must shift values to fill in all gaps
that exist
Removing From an Array
0 1 2 n
Still need to keep values ordered or organized
Removing a value presents own set of problems Could simply assign null, but that creates
a gap Finding start & end of data hard once gaps
allowed Instead, must shift values to fill in all gaps
that exist
Removing From an Array
0 1 2 n
Still need to keep values ordered or organized
Removing a value presents own set of problems Could simply assign null, but that creates
a gap Finding start & end of data hard once gaps
allowed Instead, must shift values to fill in all gaps
that exist
Removing From an Array
0 1 2 n
Still need to keep values ordered or organized
Removing a value presents own set of problems Could simply assign null, but that creates
a gap Finding start & end of data hard once gaps
allowed Instead, must shift values to fill in all gaps
that exist
Removing From an Array
0 1 2 n
Still need to keep values ordered or organized
Removing a value presents own set of problems Could simply assign null, but that creates
a gap Finding start & end of data hard once gaps
allowed Instead, must shift values to fill in all gaps
that exist
Removing From an Array
0 1 2 n
Still need to keep values ordered or organized
Removing a value presents own set of problems Could simply assign null, but that creates
a gap Finding start & end of data hard once gaps
allowed Instead, must shift values to fill in all gaps
that exist
Removing From an Array
0 1 2 n
Still need to keep values ordered or organized
Removing a value presents own set of problems Could simply assign null, but that creates
a gap Finding start & end of data hard once gaps
allowed Instead, must shift values to fill in all gaps
that exist
Removing From an Array
0 1 2 n
Still need to keep values ordered or organized
Removing a value presents own set of problems Could simply assign null, but that creates
a gap Finding start & end of data hard once gaps
allowed Instead, must shift values to fill in all gaps
that exist
Removing From an Array
0 1 2 n
For Next Lecture
Moving to review OO concerns next week How do we write & use classes on our own? Instances can differ, but how is this
expressed? What is an instance variable & how is it
used? What does static mean? When would we
want it?
There is weekly assignment problem on Angel Due before Wednesday’s lecture (via
Submitter) Get back into the swing of writing Java code