Category Archives: Uncategorized

Algorithms – Computer Programming’s Foundation

To many, computer programming seems an arcane topic, particularly when first introduced to it. Students learn variables, constants, conditionals, control flow, and numerous other topics. What is often lost – especially in these neophyte to guru in twelve weeks or less boot-camps – is what actually underlies all the arcane symbols comprising a computer language.*see note below

“Computer science is no more about computers than astronomy is about telescopes.”
Edsger W. Dijkstra

Edsger W. Dijkstra

Computer science, and by extension computer programming, is about problem solving. By itself, a computer is a particularly dumb conglomeration of silicon, wires, and aluminum. It does nothing but store and transport electrical charges from one location to another internally. It is not until a human, through his or her intellectual labors, harness the flow of the charges to perform some task that a computer does anything particularly interesting.  But getting computers to do something interesting require a systematic approach to performing tasks. Every step must be specified in detail and you must ensure not to overlook steps. You must devise a detailed procedure for the computer to follow to perform a task. That is computer programming’s essence: write procedures that dictate how a computer solves a  particular task.

So if computer science is not necessarily computer programming, then what exactly is computer science?  Of course, computer programming is an element of computer science, but what is computer science? The following video by “Art of the Problem” on YouTube explains.

Computer science is the science of computation. How to get computers to solve problems. The math behind pushing the boundaries of what computers can and cannot do is staggering. But this is the theoretical side to computer science. Consider the practical. A computer language is a set of instructions that humans can write to have a computer perform tasks. But as computers are dumb, those instructions must be explicit and accurate. Writing accurate instructions to perform a task require an accurate underlying algorithm.

Algorithms

Webster’s dictionary defines an algorithm as “a step-by-step procedure for solving a problem or accomplishing some end especially by a computer <cite here>.”  Here’s a humorous, yet insightful, video clip from “The Big Bang Theory” illustrating an algorithm.

A clip from “Terminator Two: Judgement Day” provides another more graphic, yet still humorous, example of an algorithm.

In the above clip, the Terminator uses one or more algorithms to obtain clothing. From visual input, he calculates the attributes of features such as height, weight, and foot size to determine the probability a person is a match. If not a match, he moves to the next person. If a match, he persuades the person to remove his or her clothes.

Computer programming is formalizing algorithms into a form usable by a computer. Algorithms are the solution to a task/problem. Code is the instructions performing the algorithm. The following video by “Art of the Problem” on YouTube introduces algorithms.

The above video assumes some knowledge of looping and conditional logic. However, if you are reading this as a supplement to “Think Java” then this post only assumes familiarity through chapter four of the book. This chapter introduces you to methods that do not return a value. You have not been introduced to methods that return values, looping, or conditional logic. So let’s consider another algorithm, purposely ignoring concepts not yet covered in “Think Java.”

Consider the task of boiling water. The following steps outline a basic algorithm.

  1. Get pot from cabinet.
  2. Take pot to the sink.
  3. Turn on water facet.
  4. Place water in pot.
  5. Turn off water facet.
  6. Place pot on stove.
  7. Turn on stove burner.
  8. Heat water until boiling.

The steps seem easy enough, but remember, computers are very dumb. These instructions are not explicit enough. For instance, consider the sub-steps involved in obtaining a pot from the cabinet.

  1. Walk over to cabinet.
  2. Open the cabinet.
  3. Reach into the cabinet.
  4. Grasp pot handle.
  5. Lift pot and take it out of the cabinet.

But of course, computers are too dumb to even understand these instructions. For instance, consider the sub-steps involved physically perform the first step, first sub-step.

  1. Turn body in direction of cabinet.
  2. Take alternating right and left steps until cabinet is reached.

But even still the computer is clueless, as these sub-sub-steps remain ambiguous. We could continue to break the steps down to the most fundamental level. For instance, instructions on how to move each muscle when walking to the cabinet.

Understanding muscular contractions is obviously taking our algorithm to a level too fundamental to be useful. Thankfully, algorithms build upon previously solved algorithms, which can be reused as a “black box.” But before considering algorithm reuse, first consider how to decompose an algorithm into more manageable sub-tasks through a process called functional decomposition.

Functional Decomposition

Functional decomposition is explained well by the following.

Societal Impact

There is a downside to our rush to formalize all problems into formal algorithms. We use computers to decide everything from product

Sometimes a computer’s formalization leads us to eschew common sense. And think about this last clip. Politics aside, I leave you with this vision of our near future. It’s not science fiction, it will be reality within a few decades at most.

* This post is particularly directed towards students that have completed chapters one through four of the book “Think Java.” by Allen B. Downey & Chris Mayfield.Note in this post I specifically avoid discussing repetition and conditional algorithms, preferring to keep this post simple. I also avoid discussing Object-Oriented analysis and design. Here, I focus on simple algorithms and functions. It is my personal belief, that understanding simple functional programming helps transition to Object-Oriented programming.

