In the previous post, I’ve explained how to perform a Bubble sort. If you have’nt read it, first read it. In this post I’ll explain how to decrease the number of comparisons in Bubble Sort and thus increase speed.
Bubble Sorting Algorithm is probably the simplest, but slowest sorting algorithm. In bubble sort, we repeatedly compare the adjacent elements until all the elements are sorted. Here is the pictorial representation of Bubble sort
This c++ program can be used to reverse any number. For example, 123 to 321, 7592 to 2957 as so on.. Here is how it works.Continue reading
This C++ program will help you to check whether a number is prime or not. The logic of this program is very simple. Loop from 2 to the half of that number. For example, if you have to check whether 11 is a prime number or not, you’ll loop from 2 to 5 (not 5.5 :P) check whether 11 is divisible by any of the number 2,3,4 or 5. If found, we set flag to zero indicating that the number is not prime. After the loop we print the result according to flag is 0 or 1.Continue reading
This is a very simple c++ program that helps you to check whether an entered string is a palindrome or not. The procedure is simple. We have an array str. We read it from the user. Now we loop upto the middle of the string (len/2) and checks whether 1st character matches len-1th character, 2nd matches len-2th character and so on.. If the string is a palindrome and the break inside the for loop is not executed then the value of i will be len/2 at the end. So we print the result according to i is len/2 or not.Continue reading
In a previous post i’ve explained how to perform a linear search. In this post, i’ll explain another searching algorithm, The Binary Search. Unlike linear search which goes through all elements, binary search starts from the middle of the array and proceeds in a favorable direction. I’ll explain it with an example.
In this post, i’ll explain how to perform search using linear search algorithm If you are a serious programmer, you’ll absolutely come across situations where you need to perform search. So learning searching algorithms is really necessary. Continue reading