BinaryHeap<int,int> heap; for (int i = 1; i <= 10; ++i) { heap.insert(i,i); } for (int i = 1; i <= 5; ++i) { heap.removeMin(); }
BinaryHeap<int,int> heap; for (int i = 10; i > 0; --i) { heap.insert(i,i); }
BinaryHeap<int,int> heap; for (int i = 1; i <= 5; ++i) { heap.insert(i,i); heap.insert(-1*i,-1*i); }
void f(int n) { if (n < 0) { return; } BinaryHeap<int,int> heap; for (int i = 0; i < n; ++i) { heap.insert(i,i); } for (int i = 0; i < n; ++i) { cout << heap.removeMin() << endl; } }
Key | Hash code |
A | 1 |
B | 1 |
C | 1 |
D | 0 |
E | 2 |
int hash(int key, int capacity) { return key % capacity; }Assuming that the hash table does not resize, complete the following code so that the total running time is asymptotically proportional to n^2:
void f(int n) { HashTable<int,string> ht(n); // Creates hash table with capacity n. for (int i = 0; i < n; ++i) { ht.insert(________________, "skittles"); } }