Tag Archives: algorithms

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

Posted in programming | Tagged , , , | 7 Comments

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

Posted in programming | Tagged , , , | Leave a comment

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

More on Linked Lists – flattening and unflattening

More from the Programming Interviews Exposed book (see last post). In this problem you take a double linked list (where each node knows its previous and next nodes) with child elements, and flatten it. Then unflatten it back to its … Continue reading

Posted in programming | Tagged , , , | Leave a comment

Linked List Interview questions

I hadn’t done much programming for a while and thought I’d best brush up on some basic data structures and algorithm. The following is from Programming Interviews Exposed. I implemented some of the Linked List stuff in the first section … Continue reading

Posted in programming | Tagged , , | 2 Comments