complexity-theory

Log-log plot/graph of algorithm time complexity [closed]

我的未来我决定 提交于 2019-12-12 01:14:13
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I just wrote the quick and merge sort algorithms and I want to make a log-log plot of their run time vs size of array to sort. As I have never done this my question is does it matter if I choose arbitrary numbers for the array length (size of input) or should I follow a

Analyzing an exponential recursive function

独自空忆成欢 提交于 2019-12-11 17:26:40
问题 I am trying to calculate the complexity of the following exponential recursive function. The isMember() and isNotComputed() functions reduce the number of recursive calls. The output of this code is a set of A[], B[] which are printed at the initial part of recursive function call. Would appreciate any inputs on developing a recursive relationship for this problem which would lead to the analysis of this program. Without the functions isMember(), isNotComputed() this code has the complexity

calculating Lempel-Ziv (LZ) complexity (aka sequence complexity) of a binary string

喜你入骨 提交于 2019-12-11 17:17:52
问题 I need to calculate the LZ-complexity of a binary string. The LZ-complexity is the number of differencet substrings encountered as the stream is viewed from begining to the end. As an example: s = 1001111011000010 Marking in the different substrings the sequence complexity c(s) = 6: s = 1 / 0 / 01 / 1110 / 1100 / 0010 / can someone guide me to find a simple solution for that? I am sure there should be some very straight-forward implementations for this well-known problem, but I have

Calculate complexity of recursion algorithm

╄→гoц情女王★ 提交于 2019-12-11 14:52:35
问题 func3(int n) { for (int i = 1; i<n; i++) System.out.println("*"); if (n <= 1) { System.out.println("*"); return; } if(n % 2 != 0) //check if odd func3(n - 1) func3(n / 2); return; } I need to calculate the complexity of this algorithm, how can i do it when i have for in my code and 2 calls to func3? 回答1: The bit pattern of n is very helpful in illustrating this problem. Integer division of n by 2 is equivalent to right-shifting the bit pattern by one place, discarding the least significant

Array search NP complete [closed]

不羁岁月 提交于 2019-12-11 14:48:54
问题 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 4 years ago . Given an unsorted array of size n, it's obvious that finding whether an element exists in the array takes O(n) time. If we let m = log n then it takes O(2^m) time. Notice that if the array is sorted, a binary search actually takes O(m) time (which is polynomial) but the binary search cannot apply to an unsorted

What is the complexity / real cost of exp in cmath compared to a FLOP?

我怕爱的太早我们不能终老 提交于 2019-12-11 13:50:58
问题 [I globally edited the question to be more "useful" and clear] I was wondering about the complexity of the implementation of the function exp in cmath. By complexity, I mean algorithmic complexity if possible. Otherwise cost compared to a floating point operation (addition for example) The following lines : double x = 3; double y = std::exp(x); compile to : ... 19,23d16 movq %rax, -40(%rbp) movsd -40(%rbp), %xmm0 call exp movsd %xmm0, -40(%rbp) movq -40(%rbp), %rax ... exp has to be

Dutch national flag on a Turing Machine

笑着哭i 提交于 2019-12-11 10:35:40
问题 I have a sequence of characters xxxxxx (with x^k and k > 0) My goal is to transform this sentence into a dutch flag, that is to say : xxxxx -> RRWWBB xxxx -> RWBB with R <= W <= B All solutions that I have found, have a very high complexity. Do you have any hint/clue to help to me build a Turing machine using only one tape and one head/cursor? 回答1: How about dividing the task into subtasks like: Change the last X to B. Change the last X to W. Change the first X to R. Change BW to WB. EDIT:

How can some NP-Complete problems be also NP-Hard?

≯℡__Kan透↙ 提交于 2019-12-11 09:15:25
问题 I'm trying wrap my heard around P, NP, NP-Complete and NP-Hard in an intuitive way so that I don't have to remember their definitions. In the following image (the left hand scenario, P != NP), there's an overlapping area between NP-Complete and NP-Hard. Does it mean that some problems are both NP-Complete and NP-Hard? I find that contradictory, according to this particular answer: What are the differences between NP, NP-Complete and NP-Hard?. The table in the above link says an NP-Complete

How to solve the recurrence equation T(n)=T(n/2)+T(n/4)+\Theta(n)?

久未见 提交于 2019-12-11 07:33:13
问题 How to solve the recurrence equation 1.T(n)=T(n/2)+T(n/4)+\Theta(n) 2.T(1)=1 Use Big-Theta notation to give the result 回答1: I don't want to give you direct answer, but my hint: look for Mathematical series of form: 1/2 + 1/4 + ... + 1/2^n 回答2: well then we look at this question carfuley we can analys it. lets start with examples, as we explore them we could reach better understanding on how to solve them(the other problem is how to represent the data we have, but that is a computer sientenst

Time complexity analysis. while loop with inner for loop [duplicate]

ε祈祈猫儿з 提交于 2019-12-11 04:47:08
问题 This question already has an answer here : Time complexity analysis. choosing operator for counting number of times a line of code runs (1 answer) Closed 5 years ago . I'm trying to find the number of times this code runs. On the right I have my attempt at the code. I'm am not sure about the loops. Here is the code: times sum = 0 1 i = 1 1 while i ≤ n log n + 1 sum = sum + i n log n i = 2i log n return sum 1 => n log n + 2 log n + 4 and thereby: O(n log n) is this correct ? 回答1: No, your