2Array Most commonly used data structure Ordered array, in which the data is stored in ascending (or descending) key order. This arrangement makes possible a fast way of searching for a data item: the binary search.
3ExampleAttendance monitoring program for cricket team --- using Array.Insert player at arrivalSearch playerDelete player after departureImagine that each player has been issued a team shirt with the player’s number on the back.To make things visually interesting, the shirts come in a variety of colors --- number and color stored in arrayCreate an applet viewer for it --- insert player and randomly choose color NO DUPLICATION
4Insertion / SearchingEach button press in a Workshop applet corresponds to a step that an algorithm carries out. The more steps required, the longer the algorithm takes.Insertion taking One step because no empty cell in array ---- sequence (assume not doing dup)Searching will take more stepsAverage is half of steps like N/2Worst case scenario is NThe time an algorithm takes to execute is proportional to the number of steps, so searching takes much longer on the average (N/2 steps) than insertion (one step).
5Deletion 2 step procedure Search required item + Clear cellFill holes/empty cellA deletion requires (assuming no duplicates are allowed) searching through an average of N/2 elements and then moving the remaining elements (an average of N/2 moves) to fill up the resulting hole. This is N steps in all.
6Duplicate Issues Primary key cannot duplicate Human error chance so check all data items before insertion.Searching with duplicatesN moves required (whole array search)Insertion with duplicatesN moves to search duplicates1 step insertionDeletion with duplicatesN moves to search and N/2 moves to shift cellsAverage will be based on how many duplicates
7Average moves for 3 operations Create program for this exampleManage it with classes so that class can be used for some other purpose. E.g separate array insertion separately. Like store serial # of travelers chequeApply abstraction
8Ordered ArrayUseful when more searchingLinear SearchBinary Search