Home Answers Viewqa Java-Beginners pattern matching - four way technique

 
 


Praveen Bhushan
pattern matching - four way technique
0 Answer(s)      2 years and 3 months ago
Posted in : Java Beginners

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 Pages:
Pattern matching
Pattern 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
Pattern Matching
Pattern Matching  hello, What operator performs pattern matching?   hii, The "LIKE" operator performs the pattern matching in SQL
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
Three Way Matching
Three Way Matching  hello, What is Three Way Matching?   hii, In Three way matching the following documents are compare:- Purchase order Receipt of Items/Packing slip Invoice
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
Pattern resetting using regular expression
Pattern resetting using regular expression       This Example describes the way to retrieve... Pattern_Resetting.java. The steps involved in program Pattern_Resetting.java
Matching Address using regular expressions
Matching Address using regular expressions       This Example describes the way to match address... the pattern.       Matching.java:- public class 
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
Print Matchingwords using Regular expression
;     This Example describe the way to print the matching word from the file using Regularexpression. The steps involved in ... 224121 5245241 55241 542541 441 5541 41441 Pattern pattern = Pattern.compile
Escaping Special Characters in a Pattern
: This section provides an example for the best illustration about the way of matching... Escaping Special Characters in a Pattern   ... characters from the given string or text. Here, you can learn the way
searching technique
searching technique  Hi, i need any searching technique in java to search the data and give the all possible data by links
How to change the cloth pattern, change the cloth pattern, cloth pattern
How to change the cloth pattern       We are going to change the cloth pattern by using a simple way... Pattern. Now change layer settings. You will get this picture.   Layer
Regular Expressions
Matching Pattern using Regularexpression This Example describe the way to match a pattern... This Example describe the way to print the matching word from the file
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
Matching Case
Matching 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
Match string using regular expression without Case sensitivity
the way to match the String using regular expression. For this we are going to make program named Matching_Casesensitive.java. The steps involved in program Matching_Casesensitive.java are described below:- String regex="^java"
Pattern
Pattern  How to print this pattern in Java please help me A AC ACE ACEG ACEGI The program should be right to left
pattern
pattern  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
Pattern
Pattern  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
Singleton Pattern
Singleton Pattern       Singleton Pattern:  The singleton design pattern deals with one... from a common place. There are various ways of achieving this pattern. For example
Builder Pattern
Builder Pattern       Builder Pattern: This design pattern allows the client to construct a complex object based on its type and content. One can achieve the way
what technique - Java Beginners
what technique  what technique or algorithm i need to use to develop a system a scheduling time table in java
Abstract Factory Pattern
Abstract Factory Pattern       II Abstract Factory Pattern :  This pattern is one level of abstraction higher than factory pattern. This means that the abstract factory returns
HEPTALYSIS technique in Business Analysis
HEPTALYSIS 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
Strategy Pattern of HashCode Equality
Strategy Pattern of HashCode Equality     2005-05-18 The Java Specialists' Newsletter [Issue 109] - Strategy Pattern of HashCode Equality... Pattern and how Java works with dynamic proxies
Mysql Date like
Mysql Date like       The Like Operator is used in pattern matching by comparison with character... like '2008-12-20'.The like pattern is used in pattern matching by comparing
Creational Design Pattern
Creational Design Pattern          Design pattern includes creational, structural, and behavioral... the creational design patterns define the best possible way in which an object can
Mysql Like Operator
Mysql Like Operator       Mysql Like is used to retrieve the records on the basis of pattern matching... named employee1 using like: Now you want to return only those pattern matching
Mysql Like Operator
; Mysql Like is used to retrieve the records on the basis of pattern matching in select query. The like comparison Operator in SQL allows you to match... Table named employee1 using like: Now you want to return only those pattern
Mysql like syntax
Mysql like syntax       Mysql Like is used to retrieve the records on the basis of pattern matching... pattern matching records inside the like comparison operator from
Mysql like syntax
those pattern matching records inside the like comparison operator from...; Mysql Like is used to retrieve the records on the basis of pattern matching in select query. The like comparison Operator in SQL allows you to match any
Creating Data Access Object (DAO) Design Pattern
Creating Data Access Object (DAO) Design Pattern Data Access Object is the import component of the design patter of java. It provides a technique to separating the object persistence and data access logic. All the basic data access
Design Pattern
Design Pattern        ... to other objects. It is a simple way to design and realize relationships between the entities.  Decorator Design Pattern This section deeply
Pattern and Matcher
Java: Pattern and Matcher In addition to the regular expression methods...), there are two classes that are specifically user for regular expression matching... pattern can be reused by many Matcher objects. Pattern pat
Factory Pattern
Factory Pattern       I.  Factory Pattern:  One of the goals of object-oriented design... of a class, not what kind of subclass to create. Creational design pattern , more
pattern printing
pattern printing  
matching database again - Java Beginners
matching database again  Dear experts, So happy I get through this ask a question page again. Thank God. I want to say "A BIG THANK YOU" for helping me about the matching codes. It is working now after fine tuning
Design pattern
Design pattern  explain factory pattern
Mysql Like Command
on the basis of pattern matching. The comparison 'like' operator return you the record from a table on the basis of pattern matching with a character. Understand... operator allows you to return the records from column name matching with 'komal
Mysql Like Command
on the basis of pattern matching. The comparison 'like' operator return you the record from a table on the basis of pattern matching with a character. Understand...' .The like operator allows you to return the records from column name matching
Pattern Making
Pattern Making  how to print this pattern in java? * * * * * * * * * * * * * * * * * It is just an example
pattern program
pattern 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
Regular Expressions
, programming language for pattern matching. Java, as of version 1.4, has... programming technique to search for patterns in strings, extracting, and replacing... expressions as well as providing many additional functions. See Pattern
pattern matcher
pattern 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 program
pattern 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 program
pattern 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<
Re: XML SCHEMA MATCHING doubt's - XML
Re: XML SCHEMA MATCHING doubt's  how to store xml file in database? which database require to store xml file? how to connect xml with java
Re: XML SCHEMA MATCHING doubt's - XML
Re: XML SCHEMA MATCHING doubt's  how to store xml file in database? which database require to store xml file? how to connect xml with java

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.