Group together all the anagrams [closed] - algorithm

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Problem statement:
You are given a set of k strings, each length n. You have to output the group of anagrams together. Anagrams are like e.g atm - mat , like-kile.

Just sort the word's letters to obtain a signature that's anagram-specific. E.g., in Python,
sig = ''.join(sorted(word))
and make a dict with sig as the key and the value being a list of words with that signature (defaultdict(list) works well for this). Of course, you can do it in any language with sorting abilities, and associative arrays whose values can be lists or vectors;-).

Related

and conquer algorithm - search for pattern in string [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am trying to write a divide divide-and-conquer algorithm in pseudocode that finds how many occurrences of a 3-letter pattern there are in a given string of n letters.
Something like this in pseudocode:
the pattern is fixed: XXY
int searchString("CDSXXYZSE")
.
.
search for "XXY"
.
.
return (1)
Or
int searchString("CDSXZXYZSE")
.
.
search for "XXY"
.
.
return (0)
Thank you all for your time!
in the divide step i would split up your string parameter into all possible 3-letter combinations, in your example (CDS, DSX, XXY ...). Then test equality to the searched pattern and add up the number of matches in the conquer step.

Design a data struture for integers of range 1 to 1000(non repeating) for basic operations in O(1) [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
Design a data struture for integers of range 1 to 1000(non repeating) for following operations.
1)Insertion
2)Deletions
3)Search
4)int Anyvalid() -> This should return any valid/present number present at the time.
Example if 1,5,7
are present,then return any of the 3 number.
All the operations should be 0(1)/Constant time.
I thought of bit vector but it give 0(n) in case of AnyvalidElement()..
for rest all it works in 0(1).
Use a doubly linked list and an array of pointers to the list nodes.
Insert n: Add n to the front of the list, array[n] = pointer to newly
added node.
Delete n: Use array to jump to the correct node in the
list and remove it. Set array[n] = NULL;
Search n: check if array[n] != NULL
AnyValid: return front of the list

adding numbers in base n [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I came across this question and couldn't figure out how to approach it. Can someone please help me out? The question is-
Add numbers in base n (not any of the popular ones like 10, 16, 8 or 2 - I hear that Charles Simonyi, the inventor of Hungarian Notation, favors -2 when asking this question).
I just need the idea.
You didn't specify a language, but you could just convert the base n number into a standard integer and add it.
Suppose base N number = '...d2d1d0' where di = the i'th digit.
Number = ... d2 * N^2 + d1 * N^1 + d0 * N^0
Then just add the numbers as usual.
Idea: it looks like hashing, but in hash function you can't use negative numbers.

How to recursively check if a string is palindrome in Ruby [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am trying to make a recursive ruby function that returns true if a user enters a string that is palindrome, and false otherwise.
I am also trying to have a base case for the return value
Smells like homework assignment since you specifically request a recursive solution.
A solution with recursion is to check whether first equals last letter and if they are recursively check the string in between. An empty or one character string is a palindrome.
def palindrome?(str)
str.length <= 1 or (str[0,1] == str[-1,1] and palindrome?(str[1..-2]))
end
ruby! ;)
def palindrom?(string)
string == string.reverse
end

Telephone Words problem [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Please help solve this:
Telephone numbers are often given out as a word representation, so that they are easy to remember. For example if my number is 4357, the text given is HELP. There could be many other possibilities with the same digits, most of which do not make sense.
Write a space-and-time-optimal function that can, given a phone number, print the possible words that can be formed from it.
Based on the detailed explanation in the comment this should be a simple permutation combination problem:
Each digit will have a number of characters associated to it (example 4 could mean either of G,H or I) and then for a combination of digits the permutation can be computed.

Resources