Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computing Concepts Searching and Sorting. What we have done so far in data structures data structure as a way of organising the storage of data brief.

Similar presentations


Presentation on theme: "Computing Concepts Searching and Sorting. What we have done so far in data structures data structure as a way of organising the storage of data brief."— Presentation transcript:

1 Computing Concepts Searching and Sorting

2 What we have done so far in data structures data structure as a way of organising the storage of data brief look at: –records –arrays –sequences (lists, queues, stacks) –trees

3 What we have done so far in data structures Done more on –records –arrays

4 Example What are the contents of the element in the array PlayOffTeams which has index 3 ? What is the value of PlayOffTeams[2] ?

5 Example Describe completely the structure of the array PlayOffTeams.

6 Example The index for the array PlayOffTeams lies in the range 1..4 The elements are of type Name

7 Example Write a fragment of Pascal that would display the third name in the array. WriteLn(PlayOffTeams[3]);

8 Example Write a fragment of Pascal that would display all the names in the array.

9 Example FOR I := 1 TO 4 DO BEGIN WriteLn(PlayOffTeams[I]); END

10 What we shall do today Look at arrays in Pascal (not on assessment) Search arrays Sort (re-order) arrays

11 Pascal Array X[1] gets 2 X[2] gets 4 X[3] gets 6 etc Prog1_BigArray

12 Searching an array Example: –How does hole in the wall find your account from your credit card details ? Need to search through the array of bank records

13 Different kinds of search available Linear Search Binary search

14 Linear Search Searching for a birthday day of the month Searching for bank records –1,000 bank records –Fastest find in - 1 comparison –Slowest find in - 1,000 comparisons –Average find in 500 comparisons

15 Binary Search How can we speed up the process ? Binary search for a number in range 1 to 1000 Searching for a birthday day of the month

16 Sorting We need to sort to –be able to use the fast binary search –produce reports in required order

17 Sorting Many different ways of carrying out a sort on an array. We shall examine EXCHANGE SORT (Also known as the BUBBLE SORT) We shall look at others

18 Exchange Sort Simple Slow Demo with heights Demo with birthday day of the month

19 Pascal Exchange Sort Prog3_LittleSort –10,000 elements –20,000 elements –40,000 elements

20 Sorting Demos http://www.cs.ubc.ca/spider/harrison/Java/sorting-demo.html http://www.cs.hope.edu/~alganim/animator/Animator.html


Download ppt "Computing Concepts Searching and Sorting. What we have done so far in data structures data structure as a way of organising the storage of data brief."

Similar presentations


Ads by Google