-1

explanation of this algorithm

function equivalence(m,n)
//n variables,m equivalence relations
//bit is a boolean array
//seq is an array of pointers each one is pointing to the list of elements called equivalence elements
for i = i to n do seq(i)<-bit(i)<-0;
for k=1 to m do
[read-next pair(i,j)
getnode(x);
data(x)<-j;
link(x)<-seq(i);
seq(i)<-x;
getnode(x);
data(x)<-i;
link(x)<-seq(j);
seq(j)<-x;
]
index<-1
repeat
if bit(index)=0 then
[
print ("new equivalence class",index)
bit(index)<- 1;
ptr<-seq(index);
top<- 0
loop
while ptr(!= 0)
do
[j<-data(ptr)
if bit(j)= 0 then
[print(j);
bit(j)<-1
t<-link(ptr)
link(ptr)<- top
top<-ptr
ptr<-t;]
else
ptr<-link(ptr)
]//end while
ptr<-seq(data(top))
top<-link(top)
forever]
if bit(index)=0
index<-index + 1;
until index>w
end
Votes + Comments
Don't dump homework without own effort!
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Taywin
0

It is your homework. Who would know better than you do about what you are talking about this somewhat pseudo code?

Also, there are many unknown variables in the code...
1)Is "seq" a global variable? Because it just pops up in the function without declaration.
2)Where does "x" come from? All the sudden it is being used in getnode(x);
3)You need to explain the implication of value "0" in the code. It seems to represent both "false" and "null" values?
4)What is data?
5)What is link?
6)What does getnode() do?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.