User:Realazthat/Notes/Algorithms/Set-intersection: Difference between revisions

From Rosetta Code
Content added Content deleted
(Created page with "== Intersection Not Empty == <pre> #Intersection Not Empty INE(A,B): if |A| > |B| return true for ( a in A ) if ( a not in B ) return true return fals...")
 
No edit summary
Line 1: Line 1:
== Intersection Not Empty ==
== Set Difference Not Empty ==




<pre>
<pre>
#Intersection Not Empty
#Set Difference Not Empty
INE(A,B):
DNE(A,B):
if |A| > |B|
if |A| > |B|
return true
return true
Line 18: Line 18:
<pre>
<pre>
#Intersection Not Empty
#Intersection Not Empty
INE(A,B):
DNE(A,B):
if |A| > |B|
if |A| > |B|
return true
return true

Revision as of 17:33, 6 January 2011

Set Difference Not Empty

#Set Difference Not Empty
DNE(A,B):
  if |A| > |B|
    return true
  
  for ( a in A )
    if ( a not in B )
      return true
  
  return false

#Intersection Not Empty
DNE(A,B):
  if |A| > |B|
    return true
  
  for ( b in B )
    remove b from A
    remove b from B
    if |A| > |B|
      return true
  
  return false