To be done in java code. 2 words are anagrams if 1 word can be formed by rearranging all the letters of the other word, eg: mary, army a word is represented as a linked list with one letter per node of the list.
Write a function that, given w1 and w2, with each pointing to a word of lowercase letters, returns 1 if the words are anagrams and 0 if they are not. Base your algorithm on the following: for each letter in w1, search w2 for it; if found, delete it and continue; otherwise, return 0.
public class Angagram {
public static void main(String[] args) {
int s=anagram("mean","name");
System.out.println(s);
}
private static int anagram(String w1, String w2)
{
w1=w1.toLowerCase();
w2=w2.toLowerCase();
StringBuffer sb = new
StringBuffer(w2);
for(int i=0;i<w1.length();i++)
{
if(sb.indexOf(w1.charAt(i)+"")!=-1) {
sb.deleteCharAt(sb.indexOf(w1.charAt(i)+""));
}
else {
return 0;
}
}
return (sb.length()==0)?1:0;
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
To be done in java code. 2 words are anagrams if 1 word can be formed...
Question 2: Finding the best Scrabble word with Recursion using java Scrabble is a game in which players construct words from random letters, building on words already played. Each letter has an associated point value and the aim is to collect more points than your opponent. Please see https: //en.wikipedia.org/wiki/Scrabble for an overview if you are unfamiliar with the game. You will write a program that allows a user to enter 7 letters (representing the letter tiles they hold), plus...
I have 4 questions dont know can anyone help me with any of
it?
ii) Consider the 11 letter word MATHEMATICS a) How many distinct words can be formed by rearranging its letters? b) How many 4 letter words can be formed using the letters in the word MATHEMATICS, using letters no more often than they appear in the word? ii) Consider the equation where xi, x2, 13, T4,5 and re are non-negative integers a) How many solutions are there...
**IN JAVAAssignment 10.1 [95 points]The WordCruncher classWrite the Java code for the class WordCruncher. Include the following members:A default constructor that sets the instance variable 'word' to the string "default".A parameterized constructor that accepts one String object as a parameter and stores it in the instance variable. The String must consist only of letters: no whitespace, digits, or punctuation. If the String parameter does not consist only of letters, set the instance variable to "default" instead. (This restriction will make...
can someone please double check my code here are the requirements please help me fulfill the requirements Using the material in the textbook (NumberList) as a sample, design your own dynamic linked list class (using pointers) to hold a series of capital letters. The class should have the following member functions: append, insert (at a specific position, return -1 if that position doesn't exist), delete (at a specific position, return -1 if that position doesn't exist), print, reverse (which rearranges...
Recursion and Trees Application – Building a Word Index Make sure you have read and understood · lesson modules week 10 and 11 · chapters 9 and 10 of our text · module - Lab Homework Requirements before submitting this assignment. Hand in only one program, please. Background: In many applications, the composition of a collection of data items changes over time. Not only are new data items added and existing ones removed, but data items may be duplicated. A list data structure...
For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...
Task 2: SecretWord class:
Download and save a copy of LinkedLists.py (found at the bottom
of this assignment page on eClass). In this file, you have been
given the complete code for a LinkedList class. Familiarize
yourself with this class, noticing that it uses the Node class from
Task 1 and is almost identical to the SLinkedList class given in
the lectures. However, it also has a complete insert(pos, item)
method (which should be similar to the insert method you...
For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...
In this assignment you’ll implement a data structure called a trie, which is used to answer queries regarding the characteristics of a text file (e.g., frequency of a given word). This write-up introduces the concept of a trie, specifies the API you’re expected to implement, and outlines submission instructions as well as the grading rubric. Please carefully read the entire write-up before you begin coding your submission. Tries A trie is an example of a tree data structure that compactly...
***JAVA: Please make "Thing" movies.
Objective In this assignment, you are asked to implement a bag collection using a linked list and, in order to focus on the linked list implementation details, we will implement the collection to store only one type of object of your choice (i.e., not generic). You can use the object you created for program #2 IMPORTANT: You may not use the LinkedList class from the java library. Instead, you must implement your own linked list...