473,698 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

joining two maps



Is there a way to union two maps into one map in O(log n) time?

Jul 23 '05 #1
5 1603
John wrote:

Is there a way to union two maps into one map in O(log n) time?


No. The best you can do is O(N) time.

Consider this. If you had a map with all the odd integers from 1 to 127
and another map with all the even integers between 2 and 128 and assume
this takes 7k operations, can you come up with an algoritm that would do
1-255 and 2-256 in 8k operations (where k is some constant) ?

I can easily do it in 14k operations !
Jul 23 '05 #2


stupid me. I was thinking if the sets were disjoint (non-overlapping).
You are absolutely right.

Here is a better formulation of my question, I have two maps M1,M2.
I would like to do the set_union type operation on it. I can of course
make a set and put the data inside it using pair. Any other ideas
on how to do this more naturally? can maps be unioned?

Jul 23 '05 #3
"John" <we**********@y ahoo.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Here is a better formulation of my question, I have two maps M1,M2.
I would like to do the set_union type operation on it. I can of course
make a set and put the data inside it using pair. Any other ideas
on how to do this more naturally? can maps be unioned?


I think the way to union two maps is:
M1.insert( M2.begin(), M2.end() );

But I haven't checked the performance specifications for this...

Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Jul 23 '05 #4


should take O(n log_2 m) where n is the smaller of M_1, M_2 and
m is the bigger one. Thanks, at least I got something to lookup.

Jul 23 '05 #5

"John" <we**********@y ahoo.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .


stupid me. I was thinking if the sets were disjoint (non-overlapping).
You are absolutely right.

Here is a better formulation of my question, I have two maps M1,M2.
I would like to do the set_union type operation on it. I can of course
make a set and put the data inside it using pair. Any other ideas
on how to do this more naturally? can maps be unioned?


If you want the union to a separate set from M1 and M2, you can do the
following:

map<key, value, comp> M1plus2;
set_union(M1.be gin(), M1.end(), M2.begin(), M2.end(), inserter(M1plus 2,
M1plus2.end()), M1plus2.value_c omp());

This finishes in O(M1.size() + M2.size()), because it always inserts new
elements at the end of the output map.

Joe Gottman
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2059
by: Jeff Sandys | last post by:
I'm trying to write a mapping function for genealogy. I want to read a gedcom database and plot an icon at a geographic location based on a user's query. Can you help me find: 1) A python interface to gedcom? (gedcom is a well documented linear file so I can probably do this myself if an interface is not available)
4
2210
by: Stanimir Stamenkov | last post by:
I have this kind of construct: http://www.geocities.com/stanio/temp/usemap01.html (an IMG element using MAP described with AREA elements) I'm trying to make it more accessible and currently I'm testing in Lynx. Lynx plays it clever and when I "enter" the map it shows only 3 links no matter there are 5 AREAs (3 point to a same reference). I don't like Lynx displays the 'alt' text and not the link titles
2
1461
by: Old Monk | last post by:
Hi all, Say I have two maps m1 and m2. Both have key as std::string and value as long. m1 could hold entries like "abc" 123 "def" 456 m2 could have entries like
43
4987
by: Steven T. Hatton | last post by:
Now that I have a better grasp of the scope and capabilities of the C++ Standard Library, I understand that products such as Qt actually provide much of the same functionality through their own libraries. I'm not sure if that's a good thing or not. AFAIK, most of Qt is compatable with the Standard Library. That is, QLT can interoperate with STL, and you can convert back and forth between std::string and Qt::QString, etc. Are there any...
3
61075
by: Sean | last post by:
Have you ever wanted to add the great features inherent in Google Maps? Here is how you do it. ============== == STEP ONE == ============== Create a new MS Access form called frmGoogleMap. Size the form to your liking...
0
1404
by: Philadelphia XML User Group | last post by:
NEXT MEETING: March 8th, 6:00 to 8:00 pm A Definitive Introduction to Topic Maps with Michel Biezunski and Roger Sperberg To sign up, please visit http://www.xmlphilly.org/signup.asp There's been lots of buzz about Topic Maps in the XML community, and
6
2985
by: Sam Carleton | last post by:
Ok, over the years I have read about doing web programing and I have done some real basic stuff. Now I am digging into some real ASP.Net 2.0 and am totally lost some things. I have a master page setup and that is working great. On my contact page I would like to use Google Maps API Version 2 to show a map to my location. Below is the first Google example. I would like to add this to my aspx page that is using the master page. I...
2
1767
by: rn5arn5a | last post by:
I am not sure where I should have posted this question in this newsgroup. Please excuse me if I am wrong. Nowadays, a lot of websites have come with Maps (Google Maps being an example). Can someone please tell me whether these maps are created by using graphic/imaging softwares (like Adobe PhotoShop)? Actually one of my clients who is into real estate wants such maps incorporated in his website & asked me whether such maps can be...
3
4433
by: Phil Stanton | last post by:
I have a button on a form which when pressed displays a google map of the address. Code is Private Sub Googlemap_Click() MakeURL ("") End Sub
0
8678
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9166
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8899
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7737
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.