computation-theory

Subtle nuances of Big O notation for computation complexity

二次信任 提交于 2021-02-11 07:08:55
问题 I was just working on a LeetCode problem, Roman to Integer, the conversion of Roman numerals to integers, and after finishing up and comparing solutions, I noticed a rather interesting nuance in how the solutions listed describe their computational complexity. I had described my solution as O(n) , linear with the number of input elements, as my solution iterated over the elements of a Roman numeral character by character. The official solutions, however, described how with numerals I , V , X

Negative speed up in Amdahl's law?

删除回忆录丶 提交于 2021-02-02 09:07:51
问题 Amdahl’s law states that a speed up of the entire system is an_old_time / a_new_time where the a_new_time can be represented as ( 1 - f ) + f / s’ , where f is the fraction of the system that is enhanced by some modification, and s’ is the amount by which that fraction of the system is enhanced. However, after solving this equation for s’ , it seems like there are many cases in which s’ is negative, which makes no physical sense. Taking the case that s = 2 (a 100% increase in the speed for

Divide list into two equal parts algorithm

≯℡__Kan透↙ 提交于 2020-06-27 04:07:10
问题 Related questions: Algorithm to Divide a list of numbers into 2 equal sum lists divide list in two parts that their sum closest to each other Let's assume I have a list, which contains exactly 2k elements. Now, I'm willing to split it into two parts, where each part has a length of k while trying to make the sum of the parts as equal as possible. Quick example: [3, 4, 4, 1, 2, 1] might be splitted to [1, 4, 3] and [1, 2, 4] and the sum difference will be 1 Now - if the parts can have

Why does Regexp have a timeout method, while in theory they shouldn't?

大兔子大兔子 提交于 2020-01-01 19:51:11
问题 This is a theoretical Computer Science question (Computation Theory). I know that RegExps can take a very long time to calculate. However, from Theory of Computation we know that matching with a Regular Expression can be done extremely fast in a few clock cycles. If RegExps are equivalent to Finite Automata, why RegExps have (or require) a timeout method? Using a DFA, the computation time for matching can be exteremely fast. By RegExps I mean the Regular Expressions pattern matching classes

NP problems and need some detail?

随声附和 提交于 2020-01-01 19:40:29
问题 I see one solved ex on Algorithms. Which of the following is in NP? a) Decision Version of TSP b) Array is Sorted? c) Finding the maximum flow network d) Decision version of 0/1 knapsack? My Note, says all of these is in NP, anyone could add a bit detail for each one why? and I confusing about 0/1 knapsack, is it NP? NP-HARD? or NP-Complete? Thanks. 回答1: They all are in NP, because: It is verifiable in polynomial time. Given some route, we can easily check whether its length does not exceed

What does the phrase “binds stronger” mean?

折月煮酒 提交于 2019-12-31 03:36:29
问题 I know this might be a newbie question, but I'm trying to make sense of this sentence(from a paper on a meta language that uses EBNF): Logical and (&) binds stronger than logical or (|). Before that it says: Conditions are: condition ::= condition (`&´ | `|´ ) condition | `!´ condition | relation relation ::= expression ( `=´ | `#´ | `<´ | `<=´ | `>´ | `>=´ ) expression thanks 回答1: This refers to precedence. In other words, if you have A & B | C , you really have (A & B) | C . Operations with

What does the phrase “binds stronger” mean?

社会主义新天地 提交于 2019-12-31 03:36:12
问题 I know this might be a newbie question, but I'm trying to make sense of this sentence(from a paper on a meta language that uses EBNF): Logical and (&) binds stronger than logical or (|). Before that it says: Conditions are: condition ::= condition (`&´ | `|´ ) condition | `!´ condition | relation relation ::= expression ( `=´ | `#´ | `<´ | `<=´ | `>´ | `>=´ ) expression thanks 回答1: This refers to precedence. In other words, if you have A & B | C , you really have (A & B) | C . Operations with

Eliminating Immediate Left Recursion

两盒软妹~` 提交于 2019-12-20 07:09:57
问题 I understand that in order to eliminate an immediate left recursion from a grammar containing production of the form A⇒Aα i need to replace it by A⇒βA'and A'⇒αA/∈ Im having the following productions,i need to eliminate immediate left recursion E⇒E+T/T E⇒E+T/T T⇒T*F/T F⇒(E)/(id) I can see that after elimination the first production becomes E⇒TE' E'⇒+TE'/T∈ Can somebody explain how this comes 回答1: It's really just a matter of following the algorithm. Let's look at the general case. According to

What is the context free grammar for the complement of the double word over 0,1?

℡╲_俬逩灬. 提交于 2019-12-19 09:58:06
问题 What is the CFG of the complement of L={ww|w belongs to {0,1}*}? 回答1: First of all observe the fact that any odd word is part of the language. Let's define the following languages: L1={w1w|w{0,1}*}, L0={w0w|w{0,1}*}. These languages can be defined with the following CFG: S0/1 -> |0S0|1S1|0S1|1S0 Now look at L3: L3=(L1)U(L2)U(L1L2)U(L2L1) It is context free from closure to union and concatenation. Let's prove that L3 is the language we're looking for. First of all as we have seen it deals with

Construct grammar given the following language {a^n b^m | n,m = 0,1,2,…,n <= 2m} [closed]

一曲冷凌霜 提交于 2019-12-18 12:42:55
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I just took my midterm but couldn't answer this question. Can someone please give a couple of examples of the language and construct a grammar for the