Lecture12

# Lecture12 - Algorithms in Systems Engineering ISE 172...

• 26

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

Algorithms in Systems Engineering ISE 172 Lecture 12 Dr. Ted Ralphs

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

ISE 172 Lecture 12 1 References for Today’s Lecture Required reading Chapter 6 References CLRS Chapter 7 D.E. Knuth, The Art of Computer Programming, Volume 3: Sorting and Searching (Third Edition), 1998. R. Sedgewick, Algorithms in C++ (Third Edition), 1998.
ISE 172 Lecture 12 2 Optimal Algorithms In Lecture 7, we saw merge sort . Merge sort is asymptotically optimal and stable . However, it cannot be performed in place . Later in this lecture, we’ll introduce a more sophisticated recursive algorithm called quick sort , which is based on partitioning. Quick sort is also Θ( n 2 ) in the worst case, but is Θ( n lg n ) on average. However, it is unstable and can result in a large call stack and poor performance in common special cases if not implemented carefully. Another alternative, which is optimal and stable is heap sort , which sorts using a priority queue data structure.

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

ISE 172 Lecture 12 3 Priority Queues and Sorting To understand heap sort, we must introduce a new data structure called a priority queue . A priority queue is a data structure for maintaining a list of items that have associated priorities . It is like a queue, but items might have their priorities changed so we need to be able to shuffle items around efficiently. The usual operations are * construct a queue from a list of items. * find the item with the highest priority. * insert an item. * delete an item. * change the priority of an item. Note that any implementation of a priority queue can be used to sort a list of items. Put the items in a priority queue. Delete the maximum item n times.
ISE 172 Lecture 12 4 Heap Sort We will see later an implementation of priority queues for which each of the major operations has a running time of O (log n ) . This immediately yields an algorithm that runs in O ( n log n ) . Neverthless, we will see it is not very competitive in practice.

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

ISE 172 Lecture 12 5 Quicksort We now discuss a sorting algorithm called quicksort that is a recursive algorithm like mergesort.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern