Heaps

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/5

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:40 PM on 4/3/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

6 Terms

1
New cards

Why are priority queues helpful?

Different people get priority in certain cases:

  • scheduling

  • boarding a place

  • emergency room

2
New cards

Interface

  • public void enqueue( E element ) adds the element to this queue

  • public E dequeue() removes and returns the element with highest priority

  • public E front() returns (but does not remove) the element with the highest priority

3
New cards

Represented by T

  • Either T has a natural ordering (e.g., it implements Comparable<T> in Java)

  • Or T has a field K (called key) that represents the priority (e.g., an Integer)

  • or a Comparator<T> is provided to the constructor of the priority queue.

4
New cards

Priorities as methods

enqueue(element, priority)

  • highest priority represented by highest/smaller number

  • names of methods differ

    • public void add (E element)

5
New cards

Priority Queue Interface: Comapreator <T>

public interface PriorityQueue<T> {

void add(T item);

T peek();

T remove();

boolean isEmpty();

int size();

}

6
New cards

Priority Queue Interface: priorities explictely provided as part of method calls

public interface PriorityQueue<K extends Comparable<? super K>, V> {

interface Entry<K, V> {

K getKey();

V getValue();

}

int size();

boolean isEmpty();

Entry<K, V> insert(K key, V value);

Entry<K, V> min();

Entry<K, V> removeMin();

Explore top notes

note
Lecture 13A: Paleozoic Life
Updated 236d ago
0.0(0)
note
Gravitation and Circular Motion
Updated 1083d ago
0.0(0)
note
Chapter 11: Stockholders' Equity
Updated 812d ago
0.0(0)
note
chapter 4: a&p (tissues)
Updated 661d ago
0.0(0)
note
APES Unit 2 - Biodiversity
Updated 546d ago
0.0(0)
note
Lecture 13A: Paleozoic Life
Updated 236d ago
0.0(0)
note
Gravitation and Circular Motion
Updated 1083d ago
0.0(0)
note
Chapter 11: Stockholders' Equity
Updated 812d ago
0.0(0)
note
chapter 4: a&p (tissues)
Updated 661d ago
0.0(0)
note
APES Unit 2 - Biodiversity
Updated 546d ago
0.0(0)

Explore top flashcards

flashcards
global Quiz
39
Updated 1053d ago
0.0(0)
flashcards
ap psych unit 7
73
Updated 1143d ago
0.0(0)
flashcards
Westward Expansion
29
Updated 1139d ago
0.0(0)
flashcards
latin vocab 1-30
28
Updated 754d ago
0.0(0)
flashcards
Chem Ch.4 Element Info
30
Updated 1283d ago
0.0(0)
flashcards
global Quiz
39
Updated 1053d ago
0.0(0)
flashcards
ap psych unit 7
73
Updated 1143d ago
0.0(0)
flashcards
Westward Expansion
29
Updated 1139d ago
0.0(0)
flashcards
latin vocab 1-30
28
Updated 754d ago
0.0(0)
flashcards
Chem Ch.4 Element Info
30
Updated 1283d ago
0.0(0)