1 / 48

COP 3540 Data Structures with OOP

COP 3540 Data Structures with OOP. Arrays Chapter 2. The Basics of Arrays in Java – Array Creation. Two kinds of Arrays: primitive (ints, floats, double, char, unsigned, …) and objects In Java arrays are objects not primitives.

alanis
Download Presentation

COP 3540 Data Structures with OOP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COP 3540 Data Structures with OOP Arrays Chapter 2

  2. The Basics of Arrays in Java – Array Creation • Two kinds of Arrays: • primitive (ints, floats, double, char, unsigned, …) and • objects • In Java arrays are objects not primitives. • Since all arrays are objects, must use ‘new’ to create. (except for String objects) • Two ways to create an array in Java • 1. int[ ] intArray; // only the reference intArray = new int[100]; // creates the array with space for 100 integers // intArray now points (references) this array. 2. Alternatively: int intArray[ ] = new int[100]; Either format is acceptable. (I prefer the latter) What is a primitive? Where is the array data actually stored? Where is the reference stored? Attribute: int arrayLength = intArray.length; // number of elements • Where does this ‘length’ attributecome from? • How do you know intArray.length is not a method?

  3. The Basics of Arrays in Java – Accessing Array Elements • Array access is via an index number What is an index? Same as a subscript? temp = intArray[3]; //assign value of fourth element // in intArray to temp (assumes // temp is an int). intArray[7] = 66; // assigns value of 66 to // intArray[7]. (8th element) Array Index Out of Bounds – discuss…. intArray = new int [100]; // bounds?

  4. The Basics of Arrays in Java – Initialization • Unlike some languages, integer arrays are set to 0. • autoData[ ] carArray = new autoData[4000]; • “I have an array of autoData objects named carArray and have 4000 of them.” • Each array element has null value (pointer value is null) • No object values have been created. • Assigning values to primitive array types: • int[ ] intArray = {2,4,78,54,67}; // initializationlist • Also sets array to five elements: intArray[0] … inArray[4].

  5. Declaring an array of objects (not primitives) • If you had a class of, say, State objects (or Student objects, …) you might declare an array of these like: State [ ] myStates = new State[50]; • Declares an array of 50 State objects (not yet loaded or instantiated) called myStates. You’d refer to an individual State in myStates via an array item, such as myStates[i], … • Each object, when initialized with values, looks like State, which you would have already defined via public class State with attributes and essential methods, like the constructor and perhaps a few other methods. • In the following code, however, we are dealing with an array of ints (primitives) so we do not have to declare what they look like or the operations that we will perform on them.

  6. The Basics of Arrays in Java – Array Example – p1 // array.java - // demonstrates Java arrays This is an array of primitives / not objects!! class ArrayApp { public static void main(String[] args) { int [ ] arr; // reference to array arr = new int [100]; // allocates array for 100 ‘longs.’ int nElems = 0; // number of items (to be used for size of arr) int j; // loop counter int searchKey; // key of item to search for //-------------------------------------------------------------- arr[0] = 77; // insert 10 items // brute force approach!! arr[1] = 99; // specifically assigning each element to arr[2] = 44; // a specific location in the array! arr[3] = 55; arr[4] = 22; //’hard coded values” arr[5] = 88; arr[6] = 11; arr[7] = 00; arr[8] = 66; arr[9] = 33; nElems = 10; // now 10 items in array //-------------------------------------------------------------- for (j=0; j< nElems; j++) // display items // value of j upon leaving loop? System.out.print( arr[j] + " "); // How many times is the ‘for’ executed? System.out.println (""); // How many time is the System.out… executed //--------------------------------------------------------------

  7. The Basics of Arrays in Java – Array Example – p2 // Continuing… searchKey = 66; // find item with key 66 for(j=0; j<nElems; j++) // for each element, // any difference here j++ or ++j ?? if(arr[j] == searchKey) // found item? break; // yes, exit before end // What does ‘break’ do? if(j == nElems) // at the end? Under what conditions will I ‘get to’ this if statement? System.out.println("Can't find " + searchKey); // yes Will this always work??? else // covers successful and unsuccessful search. System.out.println("Found " + searchKey); //-------------------------------------------------------------- searchKey = 55; // delete item with key 55 for(j=0; j<nElems; j++) // look for it if(arr[j] == searchKey) // braches needed? Put them in? Ech!! break; for(int k=j; k<nElems; k++) // move higher ones down // what if k = nElems? Will this work? arr[k] = arr[k+1]; nElems--; // decrement size // check: either we get a hit or not. Check both! // What is wrong with this little routine? //-------------------------------------------------------------- for(j=0; j<nElems; j++) // display items System.out.print( arr[j] + " "); System.out.println(""); } // end main() } // end class ArrayApp Note: all processing is in one single method, main!

  8. Program Organization • Program looks like a COBOL program or a C program. • All components: data and procedure – are smushed together. • No chance for reuse; extension; information hiding, etc. • Will it work? Yes. But it does NOT take any advantage of OO features. • In general, this is poor programming…

  9. Dividing the Program into Classes •  To build a much better program that is easier to maintain, reuse, and understand, separate the data (array of ints) from its clients (main() ). • Develop a class that contains the dataitself and the methods that access / manipulate that data. • Encapsulation • Information hiding •  Protect the data and control access.

  10. Better Approach: the lowArray.java Program Here is the class (object) with its data declarations and methods for accessing that data. All ‘clients’ may have access to the array, a, via the methods in LowArray objects. Access to objects of type LowArray are NOT tied to a specific implementation! // lowArray.java // demonstrates array class with low-level interface //////////////////////////////////////////////////////////////// class LowArray { private int [ ] a; // ref to array a //note ‘private’ //-------------------------------------------------------------- public LowArray(int size) // constructor// note public methods { a = new int[size]; } // creates array of a size ‘passed’ to it! //-------------------------------------------------------------- public void setElem(int index, int value) // set value { a[index] = value; } // sets a specific element value. //-------------------------------------------------------------- public int getElem(int index) // get value { return a[index]; } // ‘gets’ a specific element and //-------------------------------------------------------------- // returns value to client. } // end class LowArray Note how nicely these work together! What kind of variables are: index, value, and a? What are their visibilities? Note: array is defined HERE. Methods to process the array are HERE. Since ints are primitives, this is sufficient. If the array were of objects, say, State or Country, we would still define the ARRAY itself here! (and the class (that is, the description of each object), State, Country, … would be defined in a separate class. But the array is here!

  11. class LowArrayApp { public static void main(String[] args) { LowArray arr; // reference to an object of type LowArray. arr = new LowArray(100); // create LowArray object and passes 100 as argument for number of elements int nElems = 0; // number of items in array int j; // loop variable arr.setElem(0, 77); arr.setElem(1, 99); arr.setElem(2, 44); arr.setElem(3, 55); arr.setElem(4, 22); // do NOT DO THIS!!! arr.setElem(5, 88); arr.setElem(6, 11); arr.setElem(7, 00); arr.setElem(8, 66); arr.setElem(9, 33); // DONE ONLY FOR SPACE.. nElems = 10; // now 10 items in array // --------------------------------------------------------------------------------------- for(j=0; j<nElems; j++) // display items System.out.print(arr.getElem[j] + " "); System.out.println(""); // --------------------------------------------------------------------------------------- int searchKey = 26; // search for data item for(j=0; j<nElems; j++) // for each element, if(arr.getElem[j] == searchKey) // found item? break; if(j == nElems) // nope System.out.println("Can't find " + searchKey); else // yes System.out.println("Found " + searchKey); // ---------------------------------------------------------------------------------------- for(j=0; j<nElems; j++) // delete value 55 if(arr.getElem[j] == 55) break; for(int k=j; k<nElems; k++) // move ‘higher’ ones down arr.setElem(k, arr.getElem(k+1) ); nElems--; // decrement size // ---------------------------------------------------------------------------------------- for(j=0; j<nElems; j++) // display items System.out.print( arr.getElem(j) + " "); System.out.println(""); } // end main() } // end class LowArrayApp

  12. Evaluation? • What do you think? • Advantages? • Other than separating data from user, not too much! • Data separated from user (clients) Good. • Data is private and only LowArray class methods have access to the data. Good. • Requires other clients (users) to use objects. Good. • Classes have clearly defined roles. Good • LowArray class is called a Container Class • Container Classes store data and provide methods to accessing and manipulating elements in it. • Note: all work done on the data done by the object that contains the data (mostly) • Still, not so hot!! Only methods were get() and set()…

  13. Discussion: pg. 1 of 2 (We’ve already talked about these, but…) • Classes have … ‘responsibilities;’ objects of a class provide services’ (i.e, they ‘do’ things! • What does this mean? • Classes (really, ‘objects’ of a class) may have many / varied users who wish different services provided to them. • Compute gpa; print name and SSAN, etc. • If the class is a high-usage class, it should be designed to provide flexibility for its clients. •  Services (the methods) are ‘provided’ via the class interface: the methods and their ‘signatures.’ • The ‘whats’ are provided and ‘how’ to get them. • To provide for reusability, we put the data and the methods together in the same object wherever practical.

  14. Discussion: pg 2 of 2. • Consider LowArray class. • Its ‘public interface’ (i.e., the signatures of its public methods) are among the most basic of services • ‘Creating’ ‘getting’ ‘setting’ are very primitive services…. • Chances are users of this data will still have to do most of the manipulation themselves in this scenario! • Which means other methods might be in … main() • Not much real valuable ‘service’ provided. •  Separating data from its users is a step forward. But we can do much better! • Consider the highArray.java program. (next slides) • First: look at the Container class, HighArray • Secondly, look at the app(lication) that uses the services of objects of type HighArrayApp

  15. class HighArray { // have taken some spacing liberties to fit this on one page… private int[] a; // ref to array a private int nElems; // number of data items public HighArray(int max) // constructor { a = new int [max]; // create the array nElems = 0; // no items yet } // end Constructor- public boolean find (int searchKey) { // find specified value int j; for (j=0; j<nElems; j++) // for each element, // /note that the class provides the search capability! Nice ‘service.’ if (a[j] == searchKey) // found item? // Client does not have to be concerned over ‘how’ the search isundertaken! break; // exit loop before end // Search was done in the app last time and NOT in the object….. This is MUCH better. if(j == nElems) // gone to end? return false; // yes, can't find it else return true; // no, found it } // end find() //----------------------------------------------------------- public void insert(int value) // put element into array { //note the services provided by the object a[nElems] = value; // insert it // note the public interface. nElems++; // increment size // Note that the object controls all indexing, looping, etc!! }// end insert() //----------------------------------------------------------- public boolean delete(int value) { // Again, note the service: delete is accommodated within object! int j; // Client just requests a simple ‘delete’ service! for(j=0; j<nElems; j++) // look for it if( value == a[j] ) // Client really doesn’t care about ‘how’ the delete is done. break; // only that it IS done. if(j==nElems) // can't find it return false; else // found it { for(int k=j; k<nElems; k++) // move higher ones down a[k] = a[k+1]; nElems--; // decrement size return true; }// end else } // end delete() //----------------------------------------------------------- public void display() // displays array contents { for(int j=0; j<nElems; j++) // for each element, System.out.print(a[j] + " "); // display it System.out.println(""); }// end display() } // end class HighArray

  16. Infinitely better!!! Let the object do the work for client! class HighArrayApp  Here’s the Application! { public static void main(String[] args) { int maxSize = 100; // array size HighArray arr; // creates a reference to object arr (to be created) of class HighArray. arr = new HighArray(maxSize); // creates object arr and passes 100 to its constructor. arr.insert(77); // insert 10 items Note: we only supply value not arr.insert(99); // it’s the job of the object to insert the element into the array. arr.insert(44); // We have sent a message to arr to provide this service to us. arr.insert(55); arr.insert(22); Note: we don’t handle indices arr.insert(88); Note: we don’t loop arr.insert(11); Note: we don’t controlthe type of search!!!! arr.insert(00); arr.insert(66); arr.insert(33); arr.display(); // displayitemsWe simply request the object to provide those services!! (assuming it can via its public interface that is,assumingit is well-designed for its clients). int searchKey = 35; // search for item if( arr.find(searchKey) ) System.out.println("Found " + searchKey); else Still more: give parameter and request Search! No more! System.out.println("Can't find " + searchKey); We are ‘abstracting out’ the details of these operations!! Let the object that has responsibility for the data arr.delete(00); // delete 3 itemsdo the searching, manipulating, etc. arr.delete(55); Let client (HighArrayApp) merely request this service! arr.delete(99); arr.display(); // display items again } // end main() } // end class HighArrayApp // Note how short main (driver) really is. It drives the app.

  17. Program 1 and Good Program Design • So, what do you think your design (architectural design realized in UML) might appear as for program 1?? • Hint: three classes: • 1. Main (the driver) here, does I/O, … (will change later) • 2. Entity class (your data class for states/ countries/students, ….) • 3. Your collection class – really the workhorse. All (most) methods to process your entity class are here NOT in the entity class. Will explain. • Promotes reusability and excellent separation of concerns…. Much to talk about!

  18. Incomplete but ‘start’ of UML for Project 1 Ecountry-Collection Array of Ecountry objects Other attributes (several) Methods to build and process the array Search and sort routines Computation routines…… Main <attributes> <methods> Create object of type Ecountry-Collection… Read file; pass string to method in Ecountry-Collection to build an Array object. o Ecountry Object properties (attributes) Constructor to create object Getters and setters toString()…

  19. Ordered Arrays

  20. Ordered Arrays • Will use an OrdArray class (ordered array) to encapsulate the array itself (data, the ‘entity’ if you will) and the methods (algorithms) that process that array. • From a design perspective, we want to keep them together for so many good reasons: reusability, cohesion, couping… • Most essential part of this example is, of course, the ‘find’ algorithm, which uses a binary search to find / not-find a specific item. • Let’s look at the binarysearchmethod first.

  21. Searching: Binary Search with the find() Method Let’s look at the find() routine…(from the book plus my comments) public int find (long searchKey) { int lowerBound = 0; int upperBound = nElems-1; // if array size is 50, bounds = 0, 49 int curIn; // ‘curIn’ = current index while (true) { curIn = (lowerBound + upperBound) / 2; //set curIn to middle of range. if (a[curIn] == searchKey) return curIn; // found target, Great! else if (lowerBound > upperBound) return nElems; // can’t find it. End of routine. else // adjust bounds of ‘array.’ { if (a[curIn] < searchKey) lowerBound = curIn+1; // look in upper half else upperBound = curIn – 1; // look in lower half } // end else divide range } // end while } // end find() Scope terminators GO THROUGH THE ALGORITHM. CAN YOU GO THROUGH IT?? Go through – try the ‘hit’ being at position 57 in the array… Note: every algorithm like this will have: 1. a hit; 2. a failure; 3. adjustment for continued searching.

  22. Assumes desired element is in location 57… Range: 0 + 99 = 99 / 2 = 49.5  curIn = 49 (size of array = 100) Hit? No. ‘not found?’ NO. a[curIn] < searchKey? Yes. (if target is in array, it is in upper half) lowerBound = curIn+1; iterate Range: 50 + 99 = 149 / 2 = 74.5  curIn = 74 (size of array = 50) Hit? No. ‘not found?’ No. a[curIn] < searchKey? No. (if present, target is in lower half) upperBound = curIn – 1; 74-1 = 73; iterate Range: 50+73 = 123 / 2 = 63.5  curIn = 63 (size of array is 24) Hit ? No., Not Found? No a[curIn] < searchKey? No (if present, target is in lower half) upperBound = curIn – 1; 63 – 1 = 62; iterate Range: 50 + 62 = 112 / 2 = 56.  curIn = 56. (size of array is 13) Hit? No. Not found? No a[curIn] < searchKey? Yes (if present, target is in upper half) lowerBound = curIn + 1; 56 + 1 = 57 iterate Range: 57 + 62 = 119 / 2 = 59.2  curIn = 59 (size of array is 6) Hit? No. Not Found? No a[curIn] < searchKey? No. (is in lower half) upperBound = curIn – 1  59 – 1 = 58. Range: 57 + 58 = 115 / 2 = 57.5 = 57. (size of array is 2) Hit? Yes. Number of ‘probes’ = 6. Remember this. Number of probes refers to number of ‘compares.’ “Do I have a hit here?” counts as one probe…

  23. More on Ordered Arrays (1 of 2) • Disadvantages: • Insert() – horribly long for an ordered array. • If new item to be inserted belongs in a lower position of array, movement of data items to ‘insert’ in place can be horrific! • Delete() – horribly long in BOTH ordered and unordered because element to be deleted must be: • First: found, (easier, if item is in ordered array) • Then, remaining elements must be moved to cover up the deleted element’s location.

  24. More on Ordered Arrays (2 of 2) • Advantages: • If array is of sufficient sizeAND is ordered, search times are much faster than with linear searches. • Ordered arrays – super when look-ups (that is ‘searches’) are frequent and array is of sufficient size. • But in ordered arrays – adds/deletes are terrible. • But if maintenance (insertions, deletions) is not done a lot, then this may be the best deal!) • Good examples: • Database of company employees and similar applications when adds and deletes are few. (May batch up adds and deletes and run overnight or off-line) • Large Tax tables – relative stable. Inventories, Large / long lists of all kinds that are not updated very frequently.

  25. Sequential Searching • For a sequential search with ‘small n’, search times can be very quick due to computation of index and access…merely add one. • As ‘n’ (size of array) increases, however, (assuming data is ordered) the performance is significant. • Example: • N = 20 • Sequential search: average number of probes: 10 • Binary search: maximum number of probes 5 • 5? How so? 25 = 32 (next integer power of 2 > array size…) • But don’t be misled. We must consider overall performance. • KNOW INTEGER POWERS OF 2 UP TO 212 • There is no free lunch!!! • To search an array using a binary search, the array MUST BE ORDERED! (SORTED) and this may require processing overhead! (sometimes a lot!) But, then again, if array is reasonably stable (contents doesn’t change much), this may be tolerable. • If not sorted, can not undertake a binary search.

  26. Recall:: Linear (sequential) search Binary Search n n Search times for two search algorithms and their ‘cross over’ point

  27. Binary Search Performance • So, what does all this mean? • These are easy to understand and essential to know. • Consider the table size discussion in book: Binary Search Table Size Max Comparisons Needed 10 4 100 7 1000 10 10,000 14 1,000,000,000 30 Please note that given ‘table’ sizes (on the left), the values on the right represent maximum number of probes to find / not-find. (Next integer power of 2 higher than table size.)

  28. Sequential Search performance • Sequential (Linear) Search Average Nbr:Maximum Number Table SizeComparisonsNeeded 10 5 10 100 50 100 1000 500 1000 10,000 5000 10,000 etc. Potentially, every element might need to be looked at! Average number of probes ‘to find’ would be half the size of the structure, such as 5, 50, 500 … assuming elements are equally-likely to be anywhere in the array… Maximum number of probes ‘to find’ is the table size!

  29. To start with: You mustknow ‘some’ integer powers of 2! • 2**0 = 1 • 2**1 = 2 • 2**2 = 4 • 2**3 = 8 • 2**4 = 16 • 2**5 = 32 • 2**6 = 64 • 2**7 = 128 • 2**8 = 256 • 2**9 = 512 • 2**10 = 1024 • 2**11 = 2048 • 2**12 = 4096 • 2**13 = 8192 • 2**14 = 16384 • 2**15 = 32768 • 2**16 = 65536 As unreasonable as this might appear to, perhaps, a few of you, you need to be able to come up with these without a calculator. They are basic!!! Equations log2r = s Is equivalent to: r = 2s which I might write: r = 2**s So, r = 2s  1024 = 2**10 And log21024 = ? log21024 = 10 (2 raised to what power = 1024? 10)

  30. Background Math • Equations log2r = s  r = 2s In text: given the ‘range,’ how many comparisons are needed to complete the search, s? • Equivalently, given an ‘r’ (table or list ‘size’), we want an equation that gives us ‘s,’ that is, what is the maximum number of probes it will take to ‘find’ or ‘not find’ an element in a list. • So, r = 2s may be 1024 = 2**10 So, the inverse of raising something 2 to a power is a logarithm of base 2: namely s = log2(r) • And log21024 = x or 2x = 1024 (Here, x=10) • Can say: 2 raised to what power = 1024? • Unlikely to exactly have 1024 elements in target. So if table were of size 1000, no more than 2**10 (next higher integer power of two) would be required.

  31. Insertions into Ordered / Unordered arrays

  32. Insertions into an Unordered Array is a Constant • This is an easy one. • Unordered array can only be searched sequentially. • Insert algorithm does NOT depend on array size. • Item is merely placed in next available slot. • Same amount of time is always required, regardless of size. • To insert: merely add the element to the end of the array. • Thus, the time is a constant, K. • So, T = K. • K is important and is used as a multiplier to account for the speed of • the processor, and • other hardware features.

  33. Insertions into an Ordered Array = Terrible • Recall, insertions into an ordered array requires that all of the items be ‘moved up’ to provide room for the new entry to maintain the ‘order.’ • Performance isgreatly impacted by • size, and • frequency of insertions / deletions

  34. Searches – Sequential (linear) and Binary

  35. Linear Search: Unordered Array: Proportional to n • Comparisons…. • Sequential search, unordered list, average number of probes = n/2. • Finding the desired element is ‘equally likely’ to be found early or late in the list. • T (time) will on average be n/2; i.e. time is proportional to n/2 or T α n/2. • But we factor in the hardware, that is, the speed of the hardware. • Relationship becomes: T α k * n/2 (time on one machine will not equal time on another…) • As it turns out, both K and 2 do not contribute nearly as much as the size, n. Thus, they are often ignored. • (K is usually quite small and then we take ‘half’ of that, so….) • So, say: T = k*n or simply, T α n; time is proportional to array size

  36. Binary Search: Ordered Array: Proportionalto log2n • For binary search, our formula for search times is t = k*log 2 (n). Time, T, is ‘proportional’ to the log base 2 of n where n = the number of elements in the search space. ‘means’ as n increases, time increases proportionally to base 2 of n (not linearly) K is again a constant related to the hardware and is small (and negligible) So, we say: T α k*log2(n) Or simply T α log2n, or  Time is proportional to log base 2 of n.

  37. Recall:: Linear (sequential) search Binary Search n n Search times for two search algorithms and their ‘cross over’ point

  38. Big O Notation We need a shorthand way to indicate performance differences (efficiency) of algorithms that search, sort, etc. Enter the ‘Big O’ Notation!

  39. Big O Notation • We’d ‘like’ to say things like, • Algorithm A is twice as fast as Algorithm B. • Can’t always say this. • Performance depends on MANY factors and notjust • number of items (n) or hardware or • the initial arrangement of items (order). • Even this is not enough. • Performance is often based on the ‘degree’ of un-sortedness… • Generally, however, the factor mostsignificant in determining overall performance is the size, n.

  40. Bottom Lines – Big O Notation • Big O Notation is read “Order of” is used to indicate relative efficiencies. • Linear Search is said to be an O(n) search: • Read, ‘Order n’ search. • Says search time is directlyproportional to the number of elements searched. • Think sequential search of an integer array. • Binary Search is an O (log2 n) search. • Read, “Order log base 2 n” search • Says binary search time is proportional to log base 2 n. • Think: binary search of an ordered array.

  41. Run Times using Big O – Know this Table Algorithm Running Time in Big O Linear Search (is proportional to) O(n) Binary Search “ O(log2 n) Insertion – unordered array “ O(1) (‘immediate’) Insertion – ordered array “ O(n) Deletion – unordered array “ O(n) must ‘find’ and create space! Deletion – ordered array “ O(n) Says that deletions require an amount of time proportional to the array size.

  42. Additional Relationships using Big O Notation Subjective rating of Big O Values: O(1) is excellent; O(log2 n) is very good in many cases; O(n) is fair; O(n**2) is poor. (have not discussed) There are others too! But things are not quite this simple….and ‘poor’ in some cases is excellent in other cases Remember, these are only guidelines at best and indicate (sometimes) relative performance!

  43. Advantages and Disadvantages Unordered Arrays: • A: insertions quick O(1) • D: search times can be quite slow O(n) for big n But if small n?? • D: deletions very slow also (find & compress space) O(n) Ordered Array: (assumes array is sorted) • A: search times very quick (O(log2 n)) (if sufficient size) • D: insertion times: O(n) – equally slow as unordered. • D: deletions: very slow also (find and compress space) O(n) • (quick to find; slow to compress!)

  44. Better Choices in Different Circumstances • O(1) time would be super for many things. • But often not possible… • If not, how about O(log2n)? • Very nice, but no free lunch! (data must be sorted; packed; and algorithm is not trivial.) • Data may naturally exist in a sorted order; perhaps not!

  45. StoringObjects • Primitives: In real world, we normally store many primitives together so we can retrieve them at one time. • Objects: Storing objects is different: • For OO-applications, only the variables (attributes) for an object have separate storage. • The methods are only stored one time. • Look up: serializable

  46. Questions?

More Related