Hi,
I need to find a data structure that supports insertion, deletion and finding the median of the elements stored at the data structure.
All the operation should run in O(loglogn) amortized time.
Any ideas?
I tried using two heaps so I can find the median in O(1), but I don't thing it's good enough...
7 1899 @nissanbi
Google for Blum, Floyd, Rivest, Pratt and Tarjan; they've come up with an O(n) selection algorithm that finds the median in linear time. Keeping a list ordered takes O(log(n)) steps per element at worst.
kind regards,
Jos
But I don't see it helps here.
If I'm keeping the list sorted, I won't need the select algorithm. The would be found in the middle...
And even then, if each insert/delete operation would take log(n) time, I don't think that the amortized time would be log(log(n))...
@nissanbi
That's what I'm saying: if you keep the list ordered you can find a median in O(1) but you have to spend O(log(n)) per element insertion/deletion.
If you don't keep the list ordered you can find a median in O(n) and you can insert/delete your elements in O(1) and O(n) respectively.
kind regards,
Jos
Lets say,
Insert- O(log(n))
Remove- O(log(n))
Find-Median- O(1)
after m1 insertion, m2 removals and m3 median findings, the amortized time would be:
((m1+m2)logn+m2) / (m1+m2+m3)
and I don't think it is equal to loglog(n)....
@nissanbi
True; without knowing anything about the distribution of the numbers you can't do any better than that.
kind regards,
Jos
I also think it's impossible, but I can't find a way to prove to it's impossible...
I have another median question:
We have an AVL tree with n nodes (numbered from 1 to n).
Each node i contains a weight - wi which is an integer.
Pi is the set of the ancestors of the node i, and w(Pi) is the set of weights of all the nodes in Pi.
I need to find an algorithm which runs in O(nloglogn) time.
The algorithm gets an AVL tree like the one mentioned above and returns an array of size n, where each cell i in the array contains the median of the set W(Pi).
@nissanbi
I scribbled a bit: if you sort your numbers (or keep them sorted on the fly) you need O(n*log(n)) operations (Donald Knuth, "The Art Of Computer Programming", vol III "Searching and Sorting"); you can find the median in O(1) but still it's more than O(log(log(n))); I don't know of any data structure that can do any better.
kind regards,
Jos
ps. I'll think about your other question.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dmb000006 |
last post by:
Hello,
I have a database style data structure, each record has several
fields.
I would like to create a nested data structure that would let me
'query' the data on the value of certain...
|
by: Mike Jones |
last post by:
need help with data structures.Looking for ways to start, sample code,
anything
Program description:
Design and implement a Visual C++ .NET program that inserts values
into a data...
|
by: yee young han |
last post by:
I need a fast data structure and algorithm like below condition.
(1) this data structure contain only 10,000 data entry.
(2) data structure's one entry is like below
typedef struct _DataEntry_...
|
by: theshowmecanuck |
last post by:
As a matter of academic interest only, is there a way to programmatically
list the 'c' data types? I am not looking for detail, just if it is
possible, and what function could be used to...
|
by: Alfonso Morra |
last post by:
Hi,
I am writing a messaging library which will allow me to send a generic
message structure with custom "payloads".
In many cases, a message must store a non-linear data structure (i.e....
|
by: Kiran B. |
last post by:
Hi, I am new to .net. I have two Data Structure Type ... Sturcture A and
Structure B.
Structure A
Public Fname as String
Public LastName as String
Public City as String
Public Zip as String...
|
by: Macca |
last post by:
Hi,
I'm writing an application that will pass a large amount of data between
classes/functions.
In C++ it was more efficient to send a pointer to the object, e.g structure
rather than passing...
|
by: aurora |
last post by:
This is an entry I just added to ASPN. It is a somewhat novel technique I
have employed quite successfully in my code. I repost it here for more
explosure and discussions.
...
|
by: zoltan |
last post by:
Hi,
The scenario is like this :
struct ns_rr {
const u_char* rdata;
};
The rdata field contains some fields such as :
|
by: Charles Law |
last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this
once before, but ...".
Two users are both looking at the same data, from a database. One user
changes the data and...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |