Profil de GuanyuNULL? RETURN RANDOMBlogListes Outils Aide

Blog


19 mars

different names for Stack structure

push-down lists
reversion storages
cellars
nesting stores
piles
last in first out (LIFO)
yoyo lists <= this one is interesting~~
 
(from TAOCP)
11 mars

回国先买这套书

The Art of Computer Programming, Volumes 1-3 Boxed Set (Hardcover)

 

The Art of Computer Programming, Volumes 1-3 Boxed Set

 
美国很贵的。。
 
List Price: $164.99
Price: $164.99
 

中国价格。。

 

市场价: ¥248.00  
4-5星会员: ¥186.00 返186分
1-3星会员: ¥193.44 返193分
普通会员: ¥198.40 返198分

 

  【评价】
参与评论 查看书评(共151条)
  【原书名】 The Art of Computer Programming Volumes 1-3 Boxed Set [原书信息]
  【原出版社】 Pearson Education,Inc.
  【作者】 (美)Donald E.Knuth
  【丛书名】 计算机程序设计艺术
  【出版社】 清华大学出版社 【书号】 7-302-05814-8
  【开本】 16开 【页码】 2248
  【出版日期】 2002-9-1 【版次】 1-1
  【所属类别】
  【相关信息】

w 目录 w 作译者 w 查看书评(151) w 勘误建议

 

先买了它。。

26 janvier

Computer Science

Computer Science is NOT a major, it is a LIFE STYLE..

We are not just studying. We are enjoying it. We are not just programming.. We are making the life better.
13 décembre

Poker probability in 52-card deck poker

Royal Flush

The number of different royal flushes are four (one for each suit).

Straight Flush

The highest card in a straight flush can be 5,6,7,8,9,10,Jack,Queen, or King. Thus there are 9 possible high cards, and 4 possible suits, creating 9 * 4 = 36 different possible straight flushes.

Four of a Kind

There are 13 different possible ranks of the 4 of a kind. The fifth card could be anything of the remaining 48. Thus there are 13 * 48 = 624 different four of a kinds.

Full House

There are 13 different possible ranks for the three of a kind, and 12 left for the two of a kind. There are 4 ways to arrange three cards of one rank (4 different cards to leave out), and combin(4,2) = 6 ways to arrange two cards of one rank. Thus there are 13 * 12 * 4 * 6 = 3,744 ways to create a full house.

Flush

There are 4 suits to choose from and combin(13,5) = 1,287 ways to arrange five cards in the same suit. From 1,287 subtract 10 for the ten high cards that can lead a straight, resulting in a straight flush, leaving 1,277. Then multiply for 4 for the four suits, resulting in 5,108 ways to form a flush.

Straight

The highest card in a straight flush can be 5,6,7,8,9,10,Jack,Queen,King, or Ace. Thus there are 10 possible high cards. Each card may be of four different suits. The number of ways to arrange five cards of four different suits is 45 = 1024. Next subtract 4 from 1024 for the four ways to form a flush, resulting in a straight flush, leaving 1020. The total number of ways to form a straight is 10*1020=10,200.

Three of a Kind

There are 13 ranks to choose from for the three of a kind and 4 ways to arrange 3 cards among the four to choose from. There are combin(12,2) = 66 ways to arrange the other two ranks to choose from for the other two cards. In each of the two ranks there are four cards to choose from. Thus the number of ways to arrange a three of a kind is 13 * 4 * 66 * 42 = 54,912.

Two Pair

There are (13:2) = 78 ways to arrange the two ranks represented. In both ranks there are (4:2) = 6 ways to arrange two cards. There are 44 cards left for the fifth card. Thus there are 78 * 62 * 44 = 123,552 ways to arrange a two pair.

One Pair

There are 13 ranks to choose from for the pair and combin(4,2) = 6 ways to arrange the two cards in the pair. There are combin(12,3) = 220 ways to arrange the other three ranks of the singletons, and four cards to choose from in each rank. Thus there are 13 * 6 * 220 * 43 = 1,098,240 ways to arrange a pair.

Nothing

First find the number of ways to choose five different ranks out of 13 which is combin(13,5) = 1287. Then subtract 10 for the 10 different high cards that can lead a straight, to be left with 1277. Each card can be of 1 of 4 suits so there are 45=1024 different ways to arrange the suits in each of the 1277 combinations. However we must subtract 4 from the 1024 for the four ways to form a flush, leaving 1020. So the final number of ways to arrange a high card hand is 1277*1020=1,302,540.

 

