complexity-theory

What is the complexity of regular expression?

故事扮演 提交于 2019-11-26 05:26:29
问题 What is the complexity with respect to the string length that takes to perform a regular expression comparison on a string? 回答1: The answer depends on what exactly you mean by "regular expressions." Classic regexes can be compiled into Deterministic Finite Automata that can match a string of length N in O(N) time. Certain extensions to the regex language change that for the worse. You may find the following document of interest: Regular Expression Matching Can Be Simple And Fast. 回答2:

Finding Big O of the Harmonic Series

吃可爱长大的小学妹 提交于 2019-11-26 04:46:09
问题 Prove that 1 + 1/2 + 1/3 + ... + 1/n is O(log n). Assume n = 2^k I put the series into the summation, but I have no idea how to tackle this problem. Any help is appreciated 回答1: This follows easily from a simple fact in Calculus: and we have the following inequality: Here we can conclude that S = 1 + 1/2 + ... + 1/n is both Ω(log(n)) and O(log(n)), thus it is Ɵ(log(n)), the bound is actually tight. 回答2: Here's a formulation using Discrete Mathematics: So, H(n) = O(log n) 来源: https:/

.NET Console Application Exit Event

邮差的信 提交于 2019-11-26 04:22:22
In .NET, is there a method, such as an event, for detecting when a Console Application is exiting? I need to clean up some threads and COM objects. I am running a message loop, without a form, from the console application. A DCOM component that I am using seems to require that the application pump messages. I have tried adding a handler to Process.GetCurrentProcess.Exited and Process.GetCurrentProcess.Disposed. I have also tried adding a handler to Application.ApplicationExit and Application.ThreadExit events, but they are not firing. Perhaps that is because I am not using a form. You can use

Is Big O(logn) log base e?

余生长醉 提交于 2019-11-26 03:49:58
问题 For binary search tree type of data structures, I see the Big O notation is typically noted as O(logn). With a lowercase \'l\' in log, does this imply log base e (n) as described by the natural logarithm? Sorry for the simple question but I\'ve always had trouble distinguishing between the different implied logarithms. 回答1: Once expressed in big-O() notation, both are correct. However, during the derivation of the O() polynomial, in the case of binary search, only log 2 is correct. I assume

Big O, how do you calculate/approximate it?

我只是一个虾纸丫 提交于 2019-11-26 03:11:45
问题 Most people with a degree in CS will certainly know what Big O stands for. It helps us to measure how (in)efficient an algorithm really is and if you know in what category the problem you are trying to solve lays in you can figure out if it is still possible to squeeze out that little extra performance. 1 But I\'m curious, how do you calculate or approximate the complexity of your algorithms? 1 but as they say, don\'t overdo it, premature optimization is the root of all evil, and optimization

Are there any O(1/n) algorithms?

随声附和 提交于 2019-11-26 02:59:43
问题 Are there any O(1/n) algorithms? Or anything else which is less than O(1)? 回答1: This question isn't as stupid as it might seem. At least theoretically, something such as O (1/ n ) is completely sensible when we take the mathematical definition of the Big O notation: Now you can easily substitute g ( x ) for 1/ x … it's obvious that the above definition still holds for some f . For the purpose of estimating asymptotic run-time growth, this is less viable … a meaningful algorithm cannot get

A Regex that will never be matched by anything

空扰寡人 提交于 2019-11-26 02:33:18
问题 This might sound like a stupid question, but I had a long talk with some of my fellow developers and it sounded like a fun thing to think of. So; what\'s your thought - what does a Regex look like, that will never be matched by any string, ever! Edit : Why I want this? Well, firstly because I find it interesting to think of such an expression and secondly because I need it for a script. In that script I define a dictionary as Dictionary<string, Regex> . This contains, as you see, a string and

Determining complexity for recursive functions (Big O notation)

非 Y 不嫁゛ 提交于 2019-11-26 02:25:53
问题 I have a Computer Science Midterm tomorrow and I need help determining the complexity of these recursive functions. I know how to solve simple cases, but I am still trying to learn how to solve these harder cases. These were just a few of the example problems that I could not figure out. Any help would be much appreciated and would greatly help in my studies, Thank you! int recursiveFun1(int n) { if (n <= 0) return 1; else return 1 + recursiveFun1(n-1); } int recursiveFun2(int n) { if (n <= 0

What are the differences between NP, NP-Complete and NP-Hard?

倖福魔咒の 提交于 2019-11-26 02:18:31
What are the differences between NP , NP-Complete and NP-Hard ? I am aware of many resources all over the web. I'd like to read your explanations, and the reason is they might be different from what's out there, or there is something that I'm not aware of. jason I assume that you are looking for intuitive definitions, since the technical definitions require quite some time to understand. First of all, let's remember a preliminary needed concept to understand those definitions. Decision problem : A problem with a yes or no answer. Now, let us define those complexity classes . P P is a

What are the differences between NP, NP-Complete and NP-Hard?

纵饮孤独 提交于 2019-11-26 01:50:03
问题 What are the differences between NP , NP-Complete and NP-Hard ? I am aware of many resources all over the web. I\'d like to read your explanations, and the reason is they might be different from what\'s out there, or there is something that I\'m not aware of. 回答1: I assume that you are looking for intuitive definitions, since the technical definitions require quite some time to understand. First of all, let's remember a preliminary needed concept to understand those definitions. Decision