Sunday, April 22, 2012

Depth First Search and Breadth First Search (graph search series)

I shall be writing a series of posts on graph search algorithms, starting from this one.

Depth first search and breadth first search are among the simplest of algorithms and are generally used as a basis for implementing more sophisticated searches rather than just to be used as is. These algorithms are used as a way to traverse the nodes of trees or general graphs in a systematic way according to how the nodes are connected.

Depth first search starts from the root node, or simply the start node in a general graph, process the node, take a new neighboring node and repeat. When there are no more new neighboring nodes to take, go back to the node that got you to the current node, take another new node and repeat. If you go back to the root then you have traversed all nodes and the process ends.

If "O" is an unprocessed node, "X" is a processed node and "(X)" is the current node, here's what would happen to this tree:
_____+-------O-------+
 +---O---+       +---O---+
 O       O       O       O

     +------(X)------+
 +---O---+       +---O---+
 O       O       O       O

     +-------X-------+
 +--(X)--+       +---O---+
 O       O       O       O

     +-------X-------+
 +---X---+       +---O---+
(X)      O       O       O

     +-------X-------+
 +--(X)--+       +---O---+
 X       O       O       O

     +-------X-------+
 +---X---+       +---O---+
 X      (X)      O       O

     +-------X-------+
 +--(X)--+       +---O---+
 X       X       O       O

     +------(X)------+
 +---X---+       +---O---+
 X       X       O       O

     +-------X-------+
 +---X---+       +--(X)--+
 X       X       O       O

     +-------X-------+
 +---X---+       +---X---+
 X       X      (X)      O

     +-------X-------+
 +---X---+       +--(X)--+
 X       X       X       O

     +-------X-------+
 +---X---+       +---X---+
 X       X       X      (X)

     +-------X-------+
 +---X---+       +--(X)---+
 X       X       X       X

     +------(X)------+
 +---X---+       +---X---+
 X       X       X       X

     +-------X-------+
 +---X---+       +---X---+
 X       X       X       X

For this to work you need enough memory for remembering the path you have took to get to the current node, assuming that there is a natural order for accessing the next nodes from the current node (that is, you will not revisit the same next node from the current node twice).

Breadth first search starts from the root node, or simply the start node in a general graph, and enqueues it into a queue. Then the next node in the queue is dequeued, the node is processed, all of its neighboring nodes are enqueued into the queue and repeat. If the queue is empty because no processed node has any neighboring nodes to add anymore, all the nodes were traversed and the process ends.

If "O" is an unprocessed node, "X" is a processed node and "(X)" is the current node, here's what would happen to this tree:
_____+-------O-------+
 +---O---+       +---O---+
 O       O       O       O

     +------(X)------+
 +---O---+       +---O---+
 O       O       O       O

     +-------X-------+
 +--(X)--+       +---O---+
 O       O       O       O

     +-------X-------+
 +---X---+       +--(X)--+
 O       O       O       O

     +-------X-------+
 +---X---+       +---X---+
(X)      O       O       O

     +-------X-------+
 +---X---+       +---X---+
 X      (X)      O       O

     +-------X-------+
 +---X---+       +---X---+
 X       X      (X)      O

     +-------X-------+
 +---X---+       +---X---+
 X       X       X      (X)

     +-------X-------+
 +---X---+       +---X---+
 X       X       X       X

For this to work you need enough memory for remembering the queue of nodes that are next to process. The breadth first search is great for working on graphs with infinitely long paths as it does not get stuck traversing the same path but checks all the paths simultaneously as they are gradually traversed. The nodes on the queue are called the "fringe" as they are the edges of this ever widening circle of exploration.

Here is the pseudo code. We shall be using a successor function which gives a list of the next nodes from a given node in order to keep the algorithms as generic as possible.

Iterative version of depth first search:
sub depthFirstSearch(startNode, successorFunction, nodeProcessor):
  stack = [[startNode]]
  while stack is not empty:
    currSiblings = stack.pop()
    currNode = currSiblings.pop()
    if currSiblings is not empty:
      stack.push(currSiblings)

    nodeProcessor(currNode)
    
    nextSiblings = successorFunction(currNode)
    if nextSiblings is not empty:
      stack.push(nextSiblings)