Specific High Card Lets find the probability of drawing a jack high, for example. There must be four different cards in the hand all less than a jack, of which there are 9 to choose from. The number of ways to arrange 4 ranks out of 9 is combin(9,4) = 126. We must then subtract 1 for the 9-8-7-6-5 combination which would form a straight, leaving 125. From above we know there are 1020 ways to arrange the suits. Multiplying 125 by 1020 yields 127,500 which the number of ways to form a jack high hand. For ace high remember to subtract 2 rather than 1 from the total number of ways to arrange the ranks since A-K-Q-J-10 and 5-4-3-2-A are both valid straights.

Five Card Draw High Card Hands

Hand

Combinations

Probability

Ace high

502,860

0.19341583

King high

335,580

0.12912088

Queen high

213,180

0.08202512

Jack high

127,500

0.04905808

10 high

70,380

0.02708006

9 high

34,680

0.01334380

8 high

14,280

0.00549451

7 high

4,080

0.00156986

Total

1,302,540

0.501177394

6 décembre

10 kinds of people in the world

There are 10 kinds of people in the world: those who understand binary and those who don't.
27 octobre

cool_illusion

If your eyes follow the movement of the rotating pink dot, you will only see one color, pink.
If you stare at the black + in the center, the moving dot turns to green.
Now, concentrate on the black + in the center of the picture. After a short period of time,
all the pink dots will slowly disappear, and you will only see a green dot rotating if you're lucky!
It's amazing how our brain works. There really is no green dot, and the pink ones really don't disappear.
This should be proof enough, we don't always see what we think we see.

 

http://www.patmedia.net/marklevinson/cool/cool_illusion.html

13 octobre

DeMorgan's Theorems

DeMorgan's Theorems

A mathematician named DeMorgan developed a pair of important rules regarding group complementation in Boolean algebra. By group complementation, I'm referring to the complement of a group of terms, represented by a long bar over more than one variable.

You should recall from the chapter on logic gates that inverting all inputs to a gate reverses that gate's essential function from AND to OR, or visa-versa, and also inverts the output. So, an OR gate with all inputs inverted (a Negative-OR gate) behaves the same as a NAND gate, and an AND gate with all inputs inverted (a Negative-AND gate) behaves the same as a NOR gate. DeMorgan's theorems state the same equivalence in "backward" form: that inverting the output of any gate results in the same function as the opposite type of gate (AND vs. OR) with inverted inputs:

A long bar extending over the term AB acts as a grouping symbol, and as such is entirely different from the product of A and B independently inverted. In other words, (AB)' is not equal to A'B'. Because the "prime" symbol (') cannot be stretched over two variables like a bar can, we are forced to use parentheses to make it apply to the whole term AB in the previous sentence. A bar, however, acts as its own grouping symbol when stretched over more than one variable. This has profound impact on how Boolean expressions are evaluated and reduced, as we shall see.

DeMorgan's theorem may be thought of in terms of breaking a long bar symbol. When a long bar is broken, the operation directly underneath the break changes from addition to multiplication, or visa-versa, and the broken bar pieces remain over the individual variables. To illustrate:

When multiple "layers" of bars exist in an expression, you may only break one bar at a time, and it is generally easier to begin simplification by breaking the longest (uppermost) bar first. To illustrate, let's take the expression (A + (BC)')' and reduce it using DeMorgan's Theorems:

Following the advice of breaking the longest (uppermost) bar first, I'll begin by breaking the bar covering the entire expression as a first step:

As a result, the original circuit is reduced to a three-input AND gate with the A input inverted:

You should never break more than one bar in a single step, as illustrated here:

As tempting as it may be to conserve steps and break more than one bar at a time, it often leads to an incorrect result, so don't do it!

It is possible to properly reduce this expression by breaking the short bar first, rather than the long bar first:

The end result is the same, but more steps are required compared to using the first method, where the longest bar was broken first. Note how in the third step we broke the long bar in two places. This is a legitimate mathematical operation, and not the same as breaking two bars in one step! The prohibition against breaking more than one bar in one step is not a prohibition against breaking a bar in more than one place. Breaking in more than one place in a single step is okay; breaking more than one bar in a single step is not.

You might be wondering why parentheses were placed around the sub-expression B' + C', considering the fact that I just removed them in the next step. I did this to emphasize an important but easily neglected aspect of DeMorgan's theorem. Since a long bar functions as a grouping symbol, the variables formerly grouped by a broken bar must remain grouped lest proper precedence (order of operation) be lost. In this example, it really wouldn't matter if I forgot to put parentheses in after breaking the short bar, but in other cases it might. Consider this example, starting with a different expression:

As you can see, maintaining the grouping implied by the complementation bars for this expression is crucial to obtaining the correct answer.

