Click here to Skip to main content
15,887,280 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi


I'm Beginner at MATLAB and i need to use this algorithm that implements the CRCW PRAM parallel quicksort in my project.
The binary tree construction procedure for the CRCW PRAM parallel quicksort formulation.
1. procedure BUILD TREE (A[1...n])
2. begin
3. for each process i do
4. begin
5. root := i;
6. parenti := root;
7. leftchild[i] := rightchild[i] := n + 1;
8. end for
9. repeat for each process i r oot do
10. begin
11. if (A[i] < A[parenti]) or
(A[i]= A[parenti] and i <parenti) then
12. begin
13. leftchild[parenti] :=i ;
14. if i = leftchild[parenti] then exit
15. else parenti := leftchild[parenti];
16. end for
17. else
18. begin
19. rightchild[parenti] :=i;
20. if i = rightchild[parenti] then exit
21. else parenti := rightchild[parenti];
22. end else
23. end repeat
24. end BUILD_TREE
After building the binary tree, the algorithm determines the position of each element in the sorted array. It traverses the tree and keeps a count of the number of elements in the left and right subtrees of any element. Finally, each element is placed in its proper position in time Q(1), and the array is sorted.

I'll be grateful if any one can help with this.
thanks


i used this code to build the tree

SQL
for r = 1:length(x)
      root = r;
      parent=root;
      lchild(r)=length(x)+1;
      rchild(r)=length(x)+1;
end
 i=1;
 while  i ~= root
     if (x(i)< x(parent)) || (x(i)==x(parent) && (i < parent))
     lchild(parent)= x(i);
     if x(i) == lchild(parent)
         break
     else
         parent = lchild(parent);
     end
     else
         rchild(parent)= x(i);
         if x(i) == rchild(parent)
             break
         else
             parent  = rchild(parent);
         end
     end
     i=+1;
 end



but it did not give the desired answer
any one can find what's wrong of the above implementation of the algorithm
thanks
Posted
Updated 8-Apr-10 10:47am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900