Of course depth first search is naturally recursive so we can do it like this:
sub depthFirstSearch(startNode, successorFunction, nodeProcessor):
  sub _depthFirstSearch(currNode):
    nodeProcessor(currNode)
    for each nextNode in successorFunction(currNode):
      _depthFirstSearch(nextNode)

  _depthFirstSearch(startNode)

Breadth first search is more naturally iterative than recursive:
sub breadthFirstSearch(startNode, successorFunction, nodeProcessor):
  queue = [startNode]
  while queue is not empty:
    currNode = queue.dequeue()

    nodeProcessor(currNode)

    nextNodes = successorFunction(currNode)
    if nextNodes is not empty:
      queue.enqueueAll(nextNodes)

However, this is what it would look like recursively:
sub breadthFirstSearch(startNode, successorFunction, nodeProcessor):
  sub _breadthFirstSearch(queue):
    if queue is not empty:
      currNode = queue.dequeue()

      nodeProcessor(currNode)

      nextNodes = successorFunction(currNode)
      if nextNodes is not empty:
        queue.enqueueAll(nextNodes)

      _breadthFirstSearch(queue)

  _breadthFirstSearch([startNode])

Friday, April 20, 2012

Finding the median value using MySQL sql

The median of a finite list of numbers is defined as the number in the middle of the list when the list is sorted, or the average (arithmetic mean) of the two numbers in the middle if the size of the list is even.

Since, as I described in my previous post, averages are meaningless when it comes to something like marks, I've decided to start using medians instead since it would be more useful to know in which half of the class you stand with your mark, and medians are much more intuitive than means.

