arnav251035
BAN USER
- 0of 0 votes
AnswersDesigning a data-structure for following functions
- arnav251035 in India
Insert X : Insert an element X into the set.
Delete X : Delete an element X from the set. It is guaranteed that such X always exist in the data structure.
Mean : Report Mean of the elements present in the data set. It is guaranteed that data structure will not be empty at this query.
Mode : Report Mode of the elements present in the data set. It is guaranteed that data structure will not be empty at this query.
Median : Report Median of the elements present in the data set. It is guaranteed that data structure will not be empty at this query.| Report Duplicate | Flag | PURGE
Data Structures
0 Answers Designing a data-structure
We need to implement a data-structure for following functions
- arnav251035 May 29, 2017
Insert X : Insert an element X into the set.
Delete X : Delete an element X from the set. It is guaranteed that such X always exist in the data structure.
Mean : Report Mean of the elements present in the data set. It is guaranteed that data structure will not be empty at this query.
Mode : Report Mode of the elements present in the data set. It is guaranteed that data structure will not be empty at this query.
Median : Report Median of the elements present in the data set. It is guaranteed that data structure will not be empty at this query
I had created a linked list of the values, and like insertion sort I inserted the elements in the Linked List. Deletion was also the same as deletion in Linked List. Mean I calculated on the run as and when the values came. For mode I traversed the whole linked list to see which element occurs the most. Median was the middle element in the linked list.
I know there is an efficient algorithm to calculate median on the run using two heaps (min and max) but calculating mode was the biggest problem I faced. The number of queries ranged to 10^5 and the time limit was given 3 secs. Had a TLE error| Flag | PURGE