Upload
rheigh-henley-calderon
View
7
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
Data Structures *Property of STIPage 1 of 49
Data Structures and Algorithms
@ There are instances when you do not know theelement number, but you do know the value of theelement. In this case a search must be made onthe array to find the correct element. The easiestway to search an array is called a sequential search.
SequentialSearch
Data Structures *Property of STIPage 2 of 49
Data Structures and Algorithms
Binary Search
Data Structures *Property of STIPage 3 of 49
Data Structures and Algorithms
Example of a Binary Search
Binary Search
5
7
9
12
15
20
25
28
33
35
40
44
47
A
1
2
3
4
5
6
7
8
9
10
11
12
13
Order of comparisons to find the elementnumber of 44:
1. Element 7 (UB = 13, LB = 1, ElementNumber = 7)
2. Element 10 (UB = 13, LB = 8, ElementNumber 10)
3. Element 12 (UB = 13, LB = 11,Element Number = 12)
Number 44 is found in three comparisons,compared to 12 with the sequentialsearch.
Data Structures *Property of STIPage 4 of 49
Data Structures and Algorithms
PointerTechnique
Data Structures *Property of STIPage 5 of 49
Data Structures and Algorithms
PointerTechnique
Data Structures *Property of STIPage 6 of 49
Data Structures and Algorithms
PointerTechnique
Data Structures *Property of STIPage 7 of 49
Data Structures and Algorithms
PointerTechnique
The element number of the frequencydistribution array is the number of pointscorrect and the value of the element isthe number of students that received thatgrade. Therefore, the frequencydistribution array F shows that there is 1student who received 1 point, 1 thatreceived 2 points, 2 that received 3 points,1 that received 4 points, 1 that received5 points, 3 that received 6 points, 4 thatreceived 7 points, 5 that received 8 points,6 that received 9 points and 6 thatreceived 10 points.
Data Structures *Property of STIPage 8 of 49
Data Structures and Algorithms
Cross-Tabulation
Data Structures *Property of STIPage 9 of 49
Data Structures and Algorithms
Cross-Tabulation
Data Structures *Property of STIPage 10 of 49
Data Structures and Algorithms
Cross-Tabulation
Data Structures *Property of STIPage 11 of 49
Data Structures and Algorithms
Cross-Tabulation
Data Structures *Property of STIPage 12 of 49
Data Structures and Algorithms
Cross-Tabulation
Data Structures *Property of STIPage 13 of 49
Data Structures and Algorithms
Cross-Tabulation
Data Structures *Property of STIPage 14 of 49
Data Structures and Algorithms
Cross-Tabulation
Data Structures *Property of STIPage 15 of 49
Data Structures and Algorithms
SortingTechniques
Selection Exchange Sort Technique
@ Sorting – is the process of putting data inalphabetical or numeric order using one key fieldor a concatenation of two or more fields. Data aresorted according to the primary key.
Once the data are in order, they can be accessed byvarious means, including the sequential search andthe binary search.
Data Structures *Property of STIPage 16 of 49
Data Structures and Algorithms
The Selection Exchange Sort
SortingTechniques
Data Structures *Property of STIPage 17 of 49
Data Structures and Algorithms
Flowchart and Algorithm for SWAP Module
SortingTechniques
Data Structures *Property of STIPage 18 of 49
Data Structures and Algorithms
SortingTechniques
Example Pass, I = 1
Data Structures *Property of STIPage 19 of 49
Data Structures and Algorithms
SortingTechniques
Bubble Sort
Data Structures *Property of STIPage 20 of 49
Data Structures and Algorithms
SortingTechniques
Flowchart and Algorithm for Bubble Sort
Data Structures *Property of STIPage 21 of 49
Data Structures and Algorithms
Shell Sort
SortingTechniques
Data Structures *Property of STIPage 22 of 49
Data Structures and Algorithms
SortingTechniques
Algorithm and Flowchart for the Shell Sort
Data Structures *Property of STIPage 23 of 49
Data Structures and Algorithms
Stacks
@ A Stack is a list of numbers, such as an array ofnumbers, to which all additions are at one endand all deletions are at the same end. This is alast-in, first-out procedure.
When a value (X) is added to the stack it is calledpushing the stack.
When a value (X) is used from the stack it is calledpopping the stack.
PUSH 3PUSH 4PUSH 7POP XPOP XPUSH 6
Data Structures *Property of STIPage 24 of 49
Data Structures and Algorithms
Stacks
Example of a Stack That Has Been Pushed andPopped
Data Structures *Property of STIPage 25 of 49
Data Structures and Algorithms
Algorithm and Flowchart to Push and Pop a Stack
Stacks
Data Structures *Property of STIPage 26 of 49
Data Structures and Algorithms
Linked List
@ A Linked List is a file in which each record points toits successor, except for the last record, which hasan end-of-list indicator.
@ The method of pointing to the next record is a field,which contains the record number of the next recordin order. This is called the linking field, since thevalue in this field links the records in proper order.
Example of an Initially Created Linked List
Data Structures *Property of STIPage 27 of 49
Data Structures and Algorithms
Linked List
Example of A Linked List After Multiple Adds andDeletions
Data Structures *Property of STIPage 28 of 49
Data Structures and Algorithms
Original File
Linked List
Comment: Notice thatrecords 5 and 9 are recordsthat have been deleted inthe past and are included inthe empty list, even thoughthere are data in the record.The used list skips theserecords.
Data Structures *Property of STIPage 29 of 49
Data Structures and Algorithms
File After The Additions and Deletions
Linked List
Data Structures *Property of STIPage 30 of 49
Data Structures and Algorithms
Add 69
Linked List
Data Structures *Property of STIPage 31 of 49
Data Structures and Algorithms
Linked List
Delete 17
Data Structures *Property of STIPage 32 of 49
Data Structures and Algorithms
Linked List
Delete 44
Data Structures *Property of STIPage 33 of 49
Data Structures and Algorithms
Linked List
Add 37
Data Structures *Property of STIPage 34 of 49
Data Structures and Algorithms
Delete 29
Linked List
Data Structures *Property of STIPage 35 of 49
Data Structures and Algorithms
Add 40
Linked List
Data Structures *Property of STIPage 36 of 49
Data Structures and Algorithms
Linked List
Add 90
Data Structures *Property of STIPage 37 of 49
Data Structures and Algorithms
Linked List
Add 1
Data Structures *Property of STIPage 38 of 49
Data Structures and Algorithms
Linked List
Add 16
Data Structures *Property of STIPage 39 of 49
Data Structures and Algorithms
Linked List
Algorithm and Flowchart to Create a Linked List
Data Structures *Property of STIPage 40 of 49
Data Structures and Algorithms
Linked List
Algorithm and Flowchart for Processing andUpdating a Linked List
Data Structures *Property of STIPage 41 of 49
Data Structures and Algorithms
Linked List
Data Structures *Property of STIPage 42 of 49
Data Structures and Algorithms
Linked List
Data Structures *Property of STIPage 43 of 49
Data Structures and Algorithms
Linked List
Data Structures *Property of STIPage 44 of 49
Data Structures and Algorithms
Linked List
Data Structures *Property of STIPage 45 of 49
Data Structures and Algorithms
Linked List
Data Structures *Property of STIPage 46 of 49
Data Structures and Algorithms
Linked List
Data Structures *Property of STIPage 47 of 49
Data Structures and Algorithms
Linked List
Data Structures *Property of STIPage 48 of 49
Data Structures and Algorithms
Linked List
Data Structures *Property of STIPage 49 of 49
Data Structures and Algorithms
Linked List