What is the smallest value of M signs so that if you look at any sequence of M consecutive signs, you can uniquely figure out the location of that sequence along the street?
For example, if the sequence of signs is “IXMVDKIXMV,” M cannot be 3 because “IXM” is in two places; also, M cannot be 4 because “IXMV” is on the street in two places. M = 5 is the smallest set of signs because all sequences of 5 consecutive signs are unique.
Your function must have two inputs: The first one is an integer N. The second input is the string of N characters A…Z representing the signs along the street.
Your function must output a single integer, M.
Provide your Java code separately. What is the runtime of your algorithm?
import java.util.*;
public class SmallValueOfSigns {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int limit=0;
char[] ch=new char[100];
String signs=sc.nextLine();
int len=signs.length();
String str="";
for(int i=0;i<len;i++) {
str=str+signs.charAt(i);
String str2=signs.substring(i+1)
if(!(str2.contains(str))) {
limit=str.length();
break;
}
}
System.out.println(limit); //here we are printing smallest set of sequence which is M;
}
}
Explanation:
1.Here str is to take sequnce of given signs which is needed to check with given str2.
2.str2 is to take substring of given signs afterwards of the str which is needed to be checked with str1 whether it contains str or not.
3. If str2 not contains str it means that str is the smallest set of sequence so that we can break the loop and return the smallest set of sequence that is M(length of str)
Runtime:
Run time of this algarithm is O(n) beacuse it contains only one loop.
may this help you!!!!
You went for a walk on a strange street and now you’re lost. There are N...
package week_3; /** Write a method called countUppercase that takes a String array argument. You can assume that every element in the array is a one-letter String, for example String[] test = { "a", "B", "c", "D", "e"}; This method will count the number of uppercase letters from the set A through Z in the array, and return that number. So for the example array above, your method will return 2. You will need to use some Java library methods....
Question 1 When you declare a variable of type Single, it contains 0 by default. True False Question 2 The following line declares an array that can contain whole numbers, with 10 elements. Dim Variables(9) As Integer True False Question 3 Once a variable is declared we can not change the variable's data type. True False Question 4 If A is False and B is True, then A Or B is True because A is False. True False Question 5...
Program is in C++. Write a function named wordStatsPlus that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report: the total number of lines; total number of words; the number of unique letters used from A-Z, case-insensitively, and its percentage of the 26-letter alphabet; the average number of words per line (as an un-rounded...
Program is in C++. Write a function named wordStatsPlus that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report: the total number of lines; total number of words; the number of unique letters used from A-Z, case-insensitively, and its percentage of the 26-letter alphabet; the average number of words per line (as an un-rounded...
You are given a set of ABC cubes for kids (like the one shown below) and a word. On each side of each cube a letter is written 7 FI 0 You need to find out, whether it it possible to form a given word by the cubes For example, suppose that you have 5 cubes: B1: MXTUAS B2:OQATGE ВЗ: REwMNA B4: MBDFAC В5: IJKGDE (here for each cube the list of letters written on its sides is given) You...
Create C++ program.Convert this string to Tap Code using structures. It is very important to use structures in this program. The tap code is based on a Polybius square using a 5×5 grid of letters representing all the letters of the Latin alphabet, except for K, which is represented by C. The listener only needs to discriminate the timing of the taps to isolate letters. Each letter is communicated by tapping two numbers the first designating the row (Down) the...
Create C++ program.Convert this string to Tap Code using structures. It is very important to use structures in this program. The tap code is based on a Polybius square using a 5×5 grid of letters representing all the letters of the Latin alphabet, except for K, which is represented by C. The listener only needs to discriminate the timing of the taps to isolate letters. Each letter is communicated by tapping two numbers the first designating the row (Down) the...
Hey guys I need help with this assignment. However it contains 7
sub-problems to solve but I figured only 4 of them can be solved in
one post so I posted the other on another question so please check
them out as well :)
Here is the questions in this assignment:
Note: Two helper functions Some of the testing codes for the functions in this assignment makes use of the print_dict in_key_order (a dict) function which prints dictionary keyvalue pairs...
1 Overview and Background Many of the assignments in this course will introduce you to topics in computational biology. You do not need to know anything about biology to do these assignments other than what is contained in the description itself. The objective of each assignment is for you to acquire certain particular skills or knowledge, and the choice of topic is independent of that objective. Sometimes the topics will be related to computational problems in biology, chemistry, or physics,...
This is for C programming: You will be given files in the following format: n word1 word2 word3 word4 The first line of the file will be a single integer value n. The integer n will denote the number of words contained within the file. Use this number to initialize an array. Each word will then appear on the next n lines. You can assume that no word is longer than 30 characters. The game will use these words as...