Jump to content

Roberto Dall'Angelo

Members
  • Content Count

    2
  • Joined

  • Last visited

Everything posted by Roberto Dall'Angelo

  1. Hello, I hope this is the correct section I need help. It is easy for me to translate this pseudo code into delphi, I have aleady done it. Basically: given 2 integers m and n (both >= 0), it checks if the program is the permutation of another one. Like 915 and 159 ARE permutations (just swap some numbers) while 911 and 19 are not. perm(m, n) # use an array for counting the difference in the number of digits# of the two numbers. Note that we do not need to count the 0’s as# different number of 0’s can be compensated by putting 0’s in front # D[i] = difference count for cypher i+1 for i=1 to 10 D[i] = 0 while (m > 0) # compute the last digit of m d = m mod 10 if (d > 0) D[d]++ m = m div 10 while (n > 0) # compute the last digit of m d = n mod 10 if (d > 0) D[d]-- n=n div 10 # returns True if D contains all zeros i = 1 while ((i<=9) and (D[i]==0)) i++ return (i>9) This pseudo code is good and my delphi code works because i have used the above. QUESTION: I am not expert but I'd like to analyze the complexity of the pseudo code. Is it O(n)? Because there are 3 for loops and both loop an a cicle for n or m times so it is linear. Am I correct? I hope this is good section for my question!
  2. Roberto Dall'Angelo

    Delphi permutation code complexity

    Ok I do not understand. I have basic math knowledge. Are there basic rules to understand the complexity? Like understand if is O(n) or O(log n)
×