Advertisement
phanindhar1

removeDuplicates

Apr 4th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. 1 2 3 4 6
  2. 2 3 4 5 7
  3. 1 2 3 4 5
  4. 1 2 3 4 5
  5. 2 3 4 5 7
  6.  
  7. Single Pass (O(C))
  8. M(1)={0,2,3}
  9. M(2)={1,4}
  10.  
  11. Single Pass with in rows of M(1) O(M(1)) only considering rows in M(1) (a) indicates a is common in those rows
  12.  
  13. (1) 2 3 4 6
  14. (1) 2 3 4 5
  15. (1) 2 3 4 5
  16.  
  17. Single Pass (O(M(1)))
  18.  
  19. M1(2)={0,2,3}
  20.  
  21. (1 2) 3 4 6
  22. (1 2) 3 4 5
  23. (1 2) 3 4 5
  24.  
  25. Single Pass (O(M1(2)))
  26.  
  27. M2(3)={0,2,3}
  28.  
  29. (1 2 3) 4 6
  30. (1 2 3) 4 5
  31. (1 2 3) 4 5
  32.  
  33. Single Pass (O(M2(3)))
  34.  
  35. M3(4)={0,2,3}
  36.  
  37. (1 2 3 4) 6
  38. (1 2 3 4) 5
  39. (1 2 3 4) 5
  40.  
  41. Single Pass (O(M3(4)))
  42.  
  43. M4(6)={0}
  44. M4(5)={2,3}
  45.  
  46. Here M4(6) ={0} have length as 1 so mark referenceIndex[0]=0
  47. (1 2 3 4 6 )
  48.  
  49. Here M4(5) ={2,3} have covered all elements and still the M4(5) ={2,3} have lenght 2 which means row (2,3) are same so mark referenceIndex[2]=referenceIndex[3]=2(any of 2,3)
  50. (1 2 3 4 5)
  51. (1 2 3 4 5)
  52.  
  53.  
  54. You can follow the same with M(2)also and mark referenceIndex for all its elements .
  55.  
  56. Once you mark refernce index for all , we have proper list with duplicates .
  57. This can be acchived by using the stack or recursion .
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement