473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Data structure

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...
Aug 2 '09 #1
7 1899
JosAH
11,448 Expert 8TB
@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
Aug 3 '09 #2
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))...
Aug 3 '09 #3
JosAH
11,448 Expert 8TB
@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
Aug 3 '09 #4
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)....
Aug 3 '09 #5
JosAH
11,448 Expert 8TB
@nissanbi
True; without knowing anything about the distribution of the numbers you can't do any better than that.

kind regards,

Jos
Aug 3 '09 #6
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).
Aug 3 '09 #7
JosAH
11,448 Expert 8TB
@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.
Aug 3 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
3
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...
2
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_...
11
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...
5
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....
3
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...
11
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...
3
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. ...
29
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 :
30
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.