How can I reduce time complexity on this algorithm?

I have this exercise and the goal is to solve it with complexity less than O(n^2). You have an array with length N filled with event probabilities. Create another array in which for each element i calculate the probability of all event to happen until the position i. I have coded this O(n^2) solution. Any… Read More How can I reduce time complexity on this algorithm?

What exactly is Input size

When I am about to know some algorithms I confused about what exacly is input size. For example in travelling sales person problem dynamic programming implementation takes O(2n × n2) And krushals algorithm takes O(E log V).Though both are graph problems why TSP input size is no.of Vertices n and krushals input size is in… Read More What exactly is Input size

Complexity between if-else, switch and regex

I’m going to optimize javascript code in which I seen old code is like below, var emcont = \$(‘#emcont’).val(); numericMatch = emcont.match(/\d/g); if (numericMatch == null) { isValid = false; \$(‘#msg_emcont’).html(getMessage(‘msg_emcont’)).show(); } else if (emcont.length != 14) { isValid = false; \$(‘#msg_emcont’).html(getMessage(‘msg_emcont’)).show(); } else if (numericMatch.length && numericMatch.length != 10) { isValid = false; \$(‘#msg_emcont’).html(getMessage(‘msg_emcont’)).show();… Read More Complexity between if-else, switch and regex

Big Oh notation higher than T(n)

I have just learnt Big-Oh notation and saw the below problem: (1) Is T(n) = 10n^4 + 850n = O(n^3) ?? (2) Is T(n) = 10n^4 + 850n = O(n^4) ?? (3) Is T(n) = 10n^4 + 850n = O(n^30) ?? I have understood (1) that Big-Oh represents the upper bound and hence it cannot… Read More Big Oh notation higher than T(n)