View Single Post
  #23  
Old 11-20-2007, 10:42 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by Kristi View Post
Also, in your big O, did you include the search time for the "in" operator in your intersect portion? I can see a few ways to optimize that.
A good point: O(N1*N2 + N!/((N-3)!*3!))

I had originally intended to do something along these lines:
PHP Code:
  for (elmttemp.c[0]) {
    if (
elmt in temp.c[1])
      
temp.intersect.add(elmt);
  } 
becomes
PHP Code:
  while (temp.c[0].size()) {
    
temp.elmt temp.c[0][0];
    if (
temp.elmt in temp.c[1]) {
      
temp.intersect.add(temp.elmt);
      
temp.c[0].remove(elmt);
      
temp.c[1].remove(elmt);
    } else 
temp.c[0].delete(0);
  } 
Still O(N1*N2), but often less.
It just slipped my mind. Silly me.
Also, first thing should be if (arrA.size() > 2 && arrB.size() > 2)...

As for the naive algorithm, It has O(N2^3*N1!/((N1-3)!*3!)) (?), I think.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/

Last edited by Tolnaftate2004; 11-21-2007 at 03:34 AM..
Reply With Quote