Reputation: 147
I'm trying to solve probelm which states: make data structure which supports:
1) Add element with key k
2) Delete element with key k
3) Print kth largest element in data structure
I thought that maxheap should work, but in this case we need to delete first k-1 largest value from heap to get the kth maximum element, so it won't work here.
How I can solve this ?
Upvotes: 3
Views: 405
Reputation: 18148
You can solve this with an order statistic tree, which is a (balanced) binary tree that lets you find the ith smallest (or largest) element in log(n) time with a balanced tree.
Upvotes: 2