Presentation is loading. Please wait.

Presentation is loading. Please wait.

English Conundrum s  In English, add “s” to end of word to make plural s  But for 1 special word, adding an “s” at the end:  Makes word go from plural.

Similar presentations


Presentation on theme: "English Conundrum s  In English, add “s” to end of word to make plural s  But for 1 special word, adding an “s” at the end:  Makes word go from plural."— Presentation transcript:

1 English Conundrum s  In English, add “s” to end of word to make plural s  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?

2 English Conundrum

3

4 Announcements

5 Primitives vs. References Primitive VariablesReference 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

6 Opening Question  Are array variables primitives or references?

7 Array Variables  Can be set to null to mark there is no array  Cannot use until after have instantiated array int[] 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

8 Array Variables  Can be set to null to mark there is no array  Cannot use until after have instantiated array int[] 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

9 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;

10 Entries Are Variables, Too!  Within an array entries like individual variables int[] bob = new int[30]; Car[] parkingLot = new Car[300];  bob ’s entries would be primitive variables entries  parkingLot ’s entries refer to instances  Entries initialized like variable when array created entries  bob ’s entries would all be set to 0 entries  null stored in all entries in parkingLot

11 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];

12 Higher-Dimension Arrays  Arrays instantiated with any dimension desired  2-d array is table

13 Higher-Dimension Arrays  Arrays instantiated with any dimension desired  2-d array is table identifying entries by row & column int[][] pixels = new int[20][100]; pixels[1][18] = 32;

14 Higher-Dimension Arrays  Arrays instantiated with any dimension desired  2-d array is table identifying entries by row & column int[][] pixels = new int[20][100]; pixels[1][18] = 32;

15 Higher-Dimension Arrays  Arrays instantiated with any dimension desired  2-d array is table identifying entries by row & column int[][] pixels = new int[20][100]; pixels[1][18] = 32;  Entries stored in virtual cube with 3-d array int[][][] bert = new int[60][4][10]; bert[45][3][7] = 42;  Rare to use higher dimensions, but is possible

16 Computer Professor MemoryHuge (> 250GB)Can’t remember 18 names Computing speed Fast (> 2 billion/second)Slow (needs fingers & toes) Takes direction Does exactly as toldLeaves toilet seat up Speed of updates Nearly instantaneousWears 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

17  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

18  Computers best processing huge data sets  Perform specific tasks and output results: College’s students’ transcripts available Compute & print receipt for groceries  Filter & provide few items for user to choose from Personalized recommendations from Amazon Google’s list of matching web pages  Most of year examines how to organize data  How data used determines structures selected Computers Use Collections

19 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 created Pirate[] 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];

20  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 12 n e 0

21  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 12 n e 0

22  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 12 n e 0

23  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 12 n e 0

24  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 12 n e 0

25  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 12 n e 0

26  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 12 n e 0

27  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 12 n e 0

28  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 12 n e 0

29  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 12 n e 0

30  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 12 n e 0

31  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 12 n

32  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 12 n

33  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 12 n

34  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 12 n

35  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 12 n

36  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 12 n

37  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 12 n

38  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 12 n

39  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 12 n

40  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 12 n

41  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 12 n

42 Your Turn  Get into your groups and complete activity

43 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


Download ppt "English Conundrum s  In English, add “s” to end of word to make plural s  But for 1 special word, adding an “s” at the end:  Makes word go from plural."

Similar presentations


Ads by Google