Here is the SQL to find the median in MySQL (adapted from http://stackoverflow.com/a/7263925)

SET @rownum := -1;

SELECT
   AVG(t.mark)
FROM
(
   SELECT
      @rownum := @rownum + 1 AS rownum,
      results.mark AS mark
   FROM
      results
   ORDER BY results.mark
) AS t
WHERE
   t.rownum IN (
      CEIL(@rownum/2),
      FLOOR(@rownum/2)
   )
;

Here's a brief explanation:

In MySQL we cannot use expressions in LIMIT, so instead we have to simulate a LIMIT by using a counter with user defined variables. Each row in the table will have a row number associated with it starting from 0 in the variable @rownum.

We then choose from these numbered rows the ceiling and floor of "(number of rows - 1)/2" which will be the same middle value if the number of rows is odd or the middle two values if the number of rows is even. The variable will still retain its value after all the rows are numbered so we can use it to know the number of rows.

Since the average of one number is the number itself, we can simply calculate the average of whatever is returned without checking. If the number of rows is odd then we shall find the average of the middle value which will remain the same and if the number of rows is even then we shall find the average of the middle two values will will be the correct median.

Don't forget that if you're using this in PHP you have to use two "mysql_query" calls, one for the first SET and another for the SELECT as you cannot use ";" in queries.

Friday, March 2, 2012

The true meaning of the average (arithmetic mean) of a list of numbers!

For too long we have been averaging numbers without knowing what the average really is. The process of dividing the total by the amount of numbers is so simple that we use it whenever we can without realizing what it actually means to do so.

What the arithmetic mean of a list of numbers is, is the number which is closest to all the other numbers. It is the number which when compared to all the other numbers will give the least error. The fact that it is the number which is least erroneous to all the numbers in the list makes it a good approximation of every number in the list.

Given this definition, should the mean be used as extensively as it is? In an exam result, wouldn't it be more useful to know the percentage of students who passed and failed rather than know the average mark? Or the percentage of students that scored each category of marks (A, B, C, etc)? Just by knowing the single approximate mark of every student will not really let you know how good your mark is when compared to every other mark. Percentages would be more useful.

But I digress. Let's focus on what the arithmetic mean really means.

What does "error" mean? If I say 7 when I should have said 5, what was my error? The most intuitive answer would be 2, which is the absolute difference between the two numbers. Let's see where this takes us.

Error as absolute difference
We want to find a number which has the least error when compared to every number in the list. This is less obvious that one might think as there are many ways to interpret such a statement. What does it mean for a number to have the least error when compared to every number in the list? Two ways I can think of are:

The least maximum error
One way would be to find the number which after computing its error to all the numbers, the maximum error it gives will be the least possible.

So if we have a list [1,3,7], the error the number 5 has to each number is [|1-5|, |3-5|, |7-5|] = [|-4|, |-2|, |2|] = [4, 2, 2]. Now pick the maximum error of these and we have 4. Using this interpretation, 4 is the error 5 has when compared to [1,3,7]. Now we want to find the number which will give the least maximum error.

So since we want to find the number which gives the least maximum error, we are looking for a number "x" such that
max([|1-x|, |3-x|, |7-x|])
will be the least possible.

Let's plot the graphs of each "x" separately, that is, y = |1-x|, y = |3-x| and y = |7-x|.


Each graph is a plot of how the error when compared to each number changes as different "x" are used. It is clear that the lines giving the maximum error are the ones highest up, which are the ones belonging to the largest number in the list (green) and the smallest number in the list (red) but only one of them is the maximum error at any point, depending of whether they have intersected or not. So when x < 4, the maximum error is described by |1-x| and when x > 4, the maximum error is described by |7-x|. When x = 4, they intersect and hence give the same error.

The minimum error of of these maximum errors are where |x-1| and |x-7| intersect, that is, at 4. So 4 is the number which gives the least maximum error. This error would be 3. If you try any other number instead of 4 to represent these 3 numbers, the maximum error you will get will be greater.

In general, we want to find where |max_num-x| and |min_num-x| intersect, as these will obviously always be the lines highest up and the intersection will always be their minimum. We notice that the 2 lines above the intersection are y = max_num-x and y = x-min_num so to find the intersection we put "x" subject of the formula in max_num-x = x-min_num (simultaneous equations) and we have
x = (max_num + min_num)/2
so the number which best approximates the numbers would be (max_num + min_num)/2, which is the number exactly in the middle of max_num and min_num. As you can notice, only the maximum and minimum numbers are taken into consideration using this interpretation which will not give a very representative number of all the numbers.

The least sum of errors
Another way would be to find the number which after computing its error to all the numbers, the sum of all errors it gives will be the least possible.

So if we have a list [1,3,7], the error the number 5 has to each number is [|1-5|, |3-5|, |7-5|] = [|-4|, |-2|, |2|] = [4, 2, 2]. Now add the errors together and we have 4+2+2 = 8. Using this interpretation, 8 is the error 5 has when compared to [1,3,7]. Now we want to find the number which will give the least sum of errors.

So since we want to find the number which gives the least sum of errors, we are looking for a number "x" such that
sum([|1-x|, |3-x|, |7-x|])
will be the least possible.

Let's plot the graphs of each "x" separately, that is, y = |1-x|, y = |3-x| and y = |7-x|, together with their sum.


The blue line is the sum of errors. This looks promising. There is a global minimum at x = 3. So 3 would give the least sum of errors when compared to [1,3,7]. But a little analysis of how absolute differences add up together will show that the minimum will always occur at the minimum of the median number, that is 3 in [1,3,7]. In fact if we should try this on a list with no median number, such as [1,3,5,7], the following graph will emerge:


As you can see there is no single global minimum. There is a plateau which spans between the 2 middle numbers 3 and 5 in [1,3,5,7]. Again, just like in the previous case, the median does not take in account all the numbers and so is not a good representative of all the numbers.

Error as a square of the difference
Absolute errors don't seem to be too promising. But we need to somehow make sure that the differences are always positive. We can't have any negative errors as otherwise they will cancel out with the positive errors. One way to make sure we have positive differences is by squaring the differences, since square numbers are always positive, unless they are complex, which is not a relevant issue here.

We shall now consider the two interpretations of "error when compared to all the numbers" again using this definition of "error".

The least maximum error
We now plot the 3 graphs again but this time using y = (1-x)^2, y = (3-x)^2 and y = (7-x)^2.


So what is the maximum error of these errors? Again it's the highest lines which are composed of y = (max_num-x)^2 and y = (min_num-x)^2 so again we will not get a representative of all the numbers because only the maximum and minimum numbers are considered.

The least sum of errors
What happens if we should add the errors together?


Again, the sum is the blue line, and again there's a peak. But this time it's not just a peak, it's a quadratic equation's turning point. y = (1-x)^2, y = (3-x)^2 and y = (7-x)^2 are all quadratic equations and when you add up quadratic equations you get another quadratic equation which will always have a peak. What's more is that it is not just the median as in the previous case, so what is it?

y = (1-x)^2 + (3-x)^2 + (7-x)^2
y = (1+x^2-2x) + (9+x^2-6x) + (49+x^2-14x)
y = 3x^2 - 22x + 59

So the equation which describes the sum of the errors when compared to a particular "x" is y = 3x^2 - 22x + 59. Where is this equation's minimum? Using the quadratic equation formula x@min = -b/(2a) (derived by using differentiation),

x@min = -(-22)/(2*3) = 11/3

Does 11/3 make you think of anything? It's (1+3+7)/3, which is the arithmetic mean of [1,3,7].

In fact if we use a general list of "n" numbers [a_1, a_2, ..., a_n], the sum of errors when compared with "x" will be:

y = (a_1-x)^2 + (a_2-x)^2 + ... + (a_n-x)^2
y = (a_1^2+x^2-2xa_1) + (a_2^2+x^2-2xa_2) + ... + (a_n^2+x^2-2xa_n)
y = (x^2 + x^2 + ... + x^2) + (-2xa_1 + -2xa_2 + ... + -2xa_n) + (a_1^2 + a_2^2 + ... + a_n^2)
y = nx^2 - 2(a_1 + a_2 + ... + a_n)x + (a_1^2 + a_2^2 + ... + a_n^2)

x@min = -(-2(a_1 + a_2 + ... + a_n))/(2n) = (a_1 + a_2 + ... + a_n)/n

And there you have it, the derivation of the arithmetic mean.

So what is the arithmetic mean? It is the number which gives the least sum of square errors. This seems to be the best interpretation of "least error when compared to all numbers in the list" as it considers all the numbers in the list. In fact square errors are a common occurrence in statistics.

It is interesting to note that if instead of squaring we use 4th powers, or 6th powers, or other even powers which also make the differences positive, the turning points will not be at the same value of "x". But we'll leave the analysis of this observation for another post.

Tuesday, February 21, 2012

Why multiplying a fraction by 100 gives the percentage

I remember I had this curiosity about why it is that when you multiply a fraction by a number you get that fraction of that number. Why is it that 1/2 × 5 gives half of 5? Why is it that you find the percentage from a fraction by multiplying that fraction by 100? Why is it that multiplication should have this property?

You might want to look at my previous post which explains what fractions mean.

Percentages
As you should know, if for example you have a 10% income tax, that means that out of every 100 units of income you make, 10 units of them are taxes. So a percentage means the number of units you need to take out of every 100 units of a total. This is why it's called "percent", that is, "per hundred", because you are finding the amount of units you need to take our of every hundred units in the total.

However we can also express this statement using fractions instead of percentages. We can just say that 1/10 of your income is taxes. In fact we can convert fractions into percentages by multiplying the fraction by 100, 1/10 × 100 = 10, that is 10%.

Before we understand percentages, we need to understand fractions of totals.

The statement A/B of C means two things:
  1. As explained in the last post, it means divide C into B equal parts and take A such parts.
  2. It also means A is the number of units to take out of every B units in C.
For example, if we want to take 3/4 of 20,

We can either break 20 into 4 equal parts and take 3 of them:
20 = 5 + 5 + 5 + 5 (4 equal parts)
take 3 of the parts and we have
5 + 5 + 5 = 15

Or we can take 3 from every 4 in 20:
20 = 4 + 4 + 4 + 4 + 4
take 3 from every 4 and we have
3 + 3 + 3 + 3 + 3 = 15

In general, if we want to take A/B of C,
C = C/B + C/B + C/B ... (for B times) (B equal parts, that is, C/B × B which is equal to C)
take A of the parts and we have
C/B + C/B ... (for A times) = C/B × A

Or we can take A from every B in C,
C = B + B + B ... (for C/B times) (that is, B × C/B which is equal to C)
take A from every B and we have
A + A + A ... (for C/B times) = A × C/B

Since C/B × A = A × C/B, we know that the two statements are equal.

Good. So now we return to percentages. The reason why we convert fractions to percentages by multiplying the fraction by 100 is the following:
Given a fraction A/B, when we convert it to a percentage, we are changing the denominator of said fraction to 100 but leaving the fraction equal to A/B, and taking the numerator. So A/B becomes P/100 and P is the percentage.

We are finding a number which when divided by 100 gives the original fraction and therefore the amount of units you need to take from every 100 units of a total such that when you divide the amount you took by the total, you get the original fraction.

For example, if you have a total of 50 units and you want to take 1/10 of the total, the number of units you must take from the total, when divided by 50 must result in 1/10. Likewise, if we change the denominator of the fraction to 100, that is, 10/100, then we say that 10% of 50 units is the number of units we must take such that when it is divided by 50 we get 10/100 (which is equal to 1/10).

Percentages are useful because we would be standardizing the denominator of fractions in order to make them easy to compare. If we wanted to compare 2/4 to 4/16 we can change the denominators of both fractions to 100 (50/100 and 25/100 respectively) and then we will only have to compare the numerators in order to know by how much one fraction is bigger than the other.

So what we're doing is finding another fraction which is of the form P/100. However, P/100 must equal A/B in order to remain the same fraction.

So we have the equation A/B = P/100
We want to find P, so P = A/B × 100 (multiplied both sides by 100)

So if we want to express 2/4 as a percentage,
2/4 = P/100
P = 2/4 × 100
P = 50
So 2/4 = 50/100 or 50%.

I think that the percentage sign "%" can be treated as a symbol representing the constant "1/100". Which means that 50% = 50 × 1/100. This makes sense as in order to go from percentage to fraction form you just change the % back to 1/100 and calculate the expression. 50% = 50 × 1/100 = 1/2.

And this is why percentages work this way.

In general
Now we can generalize this to numbers other than 100. If we use "X" instead of "100",
A/B = P/X
P = A/B × X

By changing the denominator to X, the numerator P will be the amount of units you need to take out of every X units of a total, such that when you divide the amount you took by the total, you get A/B.

So, since P/X is equal to A/B, then just like we can say that P/X means that P is P/X of X, we can also say that P is A/B of X. For example, if 2.5/5 = 1/2, then just like 2.5 is 2.5/5 of 5, 2.5 is also 1/2 of 5.

Why does A equal A/B of B? Understanding what fractions mean.

I believe that the simplest things are often the most complex to understand, because we take them for granted and never question them. But when we do question them, we find that in their simplicity it is very hard to find simpler things into which they can be broken down to. One such simple thing is fractions. Why does the fraction 2/3 mean that 2 is 2/3 of 3? Most of you might be amazed that anyone would ask that. After all, we've been assuming that since we were very young. But challenges are what keep us sharp and what drive us to improve ourselves, so I find the challenge to understand this question inviting.

Notice that I'm assuming that a fraction is made of 2 positive whole numbers. We won't be considering irrational numbers, fractions with other fractions as numerator and denominator or even fractions with negative numbers. General fractions of these kinds will be considered in another post in the future.

Let's start from what a fraction means. 1/B means divide 1 into B equal parts and take one such part. A/B means take A such parts. So 2/5 means divide 1 into 5 equal parts and take two such parts. 6/5 means take six such parts, and so on.

In terms of fractions, "1" is called a "whole". When we divide a whole into B parts, each part is called a "Bth" (for example fourth, fifth, etc) which means 1/B. When we take A of the Bths we say that we have "A Bths" (for example one fourth, two fifths, etc) which means A/B.

Another thing the fraction A/B means is divide A into B equal parts and take one such part. Why is this definition equal to the first definition?

If we divide 1 into B equal parts, each part would be 1/B. But we want to divide A into B equal parts. Since A is A times as much as 1 (for example 2 is two times as much as 1, 3 is three times as much as 1, etc), each of its B equal parts are also A times as much as 1/B. So each part is A × 1/B. For example, if we want to find how big each part of 2 divided into 3 equal parts is, we first see how big 1 divided into 3 equal parts is, which is 1/3, then, since 2 is twice as big as 1, we double 1/3, giving 2 × 1/3.

What is A × 1/B? It's 1/B for A times, that is, A Bths, which is A/B. So we have shown that A × 1/B = A/B and that A/B means both "1 divided into B equal parts and take A parts" and "A divided into B equal parts and take 1 part". So 2/3 means both "1 divided into 3 equal parts and take 2 parts" and "2 divided into 3 equal parts and take 1 part".

Now that we have these two definitions, why does A = A/B of B? Why is it that 2 is 2/3 of 3? First, we must understand what "A/B of C" means.

What does A Bths of C mean? It means divide C into B equal parts and take A of them. Two thirds of four means divide 4 into 3 equal parts, or thirds, and take 2 of them. This implicitly means that A Bths on its own means A Bths of 1. So using our second definition of A/B, we can say that A/B of C is equal to C/B × A.

Does C/B × A equal A/B × C? We'll show this by showing that both of those expressions are equal to (A × C)/B or "the area of a C by A rectangle divided into B equal parts and taking 1 such part". The best way to understand these quantities is through a graphical representation.


The diagram on the left represents A/B × C, that is, a length A divided into B equal parts, extended into a rectangle C long and take one such part. The diagram on the right represents C/B × A, that is, a length C divided into B equal parts, extended into a rectangle A long and take one such part.

Since both rectangles are A by C with the difference that one is a rotated version of the other, and both are divided into B equal parts, we can save that both rectangles are equal to A × C and we are taking one Bth of such a rectangle. So C/B × A = A/B × C = (A × C)/B.

Great, so now we can say that A/B of C is equal to A/B × C, which means that we can just replace the "of" with a "×". So now we have a good understanding of what A/B of C means. Now we move to why A is A/B of B.

What does "A/B of B" mean? It means "divide B into B equal parts and take A such parts" or B/B × A. What is a Bth of B? It is 1/B × B. 1 divided into B equal parts and take B such parts. But then you would be taking all the parts which form 1 again. So a Bth of B is 1, therefore B/B = 1 (unless B is 0 in which case dividing 1 into 0 equal parts will not make sense). So B/B × A = 1 × A which we know equals A.

Great! So now we know that A/B of B is A, that A/B of C means A/B × C, that A/B × C = C/B × A = (A × C)/B and that A/B means both "1 divided into B equal parts and take A such parts" and "A divided into B equal parts and take 1 such part". Next we'll see how these are applied to percentages.

Monday, November 7, 2011

A more complete proof that the square root of 2 is irrational.

I don't know about you but I never quite liked the usual proof by contradiction that the square root of 2 is irrational. It seems incomplete in some way. I never felt convinced by it. Here's what I feel is the missing piece of the puzzle.

Assume that the square root of 2 is rational. So,
√2 = a/b
=>
2 = (a/b)^2
=>
2 = a^2 / b^2
=>
2 b^2 = a^2

So far so good. The usual proof continues with the following statement:

Since a^2 is equal to a natural number multiplied by 2, a^2 is an even number. But for a^2 to be even, a must be even too (see proof in the appendix at the end). So that means that there is a natural number k where a = 2k.

Since a = 2k and 2 b^2 = a^2,
2 b^2 = a^2
=>
2 b^2 = (2k)^2
=>
2 b^2 = 4 k^2
=>
b^2 = 2 k^2

Just like for a, b must also be an even number.

The proof usually ends right there, claiming that since a and b are both even numbers, then the fraction a/b is not simplified and irreducible, contradicting that a/b exists. But let's see where the proof takes us if we just keep on going.

If both a and b are even, then the fraction a/b can be simplified by dividing both a and b by 2, that is, if a = 2k and b = 2l, then we can say that √2 = k/l. But after doing this we can reapply the same reasoning on k and l and we'll discover that k and l are also both even numbers, and we can do it again and again ad infinitum.

So, which natural numbers can be divided by 2 infinitely? Only 1 number can do that, zero. But replacing zero for both a and b will not make their quotient a real number, or if you want to define 0/0, it will not result in a number whose square equals 2. So there is no fraction a/b which gives √2.

So there you have it, a proof that goes on till the end.

===========================
APPENDIX
Now on to the proof that an even square can only come from an even number squared:

Let a^2 be an even number.

a can either be even or odd, that is there must exist an n where
a = 2n or a = 2n + 1
If a = 2n, a^2 = (2n)^2 = 4 n^2 = 2(2 n^2), which is an even number
If a = 2n + 1, a^2 = (2n + 1)^2 = 4 n^2 + 4n + 1 = 2(2 n^2 + 2n) + 1, which is an odd number

So an even number squared will give an even number and an odd number squares will give an odd number. Hence, a square even number can only come from an even number squared.

Wednesday, November 2, 2011

Wisdom hierarchy vs Bloom's taxonomy

So lately I've been reading about two subjects that I noticed are very related, the Wisdom hierarchy ( http://www.systems-thinking.org/dikw/dikw.htm) and Bloom's taxonomy (http://www.odu.edu/educ/roverbau/Bloom/blooms_taxonomy.htm). First I need to explain each.

Wisdom hierarchy
This is a hierarchy of how wisdom is obtained and describes the relationship between data, information, knowledge, understanding and finally wisdom.

Data
Data is symbols and signals which can be observed and analysed, but perhaps not be processed and organized.
An example of this is seeing the symbols "3", "×", "4", "=" and "12". Those symbols may not mean anything to you if you don't know arithmetic.

Information
Information is data which is given meaning and use. It answers "what", "where", "who" and "when" questions, that is, simple shallow questions. It is when relationships are formed between the different data and context is given to the data. The data has meaning but perhaps it cannot be used.
So now "3×4=12" has a meaning. It means that if you multiply the numbers 3 and 4, the result is equal to 12. You may know what the symbols mean but you may not be in a form that is useful.

Knowledge
Knowledge is a mass of information which is organized in a way to be useful. It answers "how" questions, that is how can I use the information. The information may be useful but perhaps you don't understand why it is related and how to generate new information from it.
So now we have organized every multiplication of two numbers we learned into a multiplication table. If we want to know what a particular multiplication equals, we know how to do that, we simply look it up our multiplication table. You may know how to multiply numbers together but you may not know why when numbers are multiplied they give a particular number as a result.

Understanding
Understanding is when you understand the knowledge, when you find a pattern to the organization and can use the pattern to generate new information. It answers "why" questions, that is, why is the information organized as it is in the knowledge. The knowledge may be understood but perhaps it cannot be judged and compared with other knowledge.
So now we understand that multiplication is repeated addition. Now we can add to our knowledge new information which is generated from our understanding rather than from the external world (such as having to ask someone). You may understand how to do multiplication but you may not be able to compare different methods to doing multiplication.

Wisdom
Wisdom is when you can pass judgement and make decisions to determine what is the best method to use. The question it could answer is "which" questions, that is, which is best.
We now can decide which method we should use to multiply two numbers, be it by looking up the multiplication table, by repeated addition or by long multiplication.

Bloom's taxonomy
This is a way of categorizing exam questions in a hierarchy such that as you go up the pyramid, the higher the level of thought required to answer the question.

Remembering
Remembering type questions are those that only require the student to remember things, without expecting any understanding.
An example question would be "What does the symbol × represent?".

Understanding
Understanding type questions are those that require the student to know what the things they know actually mean.
An example question would be "Explain what the expression 2×3=6 means in your own words.".

Applying
Applying type questions are those that require the student to be able to use what they know in a situation.
An example question would be "How many apples would you have if you had 2 baskets with 3 apples in each?".

Analyzing
Analyzing type questions are those that require the student to break down a problem into parts and see how they are related to each other.
An example question would be "What is the next number in the sequence 21, 42, 63, __".

Evaluating
Evaluating type questions are those that require the student to justify a decision.
An example question would be "Which multiplication method would you use to multiply 128 by 64 and why?".

Creating
Creating type questions are those that require the student to create something new to the student.
An example question would be "If all you have is the product of the sum and difference of two numbers and one of the numbers, how can you find the other number?".

Together
It is clear that there is a relationship between the two hierarchies. We could say that:
Remembering type questions test the student having memorized data.
Understanding type questions test if the student has derived information from data.
Applying type questions test if the student has developed a useful knowledge from the information and if the knowledge can be readily used.
Analysis type questions test if the student has understood the basis of their knowledge and can derive new information from it.
Evaluating type questions test if the student has obtained any wisdom on the subject and hence can make sound judgement about it.

The last question type, creating, is not covered by the Wisdom hierarchy and perhaps it predicts yet another higher level form of cognition, perhaps called "creativity", which is when you use knowledge, understanding and wisdom together to derive new knowledge, understanding and wisdom, where knowledge provides the raw material to act on, understanding provides the ways to rearrange the knowledge and wisdom guides you into choosing a solution path which is most likely to give good results. Once this is done you will have learned from experience and would have added new knowledge, a deeper understanding of that knowledge together with new ways of using it and you would be able to make better judgement in the future.