Guest User

Untitled

a guest
Feb 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. //
  2. class HTree
  3. {
  4.  
  5. public static void DrawHTree (int x, int y, int length, int depth) {
  6. if (length == 0) {
  7. return;
  8. }
  9.  
  10. DrawHTree(x, y, length, depth, 0);
  11. }
  12.  
  13. public static void DrawHTree (int x, int y, int length, int depth, int currentDepth) {
  14. if (depth == currentDepth) {
  15. return;
  16. }
  17.  
  18. int halfLength = length / 2; // 1
  19.  
  20. int xLeft = x - halfLength; // -1
  21. int xRight = x + halfLength; // 1
  22. int yTop = y + halfLength; // 1
  23. int yBottom = y - halfLength; // -1
  24.  
  25. DrawLine(xLeft, y, xRight, y); // (-1,0) -> (1,0)
  26. DrawLine(xLeft, yTop, xLeft, yBottom); // (-1,1) -> (-1,-1)
  27. DrawLine(xRight, yTop, xRight, yBottom); // (1, 1) -> (1,-1)
  28.  
  29. int newLength = length / Math.Sqrt(2);
  30. currentDepth++;
  31.  
  32. DrawHTree(xLeft, yTop, newLength, currentDepth); // (-1,1) 1
  33. DrawHTree(xLeft, yBottom, newLength, currentDepth); // (-1,-1) 1
  34. DrawHTree(xRight, yTop, newLength, currentDepth); //
  35. DrawHTree(xRight, yBottom, newLength, currentDepth);
  36. }
  37.  
  38. public static void DrawLine(int x1, int y1, int x2, int y2) {
  39. Console.WriteLine("(" + x1 + "," + y1 + ")");
  40. Console.WriteLine("(" + x2 + "," + y2 + ")");
  41. }
  42.  
  43. // if (depth == givenLength) { // 0, 1, 2
  44. //return;
  45. //}
  46.  
  47. // halfLength = length / 2 => 1
  48. // (x - halfLength, y) (x + halfLength, y)
  49. // (x + halfLength, y + halfLength) (x + halfLength, y - halfLength)
  50. // (x - halfLength, y + halfLength) (x - halfLength, y - halfLength)
  51.  
  52. // drawHTree (x + halfLength, y + halfLength, length/Sqrt(2), depth)
  53.  
  54. // drawHTree (x + halfLength, y - halfLength, length/Sqrt(2), depth)
  55. //drawHTree (x - halfLength, y + halfLength, length/Sqrt(2), depth)
  56. //drawHTree (x - halfLength, y - halfLength, length/Sqrt(2), depth)
  57. static void Main()
  58. {
  59. System.Console.WriteLine("Practice makes Perfect!");
  60. }
  61. }
  62.  
  63. // x, y (0,0) length (2)
  64. // if (depth == givenLength) { // 0, 1, 2
  65. //return;
  66. //}
  67.  
  68. // halfLength = length / 2 => 1
  69. // (x - halfLength, y) (x + halfLength, y)
  70. // (x + halfLength, y + halfLength) (x + halfLength, y - halfLength)
  71. // (x - halfLength, y + halfLength) (x - halfLength, y - halfLength)
  72.  
  73. // drawHTree (x + halfLength, y + halfLength, length/Sqrt(2), depth)
  74. // drawHTree (x + halfLength, y - halfLength, length/Sqrt(2), depth)
  75. //drawHTree (x - halfLength, y + halfLength, length/Sqrt(2), depth)
  76. //drawHTree (x - halfLength, y - halfLength, length/Sqrt(2), depth)
  77. O(4^d) -> 1 + 4 + 4 * 4 + ... + 4^(depth - 1) = 4^depth - 1 /(4- 1)= O(4^depth)
Add Comment
Please, Sign In to add comment