Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #15  
Old 11-20-2007, 11:46 AM
Kristi Kristi is offline
Bowie's Deciple
Kristi's Avatar
Join Date: Dec 2003
Location: Boston, MA
Posts: 748
Kristi has a spectacular aura aboutKristi has a spectacular aura about
Send a message via AIM to Kristi Send a message via MSN to Kristi
Quote:
Originally Posted by Tolnaftate2004 View Post
PHP Code:
function S3(arrA,arrB) {
  
temp.intersect.clear();
  
temp.sets.clear();
  if (
arrA.size() > arrB.size()) temp.= {arrB,arrA};
  else                           
temp.= {arrA,arrB};

  for (
elmttemp.c[0]) {
    if (
elmt in temp.c[0])
      
temp.intersect.add(elmt);
  }

  
temp.len temp.intersect.size();
  for (
temp.i=0temp.i<temp.len-2temp.i++) {
    for (
temp.j=temp.i+1temp.j<temp.len-1temp.j++) {
      for (
temp.k=temp.j+1temp.ktemp.lentemp.k++) {
        
temp.sets.add({temp.intersect[temp.i],temp.intersect[temp.j],temp.intersect[temp.k]});
      }
    }
  }
  return 
temp.sets;

This has O(N+N!/((N-3)!*3!)), N ≤ min{a.size(),b.size()}.
^_^ this is an open discussion. Please explain why this is better then the naive algorithm
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.
__________________

Last edited by Kristi; 11-20-2007 at 12:00 PM..
Reply With Quote
 

Tags
programming-exercise


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:19 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.