Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Beginning Java Data Structures and Algorithms

You're reading from   Beginning Java Data Structures and Algorithms Sharpen your problem solving skills by learning core computer science concepts in a pain-free manner

Arrow left icon
Product type Paperback
Published in Jul 2018
Publisher
ISBN-13 9781789537178
Length 202 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
James Cutajar James Cutajar
Author Profile Icon James Cutajar
James Cutajar
Arrow right icon
View More author details
Toc

Naive Search Algorithm


The string matching problem has two inputs, as follows:

  • An arrayT[1, 2, ...n]of lengthn
  • An arrayP[1, 2, ...m]of lengthm (<= n)

The elements of T and P are characters from the same finite alphabet (usually called ∑).

For instance, we may be searching in binary strings, in which case our alphabet is {0, 1}, or we may be searching in strings of lowercase letters, in which case our alphabet is {a, b… z}.

The following diagram represents this terminology:

Figure 5.1: Representation of text arrayT, pattern arrayP, and finite alphabet ∑

The character arrays P and T are usually called "strings of characters". We're interested in finding occurrences of pattern P in text T.

We say that pattern P occurs in text T if we can align the pattern P with text T so that all characters in P match the ones in T. When aligning, we need to shift pattern P zero or more times to the right.

Therefore, in the string matching problem, we're interested in valid shifts with which pattern P occurs in...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image