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
Tag Archives: python
A simple Monte Carlo simulation in Python
Monte Carlo is a simulation method that can be useful in solving problems that are difficult to solve analytically. Here’s an interesting application of the technique to estimate the value of pi. Consider a circular dartboard placed against a square … Continue reading
Generating prime numbers using Numpy
I’ve been looking at generating primes, and using various element-wise operations in Numpy arrays to do so. To cut the the chase, prime6 below is the fastest implementation. The ones before that tell the story of how I got there. … Continue reading
Birthday simulations using Python and Numpy
I’ve written previously about the probability of finding a shared birthday in a room full of people. I wanted to run some simulations on this using Python. As an aside, you’ll find some of the techniques below bear a similarity … Continue reading
Dijkstra Shortest Path using Python
This post uses python and Dijkstra’s algorithm to calculate the shortest path given a start node (or vertex), an end node and a graph. The function will return the distance from the start node to the end node, as well … Continue reading
Cyclic Linked List – finding the start of the loop using Python
I’d blogged previously about writing a python function to find out whether a linked list is cyclic or acyclic – it’s worth a read before tackling this one. The challenge here is to return the node that is at the … Continue reading
Anagrams using Python
Python can be an elegant language. This is an example – a Python function that finds the anagrams for a supplied word. For the word dictionary I found one in OS X at /usr/share/dict/words.
Mth to last – a recursive approach in Python
A collegue of mine was pondering the mthToLast problem for a LinkedList I’d blogged about previously and sent me the following IM message: just a guess – but can you use recursion to solve your link list m problem? a … Continue reading
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
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