Computing Concepts - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Computing Concepts

Description:

Write a fragment of Pascal that would display the third name in the array. ... Binary search for a number in range 1 to 1000. Searching for a birthday day of the month ... – PowerPoint PPT presentation

Number of Views:16
Avg rating:3.0/5.0
Slides: 21
Provided by: BrianFa8
Category:
Tags: birthday | card | computing | concepts | in | to | what | write

less

Transcript and Presenter's Notes

Title: Computing Concepts


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 PlayOffTeams2 ?

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(PlayOffTeams3)

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(PlayOffTeamsI)
  • END

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

11
Pascal Array
  • X1 gets 2
  • X2 gets 4
  • X3 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
Write a Comment
User Comments (0)
About PowerShow.com