Download presentation

Presentation is loading. Please wait.

Published byDelaney Billingslea Modified over 2 years ago

1
Data Structures Arrays

2
Array 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.

3
Example Attendance monitoring program for cricket team --- using Array. ◦ Insert player at arrival ◦ Search player ◦ Delete player after departure Imagine 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 array Create an applet viewer for it --- insert player and randomly choose color NO DUPLICATION

4
Insertion / Searching Each 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 steps ◦ Average is half of steps like N/2 ◦ Worst case scenario is N The 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).

5
Deletion 2 step procedure ◦ Search required item + Clear cell ◦ Fill holes/empty cell A 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.

6
Duplicate Issues Primary key cannot duplicate Human error chance so check all data items before insertion. Searching with duplicates ◦ N moves required (whole array search) Insertion with duplicates ◦ N moves to search duplicates ◦ 1 step insertion Deletion with duplicates ◦ N moves to search and N/2 moves to shift cells ◦ Average will be based on how many duplicates

7
Average moves for 3 operations Create program for this example Manage it with classes so that class can be used for some other purpose. E.g separate array insertion separately. Like store serial # of travelers cheque Apply abstraction

8
Ordered Array Useful when more searching ◦ Linear Search ◦ Binary Search

9
Example

10
Logarithms & Equation

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google