Lect 3

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Data Structures and Algorithms

Array
Dr.Associate Professor
/Abdualmajed Al-Khulaidi
Array
Matrices: It is a collection of similar items, and
the items can be a numerical or symbolic value,
a mixture thereof, or a group of records.
Array Classifications
one –dimensional array •
matrix •
Sorting
Sorting: It is the arrangement of data in
ascending or descending order depending on a
linear relationship that links the elements of this
data together.
The benefits of the sorting process
-Minimize data traffic and data exchange, as
data exchange takes a great deal of time during
processing.
-Reducing the input and output process.
-Save time while searching for a specific element
of data.
Sorting types
1- Internal sorting methods: They are used when
we can place all the objects that we want to
arrange in the memory. Used with small data.
2-External sort: They are used when we cannot
place the objects that we want to arrange in the
memory. And used with big data.
Selection sort algorithm
1- We are looking for the smallest element in
the matrix .
2- The smallest element is exchanged for the
first element in the matrix. If it is found that the
smallest element in the matrix is in the first
digit, then there is no need to change.
3- Then find the smallest element in the matrix
minus the ordered portion.
Example
30 4 5 90 12 80 3 9
3 | 4 5 90 12 80 30 9
3 4 | 5 90 12 80 30 9
3 4 5 | 90 12 80 30 9
3 4 5 | 9 12 80 30 90
3 4 5 9 | 12 80 30 90
3 4 5 9 12 | 80 30 90
3 4 5 9 12 | 30 80 90
3 4 5 9 12 30 80 90
Quick Sort Algorithm

1- We choose a central element and let it be the


middle of the elements .
2- Look to the left of the pivot element if there is an
element larger than it.
3- Look to the right of the pivot element if a
smaller element is found .
4- The switch is made between them, and if there is
only one party and we do not find the other party,
the exchange is done with the same pivotal element
5- Thus, the process continues until the
arrangement is done
Example
9 7 8 3 2 1
1 7 8 3 2 9
1 7 2 3 8 9
1 2 7 3 8 9
1 2 3 7 8 9

You might also like