473,734 Members | 2,764 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 1605
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
2060
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
2215
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
1464
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
5008
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
61091
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
1405
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
2987
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
1769
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
4437
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
8946
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
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9236
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
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
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
6031
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
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.