Author Archives: nolfonzo

Reverse a string using recursion in Python

I’ve always found recursion somewhat unnatural to think about, but somehow satisfying when I can see it unfolding in my mind – this simple exercise in reversing a string using recursion is a case in point… >>> def reverse(str): if … Continue reading

Posted in programming | Tagged , , | Leave a comment

Deep copy and recursive references

Quick one about coding a deep copy and avoiding recursive references… Let’s say we have an instance a which has a reference to an instance b and we have to do a deep copy of a. To do this, we … Continue reading

Posted in programming | Tagged , , | 3 Comments

Bootstrapping Zero Curves

What is a yield curve A yield curve is a representation of what interest rates you could lock in today for investments over different periods. It’s effectively a set of yields for securities of different maturities (typically cash rates at … Continue reading

Posted in finance | Tagged , , | 5 Comments

The “Mathematical Constant” and Continuously Compouding Interest

One of the (many) aspects of the “Mathematical Constant” is that: This property makes very useful for working on compounding interest problems. How so? Let’s start with the basic time value of money formula giving the relationship between the PV … Continue reading

Posted in finance | Tagged , , | Leave a comment

Puzzle – Alternating coin toss game

A really simple problem, but needs a trick or two to solve quickly. Question: You take it in turns tossing a coin with a friend – you having the first toss – and keep going until one of you tosses … Continue reading

Posted in mathematics, puzzles | Tagged , | Leave a comment

Puzzle – Roll a die for $

This is an interesting puzzle in that it shows a basic technique used in solving these kinds of probability puzzles, as well as in models for some derivatives pricing, without the need for conditional probability calculations. Hint: start with the … Continue reading

Posted in programming | Tagged , | Leave a comment

Classic Probability Puzzles

1. I have two children. One of my children is a girl. What are the chances I have two girls? The answer to this question is not 50/50. After being told that one of your children is a girl, you … Continue reading

Posted in puzzles | Tagged , , | 7 Comments

Binary Search Tree – Lowest Common Ancestor – Python

The last problem in the Trees chapter of Programming Interviews Exposed was about finding the lowest common ancestor between two nodes of a binary search tree. Starting from the head, if you find that the nodes that you’re looking for … Continue reading

Posted in programming | Tagged , , , | 2 Comments

Tree Traversal – Python

Another question posed in the Programming Interviews Exposed book. A pre-ordered traversal of a binary tree (counterclockwise starting at root, printing nodes as you encounter them) is pretty straight forward, and a very natural thing to implement with recursion: A … Continue reading

Posted in programming | Tagged , , , | 4 Comments

Linked List – Cyclic or Acyclic?

Another problem in the Programming Interviews Exposed book (see previous post) is to determine whether a Linked List is cyclic or not. The most obvious way to do this is to iterate over the list, checking whether the next element … Continue reading

Posted in programming | Tagged , , | 3 Comments