Programming Defined / Algorithms
Subtitles of the Movie
In this video we're going to take a look at what algorithms are and what they are in relationship to programming. So an algorithm is a well-defined set of instructions for accomplishing some task. So what we mean by well-defined is that every instruction is very clear in what it does, along with that there must be a clear path on how, or what the next step is from a particular instruction. There must be a definite stopping point. Somehow that algorithm stops; either exits out, say, if it's a function or something, or it actually stops processing. This is the definition and it's a pretty formal definition of an algorithm. The main things to draw from it are that you have very clear instructions and you know how to get from line to line in those instructions and you have a very clear stopping point or stopping definition. In programming, specifically, we draw from algorithms, essentially creating the program from those algorithms. So an algorithm, if you want to think about it, is how you go about doing something; solving a particular problem if it's mathematical in nature there are a certain number of steps you go through to solve it, or even common things in life. Now, my little example here I've written out in English in outline form is starting the car. So we have the first, we're going to give it a title, because you have to have a title - Starting the Car - so the first thing is you're going to open the door, sit in the driver's seat, you're going to insert the key into the ignition, turn the key, and the car starts. Now that's an algorithm in a very general form, very short-handish, doesn't have a lot of the details or anything that we really need to accomplish this if we haven't done this before. It's a good instruction if you've done it before or done something similar, you know, start the truck, uh, if you've done that you can start the car, here's how you've got to do the car. But let's change the form a little bit and put it into an outline, or excuse me, into a flow chart form. For a flow chart form we start at the top here, and we have Start Car, and this particular object means is essentially a starting point, and these boxes mean different things occur. So the first thing again, is open the driver's side car door, sit in the driver's seat and insert - so it's the same thing and we have a conclusion down here. So as far as an algorithm we have, you know, some relatively clearly defined steps, we have very clearly defined flow where we're going from one instruction to the next and we have a definite stopping point. But when you tink about this analogy or this particular algorithm you start realizing that, well, this isn't all I need to know. And if we expand this just a little bit, include a few things that are needed, and we start up at the top here, well, to start the car you're going to need a key. So even before you can start this thing you're going to need a key. So I get the key. You open the driver's side car door. Well, even there, that's a multiple step process there. The first thing is the door locked? Well, if it is, insert the key into the lock. Does the key work? Yep. Okay, unlock the door. Does the key not work, or does the key work? No. We're going to have to go get the right key and we'll stay in that loop until we get the right key. So you can see right here we have a decision, two decision things, and these equate in programming, when we get to that point, to "if" statements, and this is a type of looping structure here and you can actually see the loop inside this decision process here. Okay, so the car door, even if it is or isn't locked we end up back here, you can see, through both these paths, so we open it, and again there's a whole bunch of steps that you could go delve however deep you want to in there to include put your hand under the handle, lift the handle up and that's depending on the type of door, maybe you have to open it with your thumb, there's tons of things inside of here. Now you sit in the driver's seat, again, you've got to, you know, how detailed do you want to get because you can talk about how you move your legs, and how you bend and all those types of things. Insert the key into ignition - same thing. Lots of extra steps that we're leaving out here but in a broad overview it works. Turn the key to start, to the start position, does the engine turn over? Again we're at a decision point here, ah, no, well the battery is dead and you've got to get a mechanic. Stopping point. Does the engine start? No. Car not working, get a mechanic. Does the car start, Yup. So the main thing to look at drawing from this aside from the fact you can still see it's clear where you go from step to step even though we have some complexity with these decision trees, it's still very clear how you go from one step to the next. Each instruction is fairly well-defined, again, I know there's some ambiguity involved because of how broad these are, but in the sense here, if you have some common sense, these make sense. So you can go from one to the next, and we have two definite stopping points. So this qualifies as an algorithm in the broader sense, not in the strict mathematical sense, and you know, if we had a program, this wasn't opening the car door, but it was a program to do something, this is a relatively easy leap from here to actually writing programming code, because you already have your logic in place of how you flow from one instruction to the next, how decisions happen here, and how you stop or how you get out of this program. So that's basically an overview of algorithms. I'll be sharing various algorithms and other videos with you, some of them mathematical in nature, and you'll see how you can go from an algorithm to a program. If you have any questions you can contact me at this address: lavtc@gmail.com.
Tutorial Information
| Course: | Programming With Ruby |
| Author: | Al Anderson |
| SKU: | 33788 |
| ISBN: | 1-934743-01-1 |
| Release Date: | 2007-08-21 |
| Duration: | 8.5 hrs / 113 lessons |
| Work Files: |
Yes |
| Captions: | For Online University members only |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 81,350 Video Tutorials (20,800 free)
- Video Available as Flash or QuickTime
- Over 782 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 