In: Computer Science
def anagramSolution1(s1,s2):
alist = list(s2)
pos1 = 0
stillOK = True
while pos1 < len(s1) and stillOK:
pos2 = 0
found = False
while pos2 < len(alist) and not found:
if s1[pos1] == alist[pos2]:
found = True
else:
pos2 = pos2 + 1
if found:
alist[pos2] = None
else:
stillOK = False
pos1 = pos1 + 1
return stillOK
include all operations and calculate the Big-O and the values for c and n0.
For the better understanfing of the complexity I will explain the complexity of each line one by one.
The order of times complexity of any algorithm is always the statement which is taking largest amount of time, because our focus is always on the worst case scenario.
We know that f(n)= O(g(n)) iff f(n)<=c*g(n) where c is a positive constant with c>=1
So time coopmlexity T(n) of the given code is
T(n)=O(m*n)., where m and n are length of strings list and s1 respectively. Value of c=1 and n0=1