computer-science

why IEEE floating point number calculate exponent using a biased form?

北战南征 提交于 2019-11-29 01:39:26
let's say, for the float type in c, according to the IEEE floating point specification, there are 8-bit used for the fraction filed, and it is calculated as first taken these 8-bit and translated it into an unsigned number, and then minus the BIASE, which is 2^7 - 1 = 127, and the result is an exponent ranges from -127 to 128, inclusive. But why can't we just treat these 8-bit pattern as a signed number, since the resulting range is [-128,127], which is almost the same as the previous one. The purpose of the bias is so that the exponent is stored in unsigned form, making it easier to do

What does it mean for two binary trees to be isomorphic?

允我心安 提交于 2019-11-29 00:56:25
问题 What does it mean for two binary trees to be isomorphic? I've been looking online and I can't seem to find a clear explanation. As far as I understand, two trees are isomorphic if they have the same shape. So I'm guessing two identical trees which can contain different values in the nodes. 回答1: Isomorphic comes from the Greek "same shape" (like isobar is points with the same air pressure and polygon means "many sided") so your understanding is correct. But don't make the mistake of assuming

Balancing a Binary Tree (AVL)

放肆的年华 提交于 2019-11-28 23:38:57
问题 Ok, this is another one in the theory realm for the CS guys around. In the 90's I did fairly well in implementing BST's. The only thing I could never get my head around was the intricacy of the algorithm to balance a Binary Tree (AVL). Can you guys help me on this? 回答1: A scapegoat tree possibly has the simplest balance-determination algorithm to understand. If any insertion causes the new node to be too deep, it finds a node around which to rebalance, by looking at weight balance rather than

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

巧了我就是萌 提交于 2019-11-28 23:22:10
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 get it (-: Thanks all! P Class of all problems which can be solved by a deterministic Turing machine in

How can I determine if a language is context free or not?

本秂侑毒 提交于 2019-11-28 22:26:06
问题 How can I know whether the languages are context free or not? 回答1: First, you should attempt to build a context-free grammar that forms the language in subject. A grammar is context-free if left-hand sides of all productions contain exactly one non-terminal symbol. By definition, if one exists, then the language is context-free. An equivalent construct would be a pushdown automaton. It's the same as DFA, but with a stack available. It may be easier to build than a grammar. However, if you

Why is Binary Search a divide and conquer algorithm?

五迷三道 提交于 2019-11-28 20:38:18
I was asked if a Binary Search is a divide and conquer algorithm at an exam. My answer was yes, because you divided the problem into smaller subproblems, until you reached your result. But the examinators asked where the conquer part in it was, which I was unable to answer. They also disapproved that it actually was a divide and conquer algorithm. But everywhere I go on the web, it says that it is, so I would like to know why, and where the conquer part of it is? Kenci The book Data Structures and Algorithm Analysis in Java, 2nd edtition, Mark Allen Weiss Says that a D&C algorithm should have

How do backreferences in regexes make backtracking required?

喜夏-厌秋 提交于 2019-11-28 18:48:13
I read http://swtch.com/~rsc/regexp/regexp1.html and in it the author says that in order to have backreferences in regexs, one needs backtracking when matching, and that makes the worst-case complexity exponential. But I don't see exactly why backreferences introduce the need for backtracking. Can someone explain why, and perhaps provide an example (regex and input)? To get directly at your question, you should make a short study of the Chomsky Hierarchy . This is an old and beautiful way of organizing formal languages in sets of increasing complexity. The lowest rung of the hierarchy is the

What is the difference between equality and equivalence?

◇◆丶佛笑我妖孽 提交于 2019-11-28 17:51:24
I've read a few instances in reading mathematics and computer science that use the equivalence symbol ≡ , (basically an '=' with three lines) and it always makes sense to me to read this as if it were equality. What is the difference between these two concepts? Eugene Yokota Wikipedia: Equivalence relation : In mathematics, an equivalence relation is a binary relation between two elements of a set which groups them together as being "equivalent" in some way. Let a, b, and c be arbitrary elements of some set X. Then "a ~ b" or "a ≡ b" denotes that a is equivalent to b. An equivalence relation "

Why are both little- and big-endian in use?

佐手、 提交于 2019-11-28 17:46:21
Why are both little- and big-endian still in use today , after ~40 years of binary computer-science? Are there algorithms or storage formats that work better with one and much worse with the other? Wouldn't it be better if we all switched to one and stick with it? When adding two numbers (on paper or in a machine), you start with the least significant digits and work towards the most significant digits. (Same goes for many other operations). On the Intel 8088, which had 16-bit registers but an 8-bit data bus, being little-endian allowed such instructions to start operation after the first

Creating the shortest Turing-complete interpreter [closed]

烈酒焚心 提交于 2019-11-28 16:32:33
I've just tried to create the smallest possible language interpreter. Would you like to join and try? Rules of the game: You should specify a programming language you're interpreting. If it's a language you invented, it should come with a list of commands in the comments. Your code should start with example program and data assigned to your code and data variables. Your code should end with output of your result. It's preferable that there are debug statements at every intermediate step. Your code should be runnable as written. You can assume that data are 0 and 1s (int, string or boolean,