computer-science

Is Date.now referential transparent?

久未见 提交于 2019-12-12 07:13:59
问题 DateTime.Now or Date.now is referential transparent? This is one of the controversial topic in a functional programming article in Qiita. First of all, we must be very careful since the word "referential transparent" is tricky word/concept in a sense, and a prominent discussion exists in What is referential transparency? The questioner states: What does the term referential transparency mean? I've heard it described as "it means you can replace equals with equals" but this seems like an

If f = O(g), is e^f = O(e^g)?

南笙酒味 提交于 2019-12-12 07:07:14
问题 If f = O(g) , is e^f = O(e^g) ? I'm having difficultly figuring out the above question. An example would be welcome. Also, if you use l'Hôpital's rule, please show how you do differentiation. 回答1: This statement is wrong, for example 2n = O(n), but exp(2n) != O(exp(n)). (The latter would mean exp(2n) <= C exp(n) for sufficiently large n, i.e. exp(n) <= C which is not true.) 回答2: The claim is not correct. A conterexample is the following: We have no doubt that 2n is element of O(n) . But, we

Subtracting binary numbers using two's complement

﹥>﹥吖頭↗ 提交于 2019-12-12 07:03:07
问题 Assume 151 and 214 are signed 8-bit decimal integers stored in two’s complement format. Calculate 151 - 214 using saturating arithmetic. The result should be written in decimal. Show your work. Is this right? I am new to this: decimal | binary | twos complement 151 | 10010111 | 01101001 214 | 11010110 | 00101010 subtract 00111111 -> 63 Why do I get positive 63? 回答1: "Two's complement format" is the normal binary representation of signed integers. It doesn't mean that you have to perform the

longest common subsequence with linear memory usage [closed]

雨燕双飞 提交于 2019-12-12 06:48:12
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I'm trying to find an algorithm which uses linear space of memory for: Given two strings x and y over an arbitrary alphabet, determine their longest common sub sequence. 回答1: Note that when you're calculating the

Implementing Extended Euclid Algorithm

情到浓时终转凉″ 提交于 2019-12-12 05:12:30
问题 Why is the following implementation of the Extended Euclid Algorithm failing? def extended_euclid(a,b): if b == 0: return {a, 1, 0} d1,x1,y1 = extended_euclid(b, a % b) d = d1 x = y1 y = x1 - math.floor(a/b) * y1 return {d, x, y} 回答1: This is the implementation found in https://en.wikibooks.org/wiki/Algorithm_Implementation/Mathematics/Extended_Euclidean_algorithm , looks similar to your's one. def egcd(a, b): if a == 0: return (b, 0, 1) else: g, x, y = egcd(b % a, a) return (g, y - (b // a)

what is meaning expected value(math) and what reason behind it in quickSort?

浪尽此生 提交于 2019-12-12 03:22:44
问题 I need help interpreting the formulas from the Quicksort algorithm description in the Clrs book, page 157 My questions are overlayed in the page screenshot. This formula is about QiuckSort Algorithm. what is behind(logic) E[X] ... I mean what is happening in quickstart that the authors wrote this formula? given n=3, the result is 8, ok, but what does 8 mean semanitcally in quicksort? 回答1: In order to understand the analysis in the book you cited, you need to understand some concepts from

Minimal number of D flip-flops

£可爱£侵袭症+ 提交于 2019-12-12 02:46:10
问题 I have encountered the following question and can't be sure on the answer. Do you have any suggestions, any help would be much appreciated. The Fibonacci sequence F(n) is defined by F(1)=1, F(2)=1, and Fn=F(n-2) + F(n-1) for all integers n>= 3. What is the minimal number of D flip-flops required (along with combinational logic) to design a counter circuit that outputs the first seven Fibonacci numbers (i.e., F1 through F7 ) and then wraps around? (A) 3 (B) 4 (C) 5 (D) 6 (E) 7 Thanks in

Building a histogram faster

北城余情 提交于 2019-12-12 00:44:12
问题 I am working with a large dataset that I need to build a histogram of. I feel like my method of just going through the entire list and marking in a second array the frequency is a slow approach. Any suggestions on how to speed the process up? 回答1: Given that a histogram is a graph containing the counts of all items in each bin, you can't make one without visiting all the items. However, you can: Create the histogram as you collect the data. Then it takes no time to generate. Break up the data

Theory of computation - Using the pumping lemma for context free languages

房东的猫 提交于 2019-12-11 14:18:18
问题 I'm reviewing my notes for my course on theory of computation and I'm having trouble understanding how to complete a certain proof. Here is the question: A = {0^n 1^m 0^n | n>=1, m>=1} Prove that A is not regular. It's pretty obvious that the pumping lemma has to be used for this. So, we have |vy| >= 1 |vxy| <= p (p being the pumping length, >= 1) uv^ixy^iz exists in A for all i >= 0 Trying to think of the correct string to choose seems a bit iffy for this. I was thinking 0^p 1^q 0^p, but I

Confusions on finding a cycle in a possibly unconnected directed graph

二次信任 提交于 2019-12-11 12:49:53
问题 I am confused about this answer. Why can't DFS decide if there is a cycle in a directed graph while visiting each node and each edge at most once? Using the white, gray, black method, one should be able to find a cycle if there is a backward edge. For an unconnected directed graph, why can't one do the following: run DFS from an arbitrary node v and visit as many nodes as v is connected to, then run DFS on another unvisited arbitrary node in the graph, if any, until all nodes are visited? It