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

for thursday
SMART_READER_LITE
LIVE PREVIEW

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:


slide-1
SLIDE 1

For Thursday

  • Read Weiss, chapter 7, sections 7-10
  • Homework:

– Weiss, chapter 4, exercises 2 and 3. – Do 3 only for 2a

slide-2
SLIDE 2

Programming Assignment 1

  • Any questions?
slide-3
SLIDE 3

Homework

slide-4
SLIDE 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
  • rder of item insertion (as in stacks and queues)
  • Instead, each item has a priority associated with it
slide-5
SLIDE 5

Priority Queue ADT

  • AbstractDataType MaxPriorityQueue {

instances: finite collection of elements; each with a priority

  • perations:

Create() Size() Max() Insert(element) DeleteMax() }

slide-6
SLIDE 6

Uses of a Priority Queue

  • Operating systems
  • Best first search
  • Simulations
  • Others?
slide-7
SLIDE 7

Implementation

  • Unordered linear list

– Insert time – Delete time

  • Ordered linear list

– Insert time – Delete time

slide-8
SLIDE 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
slide-9
SLIDE 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?

slide-10
SLIDE 10

Heap Operations

  • Insert
  • DeleteMin
  • DecreaseKey
  • IncreaseKey
  • Remove
  • BuildHeap
slide-11
SLIDE 11

Sorting

  • Importance of sorting
  • Three basic simple sorts

– bubble (or exchange) – selection – insertion

slide-12
SLIDE 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.
slide-13
SLIDE 13

Selection Sort

  • Basic concept to the find the smallest (or

largest) remaining element and put it in place.

slide-14
SLIDE 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.

slide-15
SLIDE 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?

slide-16
SLIDE 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,

…}

slide-17
SLIDE 17

Performance of Shellsort

slide-18
SLIDE 18

Heapsort

  • What’s the concept?
slide-19
SLIDE 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

slide-20
SLIDE 20

Performance of Heapsort