Compare two string literals

public boolean compare(String text1, String text2){  
if(text1\=\="" && text2!\="")  
   text1\=null;  
if(text2\=\=""&&text1!\="")  
   text2 \= null;  
if (text1\=\= null && text2\=\=null)   
         return true;  
if (text1.length()\=\=0 && text2.length()\=\=0)   
         return true;  
if (text1.length()\=\=0 || text2.length()\=\=0)   
         return false;  
if (text2\=\=null || text2\=\=null)   
        return false;  
  
      return text1.compareTo(text2);  
  
  
}  

Anagram Checker–To check if 2 strings are anagrams

An anagram is a type of word, the result of rearra… Unknown - Jul 1, 2014An anagram is a type of word, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once. For example: orchestra can be rearranged into carthorse or cat can be rearranged into act. We can find out the anagram strings using below algorithm: [Read More]

Anagram Checker–To check if 2 strings are anagrams

Problem  Wap to find out if 2 strings are anagrams or not. Anagrams Two words are anagrams if one of them has exactly same characters as that of the another word. Example : Anagram & Nagaram are anagrams (case-insensitive).Similarily, abcd and abdc are anagrams, but abcd and abdce is not. Solution A simple way to check if two strings are anagrams is to find out if the numeric sum of the characters in the strings is equal. [Read More]

All permutations of a string

small trick ,but a very nice solution for duplicat…

nikhil - Feb 4, 2014

small trick ,but a very nice solution for duplicates!!!!

Thanks Nikhil. :)

can u please write the main function for duplicate program. I ran the duplicate program and it is not giving me the desired output

All permutations of a string

Problem Write a method to compute all permutations of a string. Example For a string of length n, there are n! permutations. INPUT: “abc” OUTPUT: “abc” “acb” “bac” “bca” “cab” “cba” So, we have 3! = 6 items for string abc. Solution There are several ways to do this. Common methods use recursion, memoization, or dynamic programming. The basic idea is that you produce a list of all strings of length 1, then in each iteration, for all strings produced in the last iteration, add that string concatenated with each character in the string individually. [Read More]

Anagram Trees : Part 2

One nice thing about working at Google is that you are surrounded by very smart people. I told one of my coworkers about the anagram tree idea, and he immediately pointed out that reordering the alphabet so that the least frequently used letters come first would reduce the branching factor early in the tree, which has the effect of reducing the overall size of the tree substantially. While this seems obvious in retrospect, it’s kind of unintuitive - usually we try to _increase_ the branching factor of n-ary trees to make them shallower and require fewer operations, rather than trying to reduce it. [Read More]

Secure permutations with block ciphers

It’s been too long since I blogged about anything much, and way too long since I posted the first Damn Cool Algorithms post, which I promised would be a series. So here’s part 2. To start, I’m assuming you know what a permutation is - basically a shuffling of a sequence of items in a particular order. A permutation of the range 1-10, for example, is {5,2,1,6,8,4,3,9,7,10}. A secure permutation is one in which an attacker, given any subset of the permutation, cannot determine the order of any other elements. [Read More]

C Strings

Strings are arrays of chars. String literals are words surrounded by double quotation marks. "This is a static string" ```To declare a string of 49 letters, you would want to say:``` char string\[50\]; ```This would declare a string with a length of 50 characters. Do not forget that arrays begin at zero, not 1 for the index number. In addition, a string ends with a null character, literally a '\\0' character. [Read More]

Reducing the space for LCS lengths

When you’ve run out of main memory, any estimate of runtime based on big-O analysis becomes useless. The system either crashes or thrashes, paging in virtual memory. By contrast, if we can reduce the memory required by a program, the time analysis should still hold — we never have to page in more time. Once you’ve watched the dynamic programming solution a few times, you’ll realise that the LCS lengths (the numbers in the grid) are computed row by row, with each row only depending on the row above. [Read More]