A specific data structure

Posted by user550413 on Stack Overflow See other posts from Stack Overflow or by user550413
Published on 2010-12-26T09:57:36Z Indexed on 2010/12/26 18:54 UTC
Read the original article Hit count: 179

Filed under:
|

Well, this question is a bit specific but I think there is some general idea in it that I can't get it.

Lets say I got K servers (which is a constant that I know its size). I have a program that get requests and every request has an id and server id that will handle it. I have n requests - unknown size and can be any number.

I need a data structure to support the next operations within the given complexity:

GetServer - the function gets the request ID and returns the server id that is supposed to handle this request at the current situation and not necessarily the original server (see below).

Complexity: O(log K) at average.

KillServer - the function gets as input a server id that should be removed and another server id that all the requests of the removed server should be passed to.

Complexity: O(1) at the worst case.

--

Place complexity for all the structure is O(K+n)

--

The KillServer function made me think using a Union-Find as I can do the union in O(1) as requested but my problem is the first operation. Why it's LogK? Actually, no matter how I "save" the requests if I want to access to any request (lets say it's an AVL tree) so the complexity will be O(log n) at the worst case and said that I can't assume K>n (and probably K

Tried thinking about it a couple of hours but I can't find any solution. Known structures that can be used are: B+ tree, AVL tree, skip list, hash table, Union-Find, rank tree and of course all the basics like arrays and such.

© Stack Overflow or respective owner

Related posts about data-structures

Related posts about complexity