menu

Wednesday, February 22, 2012

Algorithms for Complete Beginners : Data Structures

Hellow everyone,

        Thought of compiling a set of articles about algorithms simply for everyone's sake as well as mine. But let me remind that I'm not someone who mastered the art of algorithms, but I have learnt the stuff [thanks to all my trainers ;)] through different means and when it comes to the internet i always found the published articles are way to hard for a complete beginner. So i thought of putting some articles that will suite everyone from the absolute guy who starts today to some professional wanting a quick review. So without much blaaas lets go with it :D

Requirements:
 -> All the coding examples will be done in C++/Java, so it is better if you could have some kinda mid level knowledge about those languages. But on the other hand, if you learn the concepts you could direct them through any language. So i you have just started programming, i suggest first to lookup on sections like Object Oriented Programming & Inheritance related matter and language libraries and functions.

Here we go ----------------------------------------------------------------------------


What are algorithms?
    Well you want be here if you dont know this already, but just to say as something meaning ful algorthims are general applications in solving certain problems [not just problems] but for the sake of the tutorial we'll keep it inside the scope of solving problems. Well in plane english, you should be able to make a computer program to do your math for numbers you can do it by hand.

Wait what about the BIG O and all those crazy stuff?
  Well those are really theoretical stuff but way too much important. Those notations are there to basically give a measurement to memory/time/IO usage of an algorithm or in other words measuring the efficiency. This is important when it comes to real world objectives with limited resources for a huge task. For now i'll not cover them, but once we'are somewhere in the middle, i'll comes back to them. [BTW if you really wanna know, there's a good explanation in the Data Structure and Algorithms in C++/Java books]

What are Data Structures?
    Here we comes to something interesting now. As i said when it comes to algorithms, we always get the need of storing the certain data to be processed through our machine, or the algorithms. Lets take a very simple problem:


Code:
   Problem: Add 2 numbers
   Algorithm: number1 + number2
   Input : number1, number2
   Output: Sum


  Once you see the process, there's a one step missing, what? it is the STORING step. The inputs given by the user should be temporally stored somewhere for our problem solver to process. But where to store?
There comes the Data Structures. Those are the different ways or structures to store data. The quickest in this example will be to store in 2 ints and process. Here it is those are the most primitive types of data structures : The primitives (int,float,double,char,bool). Then there's another well known structure called Array :
    ex: You need to input 100 integers and output the sum once the user input is over
          The best method as you get in your head right now is to make an array of size 100, initialize with the input and process them.
  That's it, although all the structures aren't easy-to-use-and-understand like Array, most of them are built on it ;). Well soon we will be going how exactly is that. There are 1000s of Data Structures out there in 3 main categories:
   1) Primitive Types : As you already know, the primitive variables are the best examples
   2) Composite Types: Most of the time can store a sequence of data and built by using primitives or other composites (Array, struct)
   3) Abstract Data Types (ADT) : Sometimes the most important ones, made by combining one or more composites as well as primitives.

Not all structures are useful for everything, according the place you'll learn to use the correct structure. Each main structure will be explained further when we are constructing them for the use. (The ADTs). Meanwhile feel free to browse and be ready to go with it. I found the wiki article highly factual [but not rather very much meaningful to someone really new] but you can refer to it, as always :D

Complete List of Data Structures:
http://en.wikipedia.org/wiki/List_of_data_structures

What are pseudo-codes?
   Basically it is the textual representation of an algorithm. without telling to add number1 and number2 in plain english we make the thing a bit generalized like this:

Code:
   input number1,number2;
   total <-- number1 + number2
   output total;

I i mentioned before although those theory parts seems non useful at first it comes really really important once the algorithms are far more complex. So knowing your pseudos well is a MUST.!.  
Alright i got your point, I just have to wait till you pull out the show, now what next? :D

What next will be the moving on the real code, one reason for this that most of the articles posted on the subject takes much more time explaining the theory [which is good] rather than the coding, but it makes the reader feel a bit retard like "heyy im waiting for some action". So Le me will be pulling little bits of action while explaining the theories as best as i could. [Usually it means the worst ;)]


Part 2 : Bubble Sort
Part 3 : Selection Sort

CyaH all with the action 

1 comment: