I'm looking for a book with the description of basic types of graphs, terminology used in this field of Mathematics and main theorems. All in all, a good book to start with to be able to understand other more complicated works.


Question: Binary tree traversal without using recursion
Answer: As pre-order can be done via depth-first search, it could be done in this way; note that depth-first search is a recursive approach. That being said, I does not need to be implemented by recursive function calls but can be implemented by using a stack as an auxiliary data structure, which effectively is used to generate the visiting sequence which would otherwise be generated by recursion. In pseudocode, this can be done as follows, where visit would be the function to actually visit a node.

push the root of the tree to the stack;
while (stack is not empty)
{
    Node = top of stack;
    visit Node;
    if Node has unvisited left child
        push left child of Node
    else if right child of Node is Not visited
        push right child of Node
    else
        pop;
}