computation-theory

Can a Turing machine perform Quicksort?

寵の児 提交于 2019-12-10 10:08:31
问题 As far as I know, a Turing machine can be made to execute loops or iterations of instructions encoded on a Tape. This can be done by identifying Line separators and making the Turing machine go back until a specific count of Line separators is reached (that is, inside the loop). But, can a Turing machine also execute a recursive program? Can someone describe various details for such a Turing Machine? I suppose, if recursion can be executed by a Turing machine, the Quicksort can also be

Complete Weighted Graph and Hamiltonian Tour

笑着哭i 提交于 2019-12-09 16:46:47
问题 I ran into a question on a midterm exam. Can anyone clarify the answer? Problem A: Given a Complete Weighted Graph G, find a Hamiltonian Tour with minimum weight. Problem B: Given a Complete Weighted Graph G and Real Number R, does G have a Hamiltonian Tour with weight at most R? Suppose there is a machine that solves B. How many times can we call B (each time G and Real number R are given),to solve problem A with that machine? Suppose the sum of Edges in G up to M. 1) We cannot do this,

Can a Turing machine perform Quicksort?

…衆ロ難τιáo~ 提交于 2019-12-06 01:48:56
As far as I know, a Turing machine can be made to execute loops or iterations of instructions encoded on a Tape. This can be done by identifying Line separators and making the Turing machine go back until a specific count of Line separators is reached (that is, inside the loop). But, can a Turing machine also execute a recursive program? Can someone describe various details for such a Turing Machine? I suppose, if recursion can be executed by a Turing machine, the Quicksort can also be performed? If the question is if a Turing Machine can execute a sorting algorithm, the answer is yes, since

Slowest Computational Complexity (Big-O)

こ雲淡風輕ζ 提交于 2019-12-05 02:59:51
问题 Out of these algorithms, I know Alg1 is the fastest, since it is n squared. Next would be Alg4 since it is n cubed, and then Alg2 is probably the slowest since it is 2^n (which is supposed to have a very poor performance). However Alg3 and Alg5 are something I have yet to come across in my reading in terms of speed. How do these two algorithms rank up to the other 3 in terms of which is faster and slower? Thanks for any help. Edit: Now that I think about it, is Alg3 referring to O(n log n)?

Context free grammar for non-palindrome

好久不见. 提交于 2019-12-04 21:59:31
问题 I need a CFG which will generate strings other than palindromes. The solution has been provided and is as below.(Introduction to theory of computation - Sipser) R -> XRX | S S -> aTb | bTa T -> XTX | X | <epsilon> X -> a | b I get the general idea of how this grammar works. It mandates the insertion of a sub-string which has corresponding non-equal alphabets on its either half, through the production S -> aTb | bTa , thus ensuring that a palindrome could never be generated. I will write down

Algorithm to generate context free grammar from any regex

核能气质少年 提交于 2019-12-04 12:34:07
问题 Can anyone outline for me an algorithm that can convert any given regex into an equivalent set of CFG rules? I know how to tackle the elementary stuff such as (a|b)*: S -> a A S -> a B S -> b A S -> b B A -> a A A -> a B A -> epsilon B -> b A B -> b B B -> epsilon S -> epsilon (end of string) However, I'm having some problem formalizing it into a proper algorithm especially with more complex expressions that can have many nested operations. 回答1: If you are just talking about regular

Left recursion elimination

蓝咒 提交于 2019-12-04 06:19:22
问题 I have this grammar S->S+S|SS|(S)|S*|a I want to know how to eliminate the left recursion from this grammar because the S+S is really confusing... 回答1: Let's see if we can simplify the given grammar. S -> S*|S+S|SS|(S)|a We can write it as; S -> S*|SQ|SS|B|a Q -> +S B -> (S) Now, you can eliminate left recursion in familiar territory. S -> BS'|aS' S' -> *S'|QS'|SS'|e Q -> +S B -> (S) Note that e is epsilon/lambda. We have removed the left recursion, so we no longer have need of Q and B. S ->

Slowest Computational Complexity (Big-O)

二次信任 提交于 2019-12-03 21:23:43
Out of these algorithms, I know Alg1 is the fastest, since it is n squared. Next would be Alg4 since it is n cubed, and then Alg2 is probably the slowest since it is 2^n (which is supposed to have a very poor performance). However Alg3 and Alg5 are something I have yet to come across in my reading in terms of speed. How do these two algorithms rank up to the other 3 in terms of which is faster and slower? Thanks for any help. Edit: Now that I think about it, is Alg3 referring to O(n log n)? If the ln inside of it means 'log', then that would make it the fastest. Gumbo The ascending order would

Context free grammar for non-palindrome

。_饼干妹妹 提交于 2019-12-03 14:14:05
I need a CFG which will generate strings other than palindromes. The solution has been provided and is as below.(Introduction to theory of computation - Sipser) R -> XRX | S S -> aTb | bTa T -> XTX | X | <epsilon> X -> a | b I get the general idea of how this grammar works. It mandates the insertion of a sub-string which has corresponding non-equal alphabets on its either half, through the production S -> aTb | bTa , thus ensuring that a palindrome could never be generated. I will write down the semantics of the first two productions as I have understood it, S generates strings which cannot be

Algorithm to generate context free grammar from any regex

让人想犯罪 __ 提交于 2019-12-03 08:18:19
Can anyone outline for me an algorithm that can convert any given regex into an equivalent set of CFG rules? I know how to tackle the elementary stuff such as (a|b)*: S -> a A S -> a B S -> b A S -> b B A -> a A A -> a B A -> epsilon B -> b A B -> b B B -> epsilon S -> epsilon (end of string) However, I'm having some problem formalizing it into a proper algorithm especially with more complex expressions that can have many nested operations. If you are just talking about regular expressions from a theoretical point of view, there are these three constructs: ab # concatenation a|b # alternation