Lecture11 - Engineering Computation ENG 1D04 Lecture...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Engineering Computation ENG 1D04 Lecture 11:Sorting, searching and recursion Mihai Albu © Copyright 2008 Alan Wassyng & Mihai Albu 1 Sorting s Selection sort 1. Scan the data to find the minimum element. 2. Exchange the minimum element with the first element. 3. Move to the next position. Go back to 1 • Sample implementation in Lecture 4 © Copyright 2008 Alan Wassyng & Mihai Albu 2 Insertion Sort s Sort the first two elements (into a new list?) s For all remaining elements • Insert it into the right position into the new list © Copyright 2008 Alan Wassyng & Mihai Albu 3 8-1 3 5 © Copyright 2008 Alan Wassyng & Mihai Albu 4 8-1 5 3 © Copyright 2008 Alan Wassyng & Mihai Albu 5 8-1 5 3 © Copyright 2008 Alan Wassyng & Mihai Albu 6 8 5 3-1 © Copyright 2008 Alan Wassyng & Mihai Albu 7 8 5 3-1 © Copyright 2008 Alan Wassyng & Mihai Albu 8 8 5 3-1 © Copyright 2008 Alan Wassyng & Mihai Albu 9 8 5 3-1 © Copyright 2008 Alan Wassyng & Mihai Albu 10 Comparing sorts s Simplicity s Efficiency s Amount of memory used s Efficiency = number of comparisons needed © Copyright 2008 Alan Wassyng & Mihai Albu 11 Efficiency s Selection and insertion sort = order n 2 s Other algorithms = n log 2 n © Copyright 2008 Alan Wassyng & Mihai Albu...
View Full Document

This note was uploaded on 04/13/2010 for the course CIVIL 2oi4 taught by Professor Lamiar during the Fall '10 term at McMaster University.

Page1 / 31

Lecture11 - Engineering Computation ENG 1D04 Lecture...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online