complexity-theory

How to improve Cyclomatic Complexity?

白昼怎懂夜的黑 提交于 2019-12-21 03:59:24
问题 Cyclomatic Complexity will be high for methods with a high number of decision statements including if/while/for statements. So how do we improve on it? I am handling a big project where I am supposed to reduced the CC for methods that have CC > 10. And there are many methods with this problem. Below I will list down some eg of code patterns (not the actual code) with the problems I have encountered. Is it possible that they can be simplified? Example of cases resulting in many decision

Best algorithm for delete duplicates in array of strings

十年热恋 提交于 2019-12-21 01:16:10
问题 Today at school the teacher asked us to implement a duplicate-deletion algorithm. It's not that difficult, and everyone came up with the following solution (pseudocode): for i from 1 to n - 1 for j from i + 1 to n if v[i] == v[j] then remove(v, v[j]) // remove(from, what) next j next i The computational complexity for this algo is n(n-1)/2 . (We're in high school, and we haven't talked about big-O, but it seems to be O(n^2) ). This solution appears ugly and, of course, slow, so I tried to

Are there any real O(n^n) algorithms?

时光怂恿深爱的人放手 提交于 2019-12-20 11:10:00
问题 Is there any real Algorithm with a time complexity O(n^n), that isn't just a gimmick? I can create such an Algorithm, like computing n^n in O(n^n) / Θ(n^n): long n_to_the_power_of_m(int n, int m) { if(m == 0) return 1; long sum = 0; for(int i = 0; i < n; ++i) sum += n_to_the_power_of_m(n, m-1); return sum; } (needs more than 4 minutes to compute 10^10) Or other way around: Are there any Problems, which cannot be solved better than in O(n^n)? 回答1: What you have coded in your example is very

Recursion and Big O

你。 提交于 2019-12-20 10:39:53
问题 I've been working through a recent Computer Science homework involving recursion and big-O notation. I believe I understand this pretty well (certainly not perfectly, though!) But there is one question in particular that is giving me the most problems. The odd thing is that by looking it, it looks to be the most simple one on the homework. Provide the best rate of growth using the big-Oh notation for the solution to the following recurrence? T(1) = 2 T(n) = 2T(n - 1) + 1 for n>1 And the

How to calculate time complexity of backtracking algorithm?

允我心安 提交于 2019-12-20 10:08:28
问题 How to calculate time complexity for these backtracking algorithms and do they have same time complexity? If different how? Kindly explain in detail and thanks for the help. 1. Hamiltonian cycle: bool hamCycleUtil(bool graph[V][V], int path[], int pos) { /* base case: If all vertices are included in Hamiltonian Cycle */ if (pos == V) { // And if there is an edge from the last included vertex to the // first vertex if ( graph[ path[pos-1] ][ path[0] ] == 1 ) return true; else return false; } /

Are there public key cryptography algorithms that are provably NP-hard to defeat? [closed]

我是研究僧i 提交于 2019-12-20 09:15:47
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . Should practical quantum computing become a reality, I am wondering if there are any public key cryptographic algorithms that are based on NP-complete problems, rather than integer factorization or discrete logarithms. Edit: Please check out the "Quantum computing in computational complexity theory" section of

Explain the proof by Vinay Deolalikar that P != NP [closed]

前提是你 提交于 2019-12-20 08:29:07
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Recently there has been a paper floating around by Vinay Deolalikar at HP Labs which claims to have proved that P != NP. Could someone explain how this proof works for us less mathematically inclined people? 回答1: I've only scanned through the paper, but here's a rough summary of how it all hangs together. From

Missing number(s) Interview Question Redux

♀尐吖头ヾ 提交于 2019-12-20 08:19:39
问题 The common interview problem of determining the missing value in a range from 1 to N has been done a thousand times over. Variations include 2 missing values up to K missing values. Example problem: Range [1,10] (1 2 4 5 7 8 9 10) = {3,6} Here is an example of the various solutions: Easy interview question got harder: given numbers 1..100, find the missing number(s) My question is that seeing as the simple case of one missing value is of O(n) complexity and that the complexity of the larger

Real-world example of exponential time complexity

我只是一个虾纸丫 提交于 2019-12-20 08:18:11
问题 I'm looking for an intuitive, real-world example of a problem that takes (worst case) exponential time complexity to solve for a talk I am giving. Here are examples for other time complexities I have come up with (many of them taken from this SO question): O(1) - determining if a number is odd or even O(log N) - finding a word in the dictionary (using binary search) O(N) - reading a book O(N log N) - sorting a deck of playing cards (using merge sort) O(N^2) - checking if you have everything

How to calculate order (big O) for more complex algorithms (eg quicksort)

两盒软妹~` 提交于 2019-12-20 08:02:58
问题 I know there are quite a bunch of questions about big O notation, I have already checked: Plain english explanation of Big O Big O, how do you calculate/approximate it? Big O Notation Homework--Code Fragment Algorithm Analysis? to name a few. I know by "intuition" how to calculate it for n , n^2 , n! and so, however I am completely lost on how to calculate it for algorithms that are log n , n log n , n log log n and so. What I mean is, I know that Quick Sort is n log n (on average).. but, why