Describe a recursive algorithm for the following variant of the text segmentation problem. Assume that you have a subroutine IsWord that takes an array of characters as input and returns True if and only if that string is a “word”.
1. Given two arrays A[1..n] and B[1..n] of characters, compute the number of different ways that A and B can be partitioned into words at the same indices.
FindWords: It contains A[ ] as array, WORDS_BAG as collections of different words (bag of words)
1) A[ ] <- Input the characters from user .
2) Initialize new array as splitedWords = [ ]
3) Repeat for i = 0 to i < length of A.
4) Append A[ from start to i] into splitedWords.
5) Append A[ from i +1 to last ] into splitedWords.
# eg: if the word is "artistoil" then splitedWords contain [ a, rtistoil, ar, tistoil, art, istoil, arti, stoil, artis, toil, artist, oil, artisto, il, artistoi, l ]
6) i = i + 1
End For Loop
7) OutPut = [ ]
8) Repeat for i = 0 to length of splitedWords
9) if splitedWords[ i ] finds null then
return 0 and "Not data input"
10) if splitedWords[ i ] finds in WORDS_BAG then
append splitedWords[ i ] into OutPut
End For Loop
# eg: OutPut will contains [a, art, toil, artist, oil ]
11) Now Repeat for 0 to 2 from the step 3 for all the OutPut then we will get more words
eg: [a, art, to, toil, artist, is , oil]
end loop
12) Repeat for i =0 to length of OutPut
13) if first character of OutPut[ i ] is equal to A[ 1 ]
then add into NewOut1 list
14) if last character of OutPut[ i ] is equal to A[ last ]
then add into NewOut2 list
i++
END loop
15) combine NewOut1 with NewOut2 word wise and also cheak first and last character of output words with A[ first ] and A [ last ] and length of word also equal to each other
16) return no. of words and words
Describe a recursive algorithm for the following variant of the text segmentation problem. Assume that you...
Describe backtracking recursive algorithms for the following variants of the text segmentation problem. Assume that you have a subroutine IsWord that takes an array of characters as input and returns True if and only if that string is a “word”. You do not need to analyze the time complexity of your algorithms for this problem. Given two arrays A[1..n] and B[1..n] of characters, decide whether A and B can be partitioned into words at the same indices. For example, the...
In java, write a program with a recursive method which asks the user for a text file (verifying that the text file exists and is readable) and opens the file and for each word in the file determines if the word only contains characters and determines if the word is alpha opposite. Now what I mean by alpha opposite is that each letter is the word is opposite from the other letter in the alphabet. For example take the word...
In this assignment, you will explore more on text analysis and an elementary version of sentiment analysis. Sentiment analysis is the process of using a computer program to identify and categorise opinions in a piece of text in order to determine the writer’s attitude towards a particular topic (e.g., news, product, service etc.). The sentiment can be expressed as positive, negative or neutral. Create a Python file called a5.py that will perform text analysis on some text files. You can...
C++ Lab 1. Read in the contents of a text file up to a maximum of 1024 words – you create your own input. When reading the file contents, you can discard words that are single characters to avoid symbols, special characters, etc. 2. Sort the words read in ascending order in an array (you are not allowed to use Vectors) using the Selection Sort algorithm implemented in its own function. 3. Search any item input by user in your...
Programming project in Java: You are allowed to use the following methods from the Java API: class String length charAt class StringBuilder length charAt append toString class Character any method Create a class called HW2 that contains the following methods: 1. isAlphabeticalOrder takes a String as input and returns a boolean: The method returns true if all the letters of the input string are in alphabetical order, regardless of case. The method returns false otherwise. Do not use arrays to...
Problem #1 Create a program that performs the following functions: Uses character arrays to read a user's name from standard input Tells the user how many characters are in her name Displays the user's name in uppercase Create a program that uses the strstr() function to search the string "When the going gets tough, the tough stay put! for the following occurrences (display each occurrence found to standard output): "Going" "tou" "ay put!" Build a program that uses an array...
CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the file is completely read, write the words and the number of occurrences to a text file. The output should be the words in ALPHABETICAL order along with the number of times they occur and the number of syllables. Then write the following statistics to...
using matlab In Class Exercises 8-Arrays For the following exercises, assume an array is already populated, your job is to write a program that traverses the array. DO NOT HARD CODE the last index. In other words, you code for 1-4&6 should be able to handle the following 2 arrays: amp2 10 array1 [52, 63, 99, 71, 3.1] array2 - [99:-3: 45); For 5: wordArray1 wordArray2 ('number, 'arrays', 'indices', 'hello', finish' [number, 'different, 'finish? 1. Determine the sum of all...
1) Design a greedy algorithm that solves the problem; describe your algorithm with clear pseudocode; and prove the time efficiency class of your algorithm: If x, y are two adjacent elements in a sequence, with x before y, we say that the pair x, y is in order when x <= y and the pair is out of order when x > y. For example, in the string “BEGGAR” the pair G, A are out of order, but all the...
New answers only outcomes for this lab: Recursive concepts Uses for recursion Infinite recursion Problem solving with recursion Say My Number You will produce a short, elegant, recursive algorithm that spells out any number between 1 and 2.1 billion. Allow the user to input a number in the range from 1 to 2.1 billion (a positive 32-bit int), then spell out the number (e.g. 123456 would output "one hundred twenty three thousand four hundred fifty six"). Use a recursive method...