{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

21. Sorting algorithms on arrays

# 21. Sorting algorithms on arrays - Philadelphia University...

This preview shows pages 1–2. Sign up to view the full content.

Philadelphia University Faculty of Information Technology Department of Applied Computer Science A Course for all Scientific Colleges Module: Computer Skills 2 for Scientific Colleges (710104) Section: 2 Lecturer: Dr. Nadia Y. Yousif Examples on Arrays Sorting an Array There are several sorting algorithms that are used to sort arrays of elements in ascending or descending order. The algorithm presented here is the Insertion sort. Definition: Let a 0 , . .., a n -1 be the sequence to be sorted. At the beginning and after each iteration of the algorithm the sequence consists of two parts: the first part a 0 , . .., a i -1 is already sorted, the second part a i , . .., a n -1 is still unsorted ( i 0, . .., n ). In order to insert element a i into the sorted part, it is compared with a i -1 , a i -2 etc. When an element a j with a j a i is found, a i is inserted behind it. If no such element is found, then a i is inserted at the beginning of the sequence. After inserting element

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 2

21. Sorting algorithms on arrays - Philadelphia University...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online