Advanced Data Structure
Fenwick Tree
Fenwick tree is also called Binary Indexed Tree. This kind of data structure can do the calculation of sum from 0 to ith of a list very efficiently.
It can also be used to calculate the frequency
. Below is a code used to calculate the number of values from 0 to i.
1 | class fenwickTree: |
Relevant application is in Leetcode No.315.
Heap
Heap is a useful data structure which can store the elements in order. In Python, there is a built in heap library called Heapq.
No.253 - Meeting Room
- Make the start time of meeting in order
- Use heap to store the end time of each meeting
- When the meeting with earliest end time is smaller than the coming meeting with earliest start time, pop that meeting, otherwise not. Then heappush the new end time of the new coming meeting.