10 data structures

49
Data Structures *Property of STI Page 1 of 49 Data Structures and Algorithms @ There are instances when you do not know the element number, but you do know the value of the element. In this case a search must be made on the array to find the correct element. The easiest way to search an array is called a sequential search. Sequential Search

description

 

Transcript of 10 data structures

Page 1: 10 data structures

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

Page 2: 10 data structures

Data Structures *Property of STIPage 2 of 49

Data Structures and Algorithms

Binary Search

Page 3: 10 data structures

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.

Page 4: 10 data structures

Data Structures *Property of STIPage 4 of 49

Data Structures and Algorithms

PointerTechnique

Page 5: 10 data structures

Data Structures *Property of STIPage 5 of 49

Data Structures and Algorithms

PointerTechnique

Page 6: 10 data structures

Data Structures *Property of STIPage 6 of 49

Data Structures and Algorithms

PointerTechnique

Page 7: 10 data structures

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.

Page 8: 10 data structures

Data Structures *Property of STIPage 8 of 49

Data Structures and Algorithms

Cross-Tabulation

Page 9: 10 data structures

Data Structures *Property of STIPage 9 of 49

Data Structures and Algorithms

Cross-Tabulation

Page 10: 10 data structures

Data Structures *Property of STIPage 10 of 49

Data Structures and Algorithms

Cross-Tabulation

Page 11: 10 data structures

Data Structures *Property of STIPage 11 of 49

Data Structures and Algorithms

Cross-Tabulation

Page 12: 10 data structures

Data Structures *Property of STIPage 12 of 49

Data Structures and Algorithms

Cross-Tabulation

Page 13: 10 data structures

Data Structures *Property of STIPage 13 of 49

Data Structures and Algorithms

Cross-Tabulation

Page 14: 10 data structures

Data Structures *Property of STIPage 14 of 49

Data Structures and Algorithms

Cross-Tabulation

Page 15: 10 data structures

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.

Page 16: 10 data structures

Data Structures *Property of STIPage 16 of 49

Data Structures and Algorithms

The Selection Exchange Sort

SortingTechniques

Page 17: 10 data structures

Data Structures *Property of STIPage 17 of 49

Data Structures and Algorithms

Flowchart and Algorithm for SWAP Module

SortingTechniques

Page 18: 10 data structures

Data Structures *Property of STIPage 18 of 49

Data Structures and Algorithms

SortingTechniques

Example Pass, I = 1

Page 19: 10 data structures

Data Structures *Property of STIPage 19 of 49

Data Structures and Algorithms

SortingTechniques

Bubble Sort

Page 20: 10 data structures

Data Structures *Property of STIPage 20 of 49

Data Structures and Algorithms

SortingTechniques

Flowchart and Algorithm for Bubble Sort

Page 21: 10 data structures

Data Structures *Property of STIPage 21 of 49

Data Structures and Algorithms

Shell Sort

SortingTechniques

Page 22: 10 data structures

Data Structures *Property of STIPage 22 of 49

Data Structures and Algorithms

SortingTechniques

Algorithm and Flowchart for the Shell Sort

Page 23: 10 data structures

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

Page 24: 10 data structures

Data Structures *Property of STIPage 24 of 49

Data Structures and Algorithms

Stacks

Example of a Stack That Has Been Pushed andPopped

Page 25: 10 data structures

Data Structures *Property of STIPage 25 of 49

Data Structures and Algorithms

Algorithm and Flowchart to Push and Pop a Stack

Stacks

Page 26: 10 data structures

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

Page 27: 10 data structures

Data Structures *Property of STIPage 27 of 49

Data Structures and Algorithms

Linked List

Example of A Linked List After Multiple Adds andDeletions

Page 28: 10 data structures

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.

Page 29: 10 data structures

Data Structures *Property of STIPage 29 of 49

Data Structures and Algorithms

File After The Additions and Deletions

Linked List

Page 30: 10 data structures

Data Structures *Property of STIPage 30 of 49

Data Structures and Algorithms

Add 69

Linked List

Page 31: 10 data structures

Data Structures *Property of STIPage 31 of 49

Data Structures and Algorithms

Linked List

Delete 17

Page 32: 10 data structures

Data Structures *Property of STIPage 32 of 49

Data Structures and Algorithms

Linked List

Delete 44

Page 33: 10 data structures

Data Structures *Property of STIPage 33 of 49

Data Structures and Algorithms

Linked List

Add 37

Page 34: 10 data structures

Data Structures *Property of STIPage 34 of 49

Data Structures and Algorithms

Delete 29

Linked List

Page 35: 10 data structures

Data Structures *Property of STIPage 35 of 49

Data Structures and Algorithms

Add 40

Linked List

Page 36: 10 data structures

Data Structures *Property of STIPage 36 of 49

Data Structures and Algorithms

Linked List

Add 90

Page 37: 10 data structures

Data Structures *Property of STIPage 37 of 49

Data Structures and Algorithms

Linked List

Add 1

Page 38: 10 data structures

Data Structures *Property of STIPage 38 of 49

Data Structures and Algorithms

Linked List

Add 16

Page 39: 10 data structures

Data Structures *Property of STIPage 39 of 49

Data Structures and Algorithms

Linked List

Algorithm and Flowchart to Create a Linked List

Page 40: 10 data structures

Data Structures *Property of STIPage 40 of 49

Data Structures and Algorithms

Linked List

Algorithm and Flowchart for Processing andUpdating a Linked List

Page 41: 10 data structures

Data Structures *Property of STIPage 41 of 49

Data Structures and Algorithms

Linked List

Page 42: 10 data structures

Data Structures *Property of STIPage 42 of 49

Data Structures and Algorithms

Linked List

Page 43: 10 data structures

Data Structures *Property of STIPage 43 of 49

Data Structures and Algorithms

Linked List

Page 44: 10 data structures

Data Structures *Property of STIPage 44 of 49

Data Structures and Algorithms

Linked List

Page 45: 10 data structures

Data Structures *Property of STIPage 45 of 49

Data Structures and Algorithms

Linked List

Page 46: 10 data structures

Data Structures *Property of STIPage 46 of 49

Data Structures and Algorithms

Linked List

Page 47: 10 data structures

Data Structures *Property of STIPage 47 of 49

Data Structures and Algorithms

Linked List

Page 48: 10 data structures

Data Structures *Property of STIPage 48 of 49

Data Structures and Algorithms

Linked List

Page 49: 10 data structures

Data Structures *Property of STIPage 49 of 49

Data Structures and Algorithms

Linked List