SSH, AWS, and The Cloud for the Layman


 
Cloud computing is the future of computing. Amazon Web Services (AWS) currently provides the most comprehensive cloud computing solution. To the layman, cloud computing probably sounds like just more computer jargon best left to nerds. But it’s not; all educated adults should understand cloud computing – at least on a non-technical level.

I have three servers – all three of which used to dramatically raise my monthly electricity bill – sitting in my closet. But now they sit there with the power button switched off. Instead I use AWS. AWS saves me money in electricity and is easily accessible over the Internet from anywhere. I couldn’t access the three servers sitting in my closet from anywhere outside my own personal network; the security risks were too great and the configuration details to big of a pain in the butt. Not so with AWS, now I can access my virtual server(s) residing on AWS from anywhere in the world.


 
In fact, I use AWS to provide a uniform computing environment for students in my introduction to programming class. On AWS I have a virtual server that is one of many residing on one of Amazon’s physical computers. I access that virtual server as if it was a physical computer via the command-line on my local computer. The communication between my personal computer and the server is accomplished using SSH over the Internet. I created accounts on the virtual server for each student. Each student uses ssh over the Internet from his or her personal computer to connect to the virtual server. The student then interacts with his or her account on the virtual server via the command-line. The actual programs the student writes, the software tools used to write and compile the programs, and the file system used to store the student’s work all reside on the virtual server residing in one of Amazon’s physical servers. This is but one use of cloud computing.

In this post I discuss the technologies behind using a virtual server on AWS. Let us explore each of the technologies involved in using a virtual server residing on AWS from a personal computer. This post is not a comprehensive technical tutorial on each technology, but rather, a layman’s introduction.

The Internet

How does one explain how the Internet functions to someone with little to no technical background?  This video does a good job explaining how the Internet works on a non-technical level.

Amazon’s servers are connected to the Internet.  This allows communicating with them. However, hackers lurk everywhere and so communication must be secure and so typically you use a secure shell (ssh) to communicate with the server from your personal computer. But understanding ssh requires understanding the command-line.

Command-line

If you already know what the command-line is and why you might use it, skip to the next section. Otherwise, you should watch the following video before continuing. Before the fancy graphics on your computer were standard, there was the command-line. Users interacted with computers via a simple text interface. Even today, that simple text interface is how most users communicate with a remote server.  Let’s explore the history of the user interface so you have a better understanding of the command-line.

Secure Shell

Just as a browser on your computer can connect to a remote computer through the Internet and display web pages, your computer can also connect to a remote server through the Internet using Secure Shell (SSH) and display text input and output. This video explains how SSH works on a non-technical level.

Cloud Computing

Okay, but what about Amazon Web Services, Cloud Computing, and all that nonsense? Why the fuss?  Let’s take a step back and get a 5 minute non-technical history of computing and cloud computing narrated by none other than Stephen Fry.

Now, remote physical servers, accessed from anywhere in the world is nothing new. Moreover, having space for your website – for example housing your site on a provider such as GoDaddy – is not new. But cloud computing is more than simply providing space on a server to house you webpage. Cloud computing gives you unprecedented access to that remote server’s computing power. Moreover, it provides that access securely and ensures your work doesn’t impact other users also using that server. To understand how, you must understand something called virtualization. Virtualization provided over the Internet is what allows ubiquitous computing power to everyone…well, everyone that can pay for it (but that’s a different blog post).

Virtualization

A virtual machine is a “pretend computer” that runs on a physical computer. For instance, a Mac user might use VMware Fusion to run Windows or Linux on his or her physical Macintosh computer. That same technology allows a physical server to run multiple “pretend servers” on its hardware.

So a few years ago, some enterprising employee noticed that much of Amazon’s vast computing power went unused. Yet Amazon was still paying for that unused computing power. Why not rent that power out? Enter the virtual machine. Amazon would allow folks to create their own virtual machines on Amazon’s physical computers and pay only for the computing power actually used – essentially “renting” the computer. This simple idea has spawned an entirely new business for Amazon that is arguably poised to make more profit than even their online marketplace. Entire corporations can throw away their physical servers and instead “rent” space on Amazon’s physical servers that run virtual machines.

Amazon Web Services

Here is a video explaining Amazon Web Services for non-technical folks. Keep in mind, behind the strange lingo and explanation, fundamentally you can explain cloud computing quite simply. As already discussed earlier, instead of owning the computer you run software, you rent space on Amazon’s server and it runs the software. But you are not simply renting space, you are running your own computer on Amazon’s computer using virtualization.

And another video by Amazon on cloud computing using AWS.

Conclusion

Cloud computing allows a lowly adjunct instructor at a community college (me!) to offer his students the same computing power that an MIT or Carnegie Mellon could offer its students. In less than an hour, while sitting in my study on a Sunday night, I was able to accomplish what would have taken days several years ago.


 
And rather than relying upon the college to house and maintain costly physical servers on campus, I will pay less than five dollars for enough computing power for an entire semester of approximately twenty-five students writing and compiling homework assignments. That is powerful stuff right there. It’s game changing.