Categories
-
Recent Posts
Recent Comments
Tags
- a-ha moment
- algorithms
- anagrams
- binary trees
- birthday pairings
- Dynamic Programming
- finance
- geometric progressions
- graphs
- interview questions
- linked lists
- logarithms
- mathematics
- monte carlo
- numpy
- permutations
- prime numbers
- probability
- programming
- puzzle
- puzzles
- python
- quants
- recursion
- shortest path
- simulations
- stirling's approximation
- yield curves
- zero curves
November 2024 M T W T F S S « Mar 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Archives
Meta
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
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
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
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
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
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
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
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
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
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