Now a days most websites use the power of AJAX to make their website more lively and productive. To transfer large amount of raw data, that JavaScript can process, the best way is to transfer it as a JSON file. It is quite easy for a PHP script to generate a JSON file from raw data. This data can be received using a suitable AJAX call. As JavaScript can easy parse JSON object, the rest of the processing with the received data can be done using JavaScript.
Showing posts with label Algorithm. Show all posts
Showing posts with label Algorithm. Show all posts
Wednesday, 9 May 2012
Saturday, 28 April 2012
Guide to Good Programming Habits
From a novice programmer to a veteran, there are a few rules to be followed so that the code you write has a professionalism in it. These might be simple things like adding comments or using proper variable names, but following it in a systematic way will make your code more easy to develop, test, debug and deploy. These rules are applicable to any programming language and making it a habit will help you in the long run. In this post, I will explain a few rules that could be followed.
Sorting Numbers Using Bubble Sort
There are a lot of algorithms available for sorting a set of numbers. Here I will give you the logic behind bubble sort and a c++ function implementing the same. The bubble sort can be used to sort a given set of numbers either in ascending order or in descending order in minimum number of iterations. Bubble sort starts by comparing the first two numbers and arranging them in the correct order, then the next two numbers and again arranging them. This process is repeated for all the numbers in the list a number of times until the list is sorted.
Tuesday, 24 April 2012
Factorial Using Recursion
Recursion can be used instead of looping statements to find the factorial of a number. Recursion can be defined in simple terms as a function calling itself. Factorial of a number is the product of all numbers from 1 to the number itself. Example: Factorial 5 written as 5! = 5*4*3*2*1 = 120. Here let us see a simple program that uses recursion to find the factorial of a number. I will be using C++ syntax, but you may take the logic and change the syntax to suit any programming language. In some programming languages, you might get a stack overflow error if you use too much recursion.
Sum of First n Natural Numbers Using Recursion
Whenever you call a function inside the body of the same function, it is called recursion. This technique can be utilized instead of looping statements to find the sum of first n numbers. In this post, I will show you how to implement this. I will be using C++ syntax, but you may take the logic and change the syntax to suit any programming language. In some programming languages, you might get a stack overflow error if you use too much recursion.
Swap two numbers without using a temporary variable
It is a common question in interviews which involve some algorithmic or programmatic requirements. Even though this logic has got nothing much to do in the real world programming, it helps to check the ability of a candidate to form simple logic.
Swapping two numbers means interchanging the value present in the two variables. Normally it can be done using a third variable using the following algorithm.
Swapping two numbers means interchanging the value present in the two variables. Normally it can be done using a third variable using the following algorithm.
Subscribe to:
Posts (Atom)