Algorithms_and_Data_Structures_07

Algorithms_and_Data_ - Lecture 7 Computer Science Algorithms and Data Structures Prof Dr Andreas Nchter Research I Room 105 Jacobs University

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

View Full Document Right Arrow Icon
Computer Science Algorithms and Data Structures Prof. Dr. Andreas Nüchter Research I, Room 105 Jacobs University Bremen http://www.nuechti.de [email protected] Lecture 7
Background image of page 1

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

View Full DocumentRight Arrow Icon
Algorithms and Data Structures Dr. Andreas Nüchter September 24, 2009 191 Announcements Oct 15. midterm (here in class)
Background image of page 2
Algorithms and Data Structures Dr. Andreas Nüchter September 24, 2009 192 Last Lecture – Advanced Sorting Methods Merge sort is based on the divide and conquer technique. Idea : Divide the keys which have to be sorted into two halves of equal size ( divide step ): Sort the two halves recursively and exploit in the merging step that the two halves are sorted. The merging step can be performed in linear time ( conquer step ).
Background image of page 3

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

View Full DocumentRight Arrow Icon
Algorithms and Data Structures Dr. Andreas Nüchter September 24, 2009 193 Last Lecture – Merge Sort How to merge two (sorted) arrays? function merge(left,right) var list result while length(left) > 0 and length(right) > 0 if first(left) first(right) append first(left) to result left = rest(left) else append first(right) to result right = rest(right) end while if length(left) > 0 append left to result if length(right) > 0 append right to result return result
Background image of page 4
Algorithms and Data Structures Dr. Andreas Nüchter September 24, 2009 194 Last Lecture – Merge Sort We showed that merge sort is in , i.e., Disadvantages of merge sort: It is not an in situ method It needs extra memory Solved by Heap Sort
Background image of page 5

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

View Full DocumentRight Arrow Icon
Algorithms and Data Structures Dr. Andreas Nüchter September 24, 2009 195 Last Lecture – Heap Sort The run time of is roughly more precisely: Theorem : has linear run time in the number of elements of the heap . Proof : The costs of corresponds to the costs of the sum of the height of the heap.
Background image of page 6
Algorithms and Data Structures Dr. Andreas Nüchter September 24, 2009 196 Last Lecture – Definition of a Heap What’s a heap? …A binary tree The parent as node The left child as node The right child as Heap condition: 100 19 36 17 3 25 1 2 7
Background image of page 7

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

View Full DocumentRight Arrow Icon
Algorithms and Data Structures Dr. Andreas Nüchter September 24, 2009 197 Last Lecture – Heap Sort Two steps Building a heap Retrieving elements in a sorted fashion and restore the heap condition Today: Quick Sort
Background image of page 8
Algorithms and Data Structures Dr. Andreas Nüchter September 24, 2009 198 Side Note: Recurrence Relations Recurrence relations are recursive definitions of mathematical functions or sequences. Example : Example :
Background image of page 9

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

View Full DocumentRight Arrow Icon
Algorithms and Data Structures Dr. Andreas Nüchter September 24, 2009 199 Side Note: Recurrence Relations Solving a recurrence relation : Given a function defined by a recurrence relation, we want to find a " closed form " of the function. In other words, we would like to eliminate recursion from the function definition. The main techniques for us are the iteration method
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/04/2010 for the course CS 320251 taught by Professor Nuechter during the Fall '09 term at Jacobs University Bremen.

Page1 / 41

Algorithms_and_Data_ - Lecture 7 Computer Science Algorithms and Data Structures Prof Dr Andreas Nchter Research I Room 105 Jacobs University

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

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