for thursday
play

For Thursday Read Weiss, chapter 7, sections 7-10 Homework: Weiss, - PowerPoint PPT Presentation

For Thursday Read Weiss, chapter 7, sections 7-10 Homework: Weiss, chapter 4, exercises 2 and 3. Do 3 only for 2a Programming Assignment 1 Any questions? Homework Priority Queues Same basic operations as a standard queue:


  1. For Thursday • Read Weiss, chapter 7, sections 7-10 • Homework: – Weiss, chapter 4, exercises 2 and 3. – Do 3 only for 2a

  2. Programming Assignment 1 • Any questions?

  3. Homework

  4. Priority Queues • Same basic operations as a standard queue: – insert an item – delete an item – look at first item – check for empty queue • But, order of item removal is not based on the order of item insertion (as in stacks and queues) • Instead, each item has a priority associated with it

  5. Priority Queue ADT • AbstractDataType MaxPriorityQueue { instances : finite collection of elements; each with a priority operations : Create() Size() Max() Insert(element) DeleteMax() }

  6. Uses of a Priority Queue • Operating systems • Best first search • Simulations • Others?

  7. Implementation • Unordered linear list – Insert time – Delete time • Ordered linear list – Insert time – Delete time

  8. Min Tree • A tree (binary or not) • Each child has a value bigger than its parent • Or each parent has a value smaller than any of its children (if any) • So the smallest value in the tree is ? • Maximum trees are simply reversed

  9. Heaps • A minimum binary heap is a min tree that is also a complete binary tree • Usually represented in an array • Height of a complete binary tree in terms of N?

  10. Heap Operations • Insert • DeleteMin • DecreaseKey • IncreaseKey • Remove • BuildHeap

  11. Sorting • Importance of sorting • Three basic simple sorts – bubble (or exchange) – selection – insertion

  12. Bubble Sort • Concept is to bubble the largest to the top (or the smallest to the bottom) • Also called exchange sort. • Naïve vs. improved bubble sort.

  13. Selection Sort • Basic concept to the find the smallest (or largest) remaining element and put it in place.

  14. Insertion Sort • Basic concept: – Conceptually split the list to be sorted into two parts: one that is sorted and one that is not – Repeatedly insert the first element from the unsorted part into the sorted part.

  15. Performance of Sorting • What is the performance? • Each sort would be the best choice (of the simple sorts, at least) in certain situations — what situations? • What’s the space cost of these sorting algorithms?

  16. Shellsort • What’s the concept? • h-sorting • increment sequence • Shell’s sequence {1, 2, 4, 8, …} • Hibbard’s sequence {1, 3, 7, 15, …} • best sequence known { 1, 5, 19, 41, 109, …}

  17. Performance of Shellsort

  18. Heapsort • What’s the concept?

  19. Heapsort • Use max heaps instead of min heaps • Use BuildHeap to turn the array into a heap • Use deleteMax to remove items from the beginning of the array, continually moving them to the end of the tree

  20. Performance of Heapsort

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend