My practice implementation of a single linked list in Python.

# Category Archives: Featured

# Using The Master Theorem To Find the Big O Of Recursive Algorithms

For some persons finding the Big O of recursive algorithms can prove to be difficult especially if the algorithms are complexed. The Master Theorem provides a relatively simple way to solve recurrence relations as long as the recurrence fits the theorem constraints.

**Basic definition:**

T(n) = aT(n/b) + f(n^{c}) **where** a >= 1, b > 1, and c >= 1

T(n) = Θ(n^{c}) **if** c >= log_{b}a

T(n) = Θ(n^{c} log n) **if **c = log_{b}a

T(n) = Θ(n^{logba}) **if** c < log_{b}a

We can think of “b” as the number of branches and “a” as the number of recurrences done; lets take a look at the example.

**If we have a function:**

T(n) = 2T(n/1) + f(n^{0}) : a = 1, b = 2, c = 0

log_{2}1 = 0 **therefore** c = log_{b}a which satisfies Θ(n^{c}log n) = O(log n)

**References:**

anupcowkur.com

wikipedia.com

# From MATLAB To Python

**MATLAB:**

For many years MATLAB has been my primary tool for prototyping algorithms, because of its rich set of optimization functions and the AI tool box it has proven to be a valuable tool to have. However, It is not cheap and if you do not have a company to pay for license or attend a university that provides you with a license then you will have to find an alternative.

MATLAB is not a programming language rather its a tool that has as part of its framework a programming language called M language, this language has a lot of quirks and takes some getting use to, the other issue I found with MATLAB is that the functions while well documented do not seem to follow a standard in terms of parameters; on the whole while MATLAB is a good tool for prototyping and is used a lot in engineering and medical fields which are my core domain; However,I am forced to look for a cheaper/free alternative that will give me as much if not more tools than MATLAB now provides.

**Python to the rescue:**

Python is powerful… and fast;

plays well with others;

runs everywhere;

is friendly & easy to learn;

is Open

All these wonderful things make Python a big contender for my MATLAB replacement.

The first thing we want to do is install Python.

Next install my favurite Python IDE PyCharm

Create a new Python Project using PyCharm

**How do we add packages to our project?**

Python is nothing without its packages and two of my favourites are numpy and scipy. To add these packages simply download the Anaconda distribution and configure it to be your default python implementation.

And here is my first piece of python code as taken from the python website 🙂

All I need now is a good Python book and 2-4 months to delve into the language. Stay tuned for more posts on my Python journey. Happy coding!!

# DICOM to XML Using MATLAB/JAVA

This little code snippet converts MATLAB Struct to xml, enjoy!!

# Alex Wissner-Gross: A new equation for intelligence

# 2013 in review

The WordPress.com stats helper monkeys prepared a 2013 annual report for this blog.

Here’s an excerpt:

The concert hall at the Sydney Opera House holds 2,700 people. This blog was viewed about

37,000times in 2013. If it were a concert at Sydney Opera House, it would take about 14 sold-out performances for that many people to see it.

# Mapping A Maze Using MATLAB Image Processing Toolbox

Recently I saw an article about mapping a maze and I thought to myself; how could this be achieved using my favorite tool MATLAB :-)? Well it turns out that its a pretty simple task. Some functions used in this post require that you have MATLAB 2012a or higher installed, so if u do not then go away and get it.

Wow you are back, ok so lets begin, first we will look at the code that was used and then further down we will look at individual functions and what they were used to do.

The code:

%% Map Maze clear im = imread('maze.png'); bw = im2bw(im(1:287, 1:400), 0.45); cc = bwconncomp(bw, 8); obj = false(size(bw)); obj(cc.PixelIdxList{13}) = true; sln = bwmorph(bwmorph(obj,'thin',Inf),'spur', Inf); figure, imshow(imfuse(im,sln,'blend','Scaling','joint'))

Explanation:

* clear* Clears all variables from the MATLAB workspace.

**Reads the maze image and stores it.**

*im = imread(‘maze.png’);*

**bw = im2bw(im(1:287, 1:400),****0.45);**Converts the image to binary, scales it and stores it.

**cc = bwconncomp(bw, 8);****Find connecting components within the image.**

*Find the largest component and select it.*

**obj(cc.PixelIdxList{13}) = true;***Use Morphological functions to refine image.*

**sln = bwmorph(bwmorph(obj,’thin’,Inf),’spur’,Inf);**

**figure, imshow(imfuse(im,sln,’blend’,’Scaling’,’joint’));****Overlay and display images**

Result:

The end 🙂