Introduction to Computing - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Introduction to Computing

Description:

Barney. Wilma. Fred. Dino. Sorting. Compare adjacent items and swap if out of order ... Barney Barney. Dino Dino. Fred Fred. Pebbles Pebbles. Wilma Wilma ... – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 16
Provided by: surajL
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Computing


1
Introduction to Computing
  • Dr. Nadeem A Khan

2
Lecture 10
3
Using Arrays Ordered Arrays
  • Ordered array vs Unordered array
  • E.g
  • Ascending order
  • each element

4
Using Arrays Ordered Arrays
  • Ordered array vs Unordered array
  • Advantage Efficient Searching

5
Using Arrays Ordered Arrays
  • Example
  • Request a name and inform if in the ordered list

6
Using Arrays Ordered Arrays
Dim nom(1 To 5) As String General
Declaration Sub Form_Load Rem Place the names
in the array in ascending order Let nom(1)
AKBAR Let nom(2) ASLAM Let nom(3)
BUSHRA Let nom(4) TONY Let nom(5)
ZAID End Sub
7
Sub Command1_Click Dim n As Integer, name2Find
As String Let name2Find Ucase(Trim(Text1.Text))
Let n0 Do Let nn1 Loop Until (nom(n)
name2Find) Or (n5) If nom(n) name2Find
Then Picture1.Print Found Else Picture1.Pri
nt Not found End If End Sub
8
Using Arrays Ordered Arrays
Average search was half the array dimension
9
Sorting
10
Sorting
  • Sorting Ordering an unordered array like the
    following
  • Pebbles
  • Barney
  • Wilma
  • Fred
  • Dino

11
Bubble Sorting Algorithm
  • Compare adjacent items and swap if out of order
  • In n-1 passes the array of n elements will get
    sorted
  • How will you swap values stored in a pair of
    variables?

12
Bubble Sorting
  • First Pass
  • Pebbles Barney Barney Braney Barney
  • Barney Pebbles Pebbles Pebbles Pebbles
  • Wilma Wilma Wilma Fred Fred
  • Fred Fred Fred Wilma Dino
  • Dino Dino Dino Dino Wilma

13
Bubble Sorting
  • Second Pass
  • Barney Barney Barney Braney
  • Pebbles Pebbles Fred Fred
  • Fred Fred Pebbles Dino
  • Dino Dino Dino Pebbles
  • Wilma Wilma Wilma Wilma

14
Bubble Sorting
  • Third Pass
  • Barney Barney Barney
  • Fred Fred Dino
  • Dino Dino Fred
  • Pebbles Pebbles Pebbles
  • Wilma Wilma Wilma

15
Bubble Sorting
  • Fourth Pass
  • Barney Barney
  • Dino Dino
  • Fred Fred
  • Pebbles Pebbles
  • Wilma Wilma
Write a Comment
User Comments (0)
About PowerShow.com