I won't give you a full solution, but will try to guide you. You should get a pencil and a paper, and ask yourself: How many times does the statement print asd[i], asd[j] execute? (in worst case, meaning that you shouldn't really care about the condition there) You'll find that...

java,algorithm,complexity-theory,code-complexity

start with inner loop : for(int k = 0; k < n; k++) x++; is obviously O(n). now one layer above that : for(int j = 0; j < n/4; j++) is O(n) because it takes n/4 for j to reach the n and we know that O(n/4) = O(n)...

algorithm,big-o,code-complexity

As far as big-O is concerned, the two are equal: you can freely subtract constants and divide by constants, so both algorithms are linear in the number of their inputs - i.e. they are O(n). In general, big-O will not tell you exactly how fast an algorithm is. It boils...

You can use sum and a dict, storing vowels as keys and the associated value as the values: word = input("Input a word: ") values = {"a":5,"e":4,"i":3,"o":2,"u":1} print(sum(values.get(ch,0) for ch in word)) values.get(ch,0) will return 0 as a default value if the ch which is each char in the word...

algorithm,asymptotic-complexity,code-complexity

Yes, this is O(n^2), assuming the function executed is O(1), of course, and the iterator is also O(1) on average per iteration (which is usually a valid assumption). Note that even if you optimize it further, you are going to process Choose(n,2) elements, and Choose(n,2)=n(n-1)/2, which is still in O(n^2)....

java,algorithm,complexity-theory,code-complexity

In each iteration x is divided by 5. How many iterations would it take for x to become lower than 1 (and therefore 0)? The answer is log5(n) (logarithm to the base 5 of n), which is O(log(n))....

The control-flow graph of your example contains 5 edges (E), 5 nodes(N) and one connected components (P). According to the defintion of the complexity (M=E-N+2P) the correct complexity value is 2....

java,sorting,insertion-sort,code-complexity

Without further information about the underlying data, the best time complexity you can achieve with sorting algorithms is O(n log n) (n being the number of elements). Sorting algorithms like insertion sort, bubble sort, selection sort, etc., all have a time complexity of O(n²) due to their double loops. In...