Showing posts with label algorithm. Show all posts
Showing posts with label algorithm. Show all posts

Sunday, 28 December 2014

Generate trees from materialized paths in Jade

Suppose you have the following objects retrieved from a database, in an array. How would you generate a tree in HTML?

Sunday, 2 February 2014

Tutorial: Constructing Pascal's triangle

Pascal's triangle is made up of several rows of numbers, with each successive row having one more number than the previous row. When the rows are stacked, a triangle-like pattern is formed, hence its name. Each element is the sum of the two elements on top of it. The first element (at the tip) is 1. At the sides, where there is only one element, it will be the equal to the sum of the element above it and zero -- 1.

Sunday, 1 December 2013

The careless mistakes that programmers make

This week has been a busy one, and I do wonder if my sexier-than-ever voice now is a sign that I should take a break. In any case, today I would like to share an "algorithm" I saw at the workplace. It is gentle reminder to always test your code...

Sunday, 27 October 2013

Three Way Handshake

The three way handshake is a simple way to establish communication. It is also useful in daily life, e.g. everyday conversations.

1) The client sends a request to the server. ("Hello, Boss.")

2) The server receives the request and returns an acknowledgement message. (Boss heard the call. He replies, "Yes, Grunt. You were looking for me?")

3) The client receives the acknowledgement message and returns one more acknowledgement message. (Grunt heard the request for confirmation. Grunt replies, "Yes, I have something to tell you." After which he begins to talk about his pay raise.)

Now both sides begin communication. At any time during the handshake, if a reply is expected but none is received after a timeout, the handshake "fails" and the client must initiate it again.

Sunday, 22 September 2013

Tutorial: Finding the greatest common divisor

One of the problems of the Malaysian education system (at least, implementation-wise) is teaching students to use algorithms without properly exploring the principle behind it, or how it "actually" works. I recall like yesterday how classmates in my pre-u classes complain about calculus being "magical". The general teaching pattern is "Just apply this series of steps mechanically, and the correct answer appears" - not a good way to foster independent thinking.

In this article we explore how to find the greatest common divisor, something that is taught in the Form One curriculum.