Let's apply the principles of DeMorgan's theorems to the simplification of a gate circuit:

As always, our first step in simplifying this circuit must be to generate an equivalent Boolean expression. We can do this by placing a sub-expression label at the output of each gate, as the inputs become known. Here's the first step in this process:

Next, we can label the outputs of the first NOR gate and the NAND gate. When dealing with inverted-output gates, I find it easier to write an expression for the gate's output without the final inversion, with an arrow pointing to just before the inversion bubble. Then, at the wire leading out of the gate (after the bubble), I write the full, complemented expression. This helps ensure I don't forget a complementing bar in the sub-expression, by forcing myself to split the expression-writing task into two steps:

Finally, we write an expression (or pair of expressions) for the last NOR gate:

Now, we reduce this expression using the identities, properties, rules, and theorems (DeMorgan's) of Boolean algebra:

The equivalent gate circuit for this much-simplified expression is as follows:

  • REVIEW
  • DeMorgan's Theorems describe the equivalence between gates with inverted inputs and gates with inverted outputs. Simply put, a NAND gate is equivalent to a Negative-OR gate, and a NOR gate is equivalent to a Negative-AND gate.
  • When "breaking" a complementation bar in a Boolean expression, the operation directly underneath the break (addition or multiplication) reverses, and the broken bar pieces remain over the respective terms.
  • It is often easier to approach a problem by breaking the longest (uppermost) bar before breaking any bars under it. You must never attempt to break two bars in one step!
  • Complementation bars function as grouping symbols. Therefore, when a bar is broken, the terms underneath it must remain grouped. Parentheses may be placed around these grouped terms as a help to avoid changing precedence.
27 juin

Greatest Common Divisor

Algorithm E (Euclid's algorithm) Given two positive integers m and n, find their greatest common divisor.
 
E1. [Find remainder.] Divide m by n and let r be the remainder.
E2. [Is it zero?] If r = 0, the algorithm terminates; n is the answer.
E3. [Interchange.] Set m <-- n, n <-- r, and go back to step E1.

Start reading The Art of Computer Programming Volume 1

I am feeling a little excited but a little nervous as well when I start reading the book because this is such a great book and very long. haha. I just don't know whether I can continue reading it as I approach the hard part. Well, let's see.
 
 
As I read the book, I will start making notes for it. Here is five important features that an algorithm should have from the book.
 
  1. Finiteness. An algorithm must always terminate after a finite number of steps.
  2. Definiteness. Each step of an algorithm must be precisely defined; the actions to be carried out must be rigorously and unambiguously specified for each case.
  3. Input. An algorithm has zero or more inputs.
  4. Output. An algorithm has one or more outputs.
  5. Effectiveness. An algorithm is also generally expected to be effective. This means that all of the operations to be performed in the algorithm must be sufficiently basic that they can in principle be done exactly and in a finite length of time by a man using pencil and paper.

In practice we not only want algorithms, but also good algorithms. One criterion of goodness is the length of time taken to perform the algorithm and the adaptability of the algorithm to computers, its simplicity and elegance.

25 juin

The History of the Word "Algorithm"

counter free hit invisible 

The word algorithm comes from the name of the 9th century Persian mathematician Abu Abdullah Muhammad bin Musa al-Khwarizmi. The word algorism originally referred only to the rules of performing arithmetic using Arabic numerals but evolved into algorithm by the 18th century. The word has now evolved to include all definite procedures for solving problems or performing tasks.

 

The first case of an algorithm written for a computer was Ada Byron's notes on the analytical engine written in 1842, for which she is considered by many to be the world's first programmer. However, since Charles Babbage never completed his analytical engine the algorithm was never implemented on it.

 

The lack of mathematical rigor in the "well-defined procedure" definition of algorithms posed some difficulties for mathematicians and logicians of the 19th and early 20th centuries. This problem was largely solved with the description of the Turing machine, an abstract model of a computer formulated by Alan Turing, and the demonstration that every method yet found for describing "well-defined procedures" advanced by other mathematicians could be emulated on a Turing machine (a statement known as the Church-Turing thesis).

 

Nowadays, a formal criterion for an algorithm is that it is a procedure that can be implemented on a completely-specified Turing machine or one of the equivalent formalisms. Turing's initial interest was in the halting problem: deciding when an algorithm describes a terminating procedure. In practical terms computational complexity theory matters more: it includes the problems called NP-complete, which are generally presumed to take more than polynomial time for any (deterministic) algorithm. NP denotes the class of decision problems that can be solved by a non-deterministic Turing machine in polynomial time.