complexity-theory

What's “P=NP?”, and why is it such a famous question? [closed]

送分小仙女□ 提交于 2019-11-28 02:30:46
The question of whether P=NP is perhaps the most famous in all of Computer Science. What does it mean? And why is it so interesting? Oh, and for extra credit, please post a proof of the statement's truth or falsehood. :) P stands for polynomial time. NP stands for non-deterministic polynomial time. Definitions: Polynomial time means that the complexity of the algorithm is O(n^k), where n is the size of your data (e. g. number of elements in a list to be sorted), and k is a constant. Complexity is time measured in the number of operations it would take, as a function of the number of data items

i-th element of k-th permutation

萝らか妹 提交于 2019-11-28 02:04:37
问题 Is there a fast algorithm to compute the i-th element (0 <= i < n) of the k-th permutation (0 <= k < n!) of the sequence 0..n-1? Any order of the permutations may be chosen, it does not have to be lexicographical. There are algorithms that construct the k -th permutation in O(n) (see below). But here the complete permutation is not needed, just its i -th element. Are there algorithms that can do better than O(n) ? Is there an algorithm that has a space complexity less than O(n)? There are

Computational complexity of the FFT in n dimensions

血红的双手。 提交于 2019-11-28 01:22:35
What is the computational complexity of the n-dimensional FFT with m points along each dimension? For a 1D FFT it's O(m log m) . For a 2D FFT you have to do m x 1D FFTs in each axis so that's O(2 m^2 log m) = O(m^2 log m) . It's too early in the morning here to get my head round n >= 3 but I'm guessing it's probably: O(m^n log m) 来源: https://stackoverflow.com/questions/6514861/computational-complexity-of-the-fft-in-n-dimensions

Observing quadratic behavior with quicksort - O(n^2)

纵然是瞬间 提交于 2019-11-28 01:06:23
The quicksort algorithm has an average time complexity of O(n*log(n)) and a worst case complexity of O(n^2). Assuming some variant of Hoare’s quicksort algorithm, what kinds of input will cause the quicksort algorithm to exhibit worst case complexity? Please state any assumptions relating to implementation details regarding the specific quicksort algorithm such as pivot selection, etc. or if it's sourced from a commonly available library such as libc. Some reading: A Killer Adversary for Quicksort Quicksort Is Optimal Engineering a Sort Function Introspective Sorting and Selection Algorithms

Number of Comparisons in Merge-Sort

喜欢而已 提交于 2019-11-28 00:18:39
I was studying the merge-sort subject that I ran into this concept that the number of comparisons in merge-sort (in the worst-case, and according to Wikipedia ) equals (n ⌈lg n⌉ - 2 ⌈lg n⌉ + 1); in fact it's between (n lg n - n + 1) and (n lg n + n + O(lg n)). The problem is that I cannot figure out what these complexities try to say. I know O(nlogn) is the complexity of merge-sort but the number of comparisons? Why to count comparisons There are basically two operations to any sorting algorithm: comparing data and moving data. In many cases, comparing will be more expensive than moving. Think

Priority Queue remove complexity time

北城以北 提交于 2019-11-27 22:58:23
问题 What is the complexity (big-oh) for the remove() function on the Priority Queue class in Java? I can't find anything documented anywhere, I think it's O(n), considering you have to find the element before you remove it and then reshuffle the tree. but I've seen others that disagree and think it's O(logn). Any ideas? 回答1: The confusion is actually caused by your "remove" function. In java, there are two remove functions. remove() -> This is to remove the head/root, it takes O(logN) time.

Why are NP problems called that way (and NP-hard and NP-complete)?

扶醉桌前 提交于 2019-11-27 21:14:57
问题 Really.. I'm having the last test for graduation this Tuesday, and that's one of the things I just never could understand. I realize that a solution for NP problem can be verfied in polynomial time. But what does determinism has to do with that? And if you could explain me where NP-complete and NP-hard got their names, that would be great (I'm pretty sure I get the meaning of them, I just don't see what their names have to do with what they are). Sorry if that's trivial, I just can't seem to

Example of a factorial time algorithm O( n! )

耗尽温柔 提交于 2019-11-27 20:39:24
问题 I'm studying time complexity in school and our main focus seems to be on polynomial time O(n^c) algorithms and quasi-linear time O(nlog(n)) algorithms with the occasional exponential time O(c^n) algorithm as an example of run-time perspective. However, dealing with larger time complexities was never covered. I would like to see an example problem with an algorithmic solution that runs in factorial time O(n!) . The algorithm may be a naive approach to solve a problem but cannot be artificially

Linear time majority algorithm?

雨燕双飞 提交于 2019-11-27 18:52:21
Can anyone think of a linear time algorithm for determining a majority element in a list of elements? The algorithm should use O(1) space. If n is the size of the list, a majority element is an element that occurs at least ceil(n / 2) times. [Input] 1, 2, 1, 1, 3, 2 [Output] 1 [Editor Note] This question has a technical mistake. I preferred to leave it so as not to spoil the wording of the accepted answer, which corrects the mistake and discusses why. Please check the accepted answer. I would guess that the Boyer-Moore algorithm (as linked to by nunes and described by cldy in other answers) is

Databases versus plain text

梦想的初衷 提交于 2019-11-27 18:31:46
When dealing with small projects, what do you feel is the break even point for storing data in simple text files, hash tables, etc., versus using a real database? For small projects with simple data management requirements, a real database is unnecessary complexity and violates YAGNI. However, at some point the complexity of a database is obviously worth it. What are some signs that your problem is too complex for simple ad-hoc techniques and needs a real database? Note: To people used to enterprise environments, this will probably sound like a weird question. However, my problem domain is