Archive

Posts Tagged ‘Algorithms’

Why randomization is a difficult algorithm to implement?

If you are doing programming, You must have used random numbers. They are useful in many situations when you want to give some randomization to your program output like lottery draw, random banners generation, random user display etc.

In PHP rand function is being used to generate random numbers, but is it really random number generator? Take a look at the following code.

< ?php for($i=0;$1i<50;$i++) { print rand(); } ?>

What this function will do? If you are thinking that it will produce 50 random numbers, you just need to run this code. It is very likely that you will get the same number fifty times. Why rand function is not generating random numbers? Lets me introduce another function srand which is short for seed rand or seeding rand.

What is seeding? seeding in random number generation is they key to uniqueness. If you are not feeding a good seed to your random number generator, you are out of luck.

Why it is so difficult to implement random number generation algorithm?As per definition of algorithms, they are set procedures to solve a given problem. they can be repetitive and usually they are consistent in number of steps, in short they have a pattern. Random number on the other hand are supposed to break pattern. Random number generation is actually finding a pattern which should output a result which should break pattern. Thats why it is difficult.

Seeding is important to random number generation. Many algorithms even require more than one seed to do generate better random number.

In computer science, we are normally dealing with pseudorandom random numbers. Liner congruential generator also known as LCG is one of the oldest and best-known pseudorandom number generator algorithms

Categories: PHP Notes Tags: ,

6 Algorithms you must know to be a good programmer

Algorithms are defined sets of instructions to solve a problem or achieve something. Almost every process in computer world can be classified as an algorithm, still it is most difficult part of computer science for many learners.

Algorithms are necessary to make your programs intelligent and efficient. They can make your program rock and it can stand out in front of competition. You need to be good at analysis, understanding and draw abstraction to get good hold on this subject.

In this post I am trying to compile a list of algorithms which every program should know. This list is not exhaustive and only indicative of some important sections of computer programming.

Sorting

Visualization of sorting algorithms experiments
You must be good at different kind of sorting algorithms like quick sort, bubble sort, merge sort, heap sort and many other useful sorting techniques. You must be able to differentiate between these algorithms based on their features, problems and potential usage scenarios. Try your hand with different combination of algorithms, who knows you can discover a new optimal algorithm while doing so.

Binary Search

binary search tree
This algorithm is necessary to be in sync with higher efficiency demand  which big data is presenting in front of programmers. Many databases are using this Binary search algorithm to provide quick query answers and it is also useful in many other scenarios.

Graph Search

Twitter social graph (social dances)

In this social network era, this algorithm is one of most needed and used algorithm. Many Algorithm like shortest path etc falls under this category. This category of algorithm is usually considered most difficult one to understand as it involves lots of dynamic variables. Knowledge of calculus in math really help in understanding this subject. Once you got the idea behind graphs, you can rock those optimal solution problems.

Stable Marriage

Do you know computer science can help you to find a good life partner or friend? This algorithm try to solve this problem in a given scenario where priorities of available people are dynamics and not linear in nature. This algorithm usually works to suggest good friends and life partner on may social networking or dating websites.

Map Reduce

MapReduce

Many algorithms has been developed to deploy MapReduce which is essential in developing distributed applications handling large data. This is essential part of Hadoop system using which we can run parallel processes to process a large amount of data.

Hilltop Algorithm

Many search engine marketers knows this algorithm which was initiated by Google to rank pages based on some kind of reference values. This algorithm (or similar algorithms) is necessary to dive into large amount of data which our world is generating everyday. Now we are facing a hill task to find useful data or pattern from so much of data noise, hill top can help in this.

 

There are many hundreds algorithms but you can start with these algorithms before you go to your journey of mastering this interesting subject.

 

One major thing which needs to be understood regarding algorithms are their patents. Many algorithms are patented and can not be used in our programs without a license.  So be sure that you are using an algorithm which you are entitled to use in your commercial programs for distributions. Many algorithms has been released under open source licenses.