pattern matching - four way technique
Hi, here's my question..
I am trying to implement pattern matching using brute force algorithm where I am trying to apply four way technique to search a given pattern in a text.in this four way technique I will be splitting text which is of length "n" into two halves i.e.from 0 to n/2 and n/2 to n and i will search for a pattern in both the directions i.e. from left as well as from right on this divided parts..there is also a special case wherein i will be searching at the junction where splitting takes place..now what i want to do this is to run this program as four different and independent threads using multithreading concept in java. As you know processors such as core2quad has four processors so i want these threads to utilise the four processors completely...this is my code for brute force..plz help me out in solving this. i also need the amount of time taken by this program to execute.
import java.lang.*;
import java.io.*;
import java.util.*;
public class bruteforcefourway
{
public static void main(String args[ ])
{
String text1,pattern1;
Scanner s=new Scanner(System.in);
System.out.println("\n Enter the text");
text1=s.nextLine();
System.out.println("\n Enter the pattern");
pattern1=s.nextLine();
brute(text1,pattern1);
}
public static void brute(String text,String pattern)
{
int count=0,i,j;
int n=text.length(); // length of the text
int m=pattern.length(); //length of the pattern
for(i= 0;i<=n/2;i++)
{
j=0;
while((j<m)&&(pattern.charAt(j)==text.charAt(i + j)))
{
j++;
if (j==m)
{
count++;
System.out.printf("\n %d Match found between %d and %d",count,i-1,i+m);
}
}
}
for(i= n/2+1;i<=n;i++)
{
j=0;
while((j<m)&&(pattern.charAt(j)==text.charAt(i + j)))
{
j++;
if (j==m)
{
count++;
System.out.printf("\n %d Match found between %d and %d",count,i-1,i+m);
}
}
}
for(i= n/2-m+1;i<=n/2+m-1;i++)// special case searching at the junction where splitting took place
{
j=0;
while((j<m)&&(pattern.charAt(j)==text.charAt(i + j)))
{
j++;
if (j==m)
{
count++;
System.out.printf("\n %d Match found between %d and %d",count,i-1,i+m);
}
}
}
System.out.printf("\n\n");
System.out.printf("\n Total Matches found are : %d",count);
}
}
View Answers
Related Tutorials/Questions & Answers:
Pattern MatchingPattern Matching hello,
What operator performs
pattern matching?
hii,ADS_TO_REPLACE_1
The "LIKE" operator performs the
pattern matching in SQL
Pattern matchingPattern matching String tagvalue =
I've above string and I need to extract the value of
1- fname
2- lname
3- email.
Please help me the best
way...
Pattern fnamepat = Pattern.compile("fname=\"([^<>]+)\" ");
Matcher fmatch
Advertisements
Three Way MatchingThree
Way Matching hello,
What is Three
Way Matching?
hii,ADS_TO_REPLACE_1
In Three
way matching the following documents are compare:-
Purchase order
Receipt of Items/Packing slip
Invoice
Matching Pattern using Regularexpression
Matching Pattern using Regularexpression
This Example describe
the
way to match a
pattern with the text by using
Regularexpression.The steps involved in
matching a
pattern searching techniquesearching technique Hi,
i need any searching
technique in java to search the data and give the all possible data by links
PatternPattern How to print this
pattern in Java please help me
A
AC
ACE
ACEG
ACEGI
The program should be right to left
patternpattern 1
3 1
5 3 1
7 5 3 1
9 7 5 3
Here is a number
pattern example.
1
3 1
5 3 1
7 5 3 1
9 7 5 3 1
class
Pattern{
public static void main(String args[]){
for(int i=1;i<=9;i
PatternPattern 1234321
123 321
12 21
1 1
please,give me this
pattern in java
class Sixth_1
{
public static void main(String args...;
}
}
}
Here is a number
pattern
class
Pattern{
public
Design Pattern
Design
Pattern
?
Pattern?
word suggests a series of events occurring in a definite order. Many a times,
you get an easy
way to tackle a recurring problem (which has been
HEPTALYSIS technique in Business AnalysisHEPTALYSIS
technique in Business Analysis What is HEPTALYSIS
technique in Business Analysis?
HEPTALYSIS is a Business analysis
technique that is for starting up a new
business during its initial phase of start up
Matching Zip code using regular expression
Matching Zip code using regular expression
This Example describes the
way of
matching Zip...
Matching_Zipcode.java.
The steps involved in program
Matching_Zipcode.java
Greedy and Non-Greedy Matching in a Regular Expression a string in
the given string through the Greedy and Non-Greedy
way of
matching. Here you can
learn about the Greedy and Non-Greedy
way of
matching the word....
Greedy
Matching: This is the
way of
matching
string from one to another
Pattern MakingPattern Making how to print this
pattern in java?
*
*
* *
* *
* * *
* * * *
* * * *
It is just an example
pattern programpattern program can some one plz help me to wright the logic for the following
pattern
abcdcba
abc cba
ab ba
a a
ab ba
abc cba
abcdcba
Matching CaseMatching Case Hi,
i want some code for
matching case from an text file. i.e if i give an query called Java from the user,i need to get an output searching the text file all the names in that without case sensitive
Java patternJava pattern Write a Java program that outputs the following
pattern.
1
21
321
4321
54321
654321
pattern matcherpattern matcher i want a number in a specific range in
pattern matcher..for example a number should only be in the range of 6-9 digits... = tf.getText();
Pattern pattern = Pattern.compile("\\d{10}");
Matcher matcher
pattern programpattern program can any 1 print the following
pattern in java .plz give the code.and yes thank u so much for answering my 2 other questions.had i... before.anyways the
pattern goes like this
abcdcba
abc cba
ab ba
a a
ab ba
abc abc
pattern programpattern program 13579 1357 135 13 1
pattern program in java
Here is your Example:-
package Compare;
public class PatternDemo {
public static void main(String [] args){
int c=10;
for(int i=0;i<
Code for Pattern Code for
Pattern 1
23
345
5678
891011
Please write the code of above program and please do not use in this string tokennizer, string buffer etc i mean to say that please use very simple method
Coder for PatternCoder for Pattern 1
12
123
1234
12345
please write the program of above
pattern and do not use string tokennizer string buffer i mean to say that please use very simple method
Thanks
public class PatternExample
pattern be between 2 and 9. The following shows the
four pattern in size 5.
Pattern 1
5...:
Menu
Pattern one
Pattern two
Pattern three
Pattern four
Quit
Enter...pattern write a java program that can create
four different patterns
pattern generationpattern generation write a program to print
pattern shown below
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
Here is an example of number spiral.
public class NumberSpiral{
public
TOM Eclipse Plugin TOM Eclipse Plugin
The
way to use a
Pattern Matching Programming
Language into Eclipse
The plugin offers automatic compilation
Tom and Java errors
ModuleNotFoundError: No module named 'matching'ModuleNotFoundError: No module named '
matching' Hi,
My Python... '
matching'
How to remove the ModuleNotFoundError: No module named '
matching... to install padas library.
You can install
matching python with following
ModuleNotFoundError: No module named 'Pattern'ModuleNotFoundError: No module named '
Pattern' Hi,
My Python... '
Pattern'
How to remove the ModuleNotFoundError: No module named '
Pattern... to install padas library.
You can install
Pattern python with following command
ModuleNotFoundError: No module named 'Pattern'ModuleNotFoundError: No module named '
Pattern' Hi,
My Python... '
Pattern'
How to remove the ModuleNotFoundError: No module named '
Pattern... to install padas library.
You can install
Pattern python with following command
ModuleNotFoundError: No module named 'Pattern'ModuleNotFoundError: No module named '
Pattern' Hi,
My Python... '
Pattern'
How to remove the ModuleNotFoundError: No module named '
Pattern... to install padas library.
You can install
Pattern python with following command
ModuleNotFoundError: No module named 'Pattern'ModuleNotFoundError: No module named '
Pattern' Hi,
My Python... '
Pattern'
How to remove the ModuleNotFoundError: No module named '
Pattern... to install padas library.
You can install
Pattern python with following command
What is static factory pattern?What is static factory
pattern? Hello,
please tell me what is static factory
pattern?
Thank you..
Dear friend,
you can go through the following links to better understand the static factory
pattern -
Factory
Design Pattern in flexDesign
Pattern in flex Hi....
I want to know about
What design... the name of this design
pattern...
Thanks
Ans:ADS_TO_REPLACE_2
Singleton design
pattern is used in Action Script and java.
Thanks
Design Pattern - JDBCDesign Pattern what is adaptar design
pattern The Adapter
pattern is used so that two unrelated interfaces can work together. The joining between them is called an Adapter The Adapter
pattern is used so that two
pattern used in hibernate.pattern used in hibernate. how many design patterns are used in hibernate 3?
please also mention the name of those design
pattern.
Thanks,
sudhil mishra
how to print String as pattern ?how to print String as
pattern ? i have a one String name ="rajesh" i want to print
pattern like
r
*
ra
**
raj
raje
rajes
rajesh
please help me