Skip to main content

Posts

Featured Post

Convert infix to postfix using stack in Java

Infix Expression : Any expression in the standard form like "2*3-4/5" is an Infix(Inorder) expression. Postfix Expression : The Postfix(Postorder) form of the above expression is "23*45/-". Example :  infix (1+2)*(3+4)with parentheses: ((1+2)*(3+4))in postfix: 12+34+*in prefix: *+12+34infix 1^2*3-4+5/6/(7+8)paren.: ((((1^2)*3)-4)+((5/6)/(7+8)))in postfix: 12^3*4-56/78+/+in prefix: +-*^1234//56+78Scan the Infix string from left to right.Initialise an empty stack.If the scannned character is an operand, add it to the Postfix string. If the scanned character is an operator and if the stack is empty Push the character tostack.If the scanned character is an Operand and the stack is not empty, compare the precedence of the character with the element on top of the stack(topStack). If topStack has higher precedence over the scanned character Popthe stack else Push the scanned character to stack. Repeat this step as long as …
Recent posts

Insertion Sort in Java

Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort. However, insertion sort provides several advantages:
Java Source Code:

Output:Before Sorted: 15 12 1 9 25 7 14 12 10  After Sorted: 1 7 9 10 12 12 14 15 25 

Selection Sort in Java

The idea of algorithm is quite simple. The algorithm divides the input list into two parts: the sublist of items already sorted, which is built up from left to right at the front (left) of the list, and the sublist of items remaining to be sorted that occupy the rest of the list. Initially, the sorted sublist is empty and the unsorted sublist is the entire input list. The algorithm proceeds by finding the smallest (or largest, depending on sorting order) element in the unsorted sublist, exchanging (swapping) it with the leftmost unsorted element (putting it in sorted order), and moving the sublist boundaries one element to the right.
Let us see an example of sorting an array to make the idea of selection sort clearer.

Example. Sort {5, 1, 12, -5, 16, 2, 12, 14} using selection sort.
Java Source Code:

Output:Enter the array size:

Palindrome program using stack and queue in java

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. Allowances may be made for adjustments to capital letters, punctuation, and word dividers. Famous examples include "A man, a plan, a canal, Panama!", "Amor, Roma", "race car", "stack cats", "step on no pets", "taco cat", "put it up", "Was it a car or a cat I saw?" and "No 'x' in Nixon"

Implement the Dynamic Programming-Rod Cutting in Java

Given a rod of length n inches and an array of prices that contains prices of all pieces of size smaller than n. Determine the maximum value obtainable by cutting up the rod and selling the pieces. For example, if length of the rod is 8 and the values of different pieces are given as following, then the maximum obtainable value is 22 (by cutting in two pieces of lengths 2 and 6)

Bloom filter to test whether a given word is in a set or not in Java using MD5 hashing

There are many circumstances where we need to find out if something is a member of a set, and there are many algorithms for doing it. For example a spell checker checks to see whether a given word is in the dictionary. Holding 250,000 words in memory for a spell checker might be too big an overhead if your target environment has low memory.

Find the MD5 hash value of a string in java

Here is the example is show quick way to calculate the MD5 hash of a string. I know things with Java have to be well structured and since MD5 is a hashing algorithm it is fairly logical to be in the security package. On the other hand i think a quick md5 method should be in the String class but that’s just my humble oppinion. Anyways here is how it’s done the Java way.

Convert roman numerals to decimal in java

Read a roman number and convert that into decimal. For such a problem we have to find a suitable solution. we need to write a method to read the Roman number and a converter. there is a  common patterns in Roman numbers and find a solution to convert. For example , " III "means 1+1+1=3 , " V " means 5 " IV " means 4 how ? let see , First read string and check from back to front .so now we have first " V " and " I " .now check last character is grater other one then " - " operator else " + "operator   ( if V > I then 5 - 1 = 4 )