Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. // This was part of HW #1
  2.  
  3. Implement recursive permutations generator.
  4. Make sure your output matches "out.txt"
  5.  
  6. Note: useful STL trick:
  7. std::vector< std::vector<int> > vv( 10, std::vector<int>(3,0));
  8. create a vector of 10 vectors with 3 zero's:
  9. 0,0,0
  10. 0,0,0
  11. 0,0,0
  12. 0,0,0
  13. 0,0,0
  14. 0,0,0
  15. 0,0,0
  16. 0,0,0
  17. 0,0,0
  18. 0,0,0
  19.  
  20. submit:
  21. perm-recursive.h
  22. perm-recursive.cpp
  23.  
  24. Implement non-recursive subset generator based on bits. You may use "int" to
  25. store bits. This limits your implementation to 32 bits, but as we discussed in
  26. class it's enough for all real-life problems.
  27.  
  28. Submit:
  29. subsets-bits.cpp
  30. subsets-bits.h
  31.  
  32. //Hw#2
  33. Prove correctness of the algorithm:
  34. Fast exponentiation:
  35. AL4(A, M)
  36. 1.   B := A
  37. 2.   E := M
  38. 3.   R := 1
  39. 4.   while (E > 0) {
  40. 5.     if (E is odd) {
  41. 6.       R := R * B
  42. 7.       E := E - 1
  43. 8.     }
  44. 9.     else {
  45. 10.      B := B * B
  46. 11.      E := E / 2
  47. 12.    }
  48. 13.  }
  49. 11.  return R
  50.  
  51. invariant A^M = R_k * ( B_k ^ E_k )
  52. prove that R = A^M.
  53.  
  54.  
  55. // hw#3
  56. Problem 5.
  57. Convert to a homogeneous recurrence and solve using characteristic
  58. equation:
  59. T(n) = 2T(n-1) + 3*2^n
  60. T(0) = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement