Wednesday, July 30, 2014

Insertion Sort Java Implementation

When we talk about algorithms, Sorting and Searching is quite significant. There are few sorting and searching algorithms. Today I'm going to present you the java implementation of Insertion sort.

int[] insertion_sort(int[] x){
    int key = 0;
    for(int j=1 ; x.length > j ; j++){
        key = x[j];
        while(i > 0 && x[j] > key){
            x[i+1] = x[i];
            i = i - 1;
        }
        x[i+1] = key;
    }
    return x;
}
In the next post I hope to implement quick sort.   
References : Introduction to Algorithms 3rd ed. T. Cormen...

Tuesday, July 29, 2014

Languages : How a computer understands different languages

We know that you can write computer programs using different computer languages such as Java, C. But the problem is how the computer understands all the instructions given in those languages. It is very simple to understand when we think a computer as a living object.

Each and every one of you have a mother language. You can understand instructions which are in your mother language without any problem. Computers also have a mother language. It is machine language (known as binary language, alphabet with 1s and 0s). Computer can understand instructions which are in machine language.


As you grow you will learn different languages(for an instance : French). After you have learnt french you will understand french instructions also. You will receive the french instructions and you will translate it into English or into your mother language. Then you know what to do. You will act according to the instruction. In computers, same thing happens. You give instructions to the computer in JAVA. JAVA compiler will translate your source code in to machine language. Then computer understands the instructions.

That's why you need a compiler and that's how a computer understands different languages. It is more like you learn a different language.

Monday, July 28, 2014

Generate Dynamic PDFs : Implementation in PHP

In this post we are going to discuss how we can generate Portable Document Files using PHP. Creating PDFs dynamically is very importent especially when we have dynamic data. Actually this is very easy since we can find pre-developed library.

You should download fpdf.php file first.
Then you can create PDF.php file as follows.

require('fpdf.php');
class PDF extends FPDF {
     
 function Header() {
  //write your own code segment
 }
  
 function Footer() {
  //write your own code segment
 }

Now you're ready to generate PDF files. Refer this code.

require('pdf.php');
$pdf=new PDF("P","mm","A4");
$pdf->SetMargins(25.4,25.4,25.4);
$pdf->AddPage();
$pdf->Cell(30, 5, 'This is the Fist page');
$pdf->AddPage();
$pdf->SetY(25.4);
$pdf->SetFont('Arial', 'BIU', 12);
$pdf->Cell(0, 5, 'Sample Text', 0, 1);
ob_start();
$pdf->Output();//pdf will be downloaded
ob_end_flush();

Sunday, July 27, 2014

Hanoi Tower Implementation in C

Here I am supposed to implement only the function which will print the instructions to move plates.

void hanoi(int n,char source,char temp,char dest){
        if(n>0){
                hanoi(n-1,source,dest,temp);
                printf("move plate from %c to %c",source,dest);
                hanoi(n-1,temp,source,dest);
        }
}
If you have read my previous post, I think you can understand this function. Feel free to use this code. Enjoy hanoi tower. Try this function with n=32. You will understand how slow your computer is. Good Luck!

Friday, July 25, 2014

Divide and Coquer Algorithms



I have seen a lots of students feel it is difficult to develop Divide and Conquer Algorithms. It’s my pleasure if this document can help those students to have a proper understand of Developing Divide and Conquer algorithms. Let’s move onto the topic. In this discussion we will take Factorial as an instance.


  1. You have to see that there exists smaller version of same type of problem(s). Solving these smaller versions should be easy than the original one. Further Results of these smaller versions should lead us to solve the original problem.
    Let’s think we have to find factorial of 6. Here we can see that if we know factorial 5 we can multiply it by 6 and find factorial 6. Actually it is easy to solve factorial 5 than factorial 6.
     
  2. Another thing you have to understand is base case. You must know the result of the base case.
    Base case of our example is we know factorial 1 equals to 1.
     
  3.  Here we are going to learn a very important point. That is you should have self confidence that the function you’re going to write, gives the correct answer.


Accordingly we can develop our function to calculate factorial of ‘n’.
 int factorial(int n){
/*since we know the result of the base case, 
we check input whether it is base case*/
     if(n == 1){

//Yes it is base case. Now we can return our known value
          return 1;
     }
     else{
/*Oops. It is not the base case. We don’t know the answer.
But if we know factorial n-1, we can find factorial n. Let’s 
move in that direction using our same function since we 
believe it returns the correct value*/
          return factorial(n-1)*n;
    }
}

Let's think in a different way.

All the students knows the answer to factorial 1. But no one knows the answers for higher numbers.

If someone ask me the answer for factorial 3, I will ask Mr. A to find the answer of factorial 2. Until he send me the answer I have to terminate my calculation.

Since he don't know the answer for factorial 2, he will ask Mr. B to find factorial 1.

Awesome. Mr. B knows the answer. He will send answer as 1. Then Mr. A can calculate his answer 1 x 2 = 2. Then I will recieve the answer for factorial 2 from Mr. A.

Now I can find factorial 3. That is 2 x 3 = 6.

That's how it works. I think you will benefit of this document. If you have any doubts feel free to contact me.



Thursday, July 24, 2014

Yes, It's Blogging

Hi, This is going to be my first blogpost. I hope to share my computer knowledge with world. Sometimes it will help me to remind what I have learnt and also I will be able to learn from the reader.

First of all I would like to share some of my cantact details with you.
You can visit my LinkedIn profile to view more information about me.
Further you can reach me via Email and follow me on twitter in order to get updates.

Today, everythings is about Computers and Software. I will be publishing contents from the beginning. You will not be find it is hard to learn. I will begin from simple programming and I don't sure where I will stop. You can ask any question from me. You can make me correct if I'm wrong. Specially I hope that from you.

Invite your friends. Read the posts. Discuss. Clarify. Learn and Apply.

Thank you.

Salesforce Metadata Deployment

Salesforce Metadata Deployment What are metadata? Let's understand this through a simple example. Imagine you are a Salesforce Admin an...