Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. # The computational complexity of my answer in Question 1 is O(n^2)
  2.  
  3. def isSubsetArray(ArrayA, ArrayB):
  4. countSameSubset = 0 # 1 Step
  5. for i_index in range(len(ArrayB)): # n Step
  6. for j_index in range(len(ArrayA)): # n Step
  7. if (ArrayA[j_index].strip().upper() == ArrayB[i_index].strip().upper()): # 1 Step
  8. countSameSubset += 1 # 1 Step
  9. break # 1 Step
  10.  
  11. if (countSameSubset == len(ArrayB)): # 1 Step
  12. return True # 1 Step
  13. else:
  14. return False # 1 Step
  15.  
  16. def main():
  17. StringA = input("Input the 1st Array : ") # 1 Step
  18. StringB = input("Input the 2nd Array : ") # 1 Step
  19. isSubsetValue = isSubsetArray(StringA.split(','), StringB.split(',')) # 1 Step
  20. print('isSubset([',StringB.upper(),'], [', StringA.upper(), ']) = ', str(isSubsetValue)) # 1 Step
  21.  
  22. if __name__ == '__main__':
  23. main() # 1 Step
  24.  
  25. # Because the comlexity time on line 5 is n Step and on line 6 is also n Step, so my computational complexity of my answer in Question 1 is O(n^2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement