Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. clear;
  2. clc;
  3. count=1;
  4. for n=5:5:100
  5. for powtorzenie=1:1:30
  6.  
  7. G=graf_pelny(n);
  8. tio;
  9.  
  10. Wierz=sortrows(G,1);
  11. wag=0;
  12. wez(1:n)=[1:n];
  13. licznik1=0;
  14. licznik2=0;
  15.  
  16. while licznik2<n-1
  17. licznik1=licznik1+1;
  18. x=Wierz(licznik1,3);
  19. y=Wierz(licznik1,2);
  20. k=wez(x);
  21. l=wez(y);
  22.  
  23. if k~=l;
  24. licznik2=licznik2+1;
  25. end1(licznik2)=x;
  26. end2(licznik2)=y;
  27. wag=wag+Wierz(licznik1,1);
  28.  
  29. if k<l
  30. wez(y)=k;
  31. b=find(wez==l);
  32. wez(1,b)=k;
  33. else
  34. wez(x)=l;
  35. b=find(wez==k);
  36. wez(1,b)=l;
  37. end
  38. end
  39. end
  40. czas30powt[powtorzenie]=toc;
  41. end;
  42. czas_powtorzen(count)=sum(czas30powt)/30;
  43.  
  44. count=count+1;
  45. end;
  46.  
  47.  
  48. A=czas_powtorzen(1);
  49. poprawka=A/25;
  50.  
  51. n=[5:5:100];
  52. x=[5:5:100];
  53. plot(n, czas_powtorzen)
  54. hold on
  55. plot(x,x.^2.'poprawka,'k')
  56.  
  57. fprintf('Pary wierzcholkow MST:')
  58. for i=1:n-1
  59. fprintf('{%g.%g}',end1(i),end2(i))
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement