Difference between kleene star and a plus

In summary, the conversation discusses the difference between using a * and a + in relation to the symbols {0,1}. The use of a * indicates 0 or more repetitions of the symbol, while a + indicates 1 or more repetitions. This is consistent with the definition of a Kleene star and the BNF notation.
  • #1
bensoa1
6
0

Homework Statement


So this isn't a question from a homework directly, but it's been used in my textbook an I'm not sure of the difference. For example, if I have a* and a+, what is the difference

Homework Equations


The exact wording in the book was {0,1}* and {0,1}+

The Attempt at a Solution


I know the kleene star means you have 0 or more repetitions of that symbol, i.e. 0* = n occurrences of 0 where n ≥ 0. I'm not sure what the plus means at all
 
Physics news on Phys.org
  • #2

Related to Difference between kleene star and a plus

What is the difference between the kleene star and a plus in regular expressions?

The kleene star, denoted by the symbol *, represents the repetition of zero or more occurrences of the preceding character or group. For example, the regular expression "ab*" would match "a", "ab", "abb", "abbb", and so on. On the other hand, the plus symbol, denoted by the symbol +, represents the repetition of one or more occurrences of the preceding character or group. So, the regular expression "ab+" would match "ab", "abb", "abbb", and so on, but not "a". Essentially, the difference between the kleene star and a plus is that the kleene star allows for zero occurrences, while the plus symbol requires at least one occurrence.

Which is more efficient, the kleene star or a plus in regular expressions?

In terms of efficiency, the kleene star is generally more efficient because it allows for zero occurrences, which means it has fewer conditions to check. However, the difference in efficiency is minimal and likely not noticeable in most cases.

Can you use both the kleene star and a plus in the same regular expression?

Yes, you can use both the kleene star and a plus in the same regular expression. This would be useful if you wanted to match a pattern that could have any number of occurrences, including zero, but also wanted to ensure that there was at least one occurrence. For example, the regular expression "ab*+" would match "a", "ab", "abb", "abbb", and so on, but not an empty string.

When should I use the kleene star versus a plus in regular expressions?

The kleene star and a plus are both useful in different scenarios. The kleene star is more flexible and can match a wider range of patterns, while the plus symbol is more specific and ensures that there is at least one occurrence. So, it is important to consider the specific pattern you are trying to match and determine which is the most appropriate to use.

Can you provide an example of when to use the kleene star and when to use a plus in regular expressions?

One example of when to use the kleene star would be when you want to match a word that can have any number of "s" at the end, such as "cats" or "catsssss". In this case, the regular expression "cats*" would be appropriate. On the other hand, if you want to match a word that must have at least one "s" at the end, such as "cats" or "catsssss", the regular expression "cats+" would be more appropriate.

Similar threads

  • Differential Geometry
Replies
29
Views
2K
  • Calculus and Beyond Homework Help
Replies
5
Views
1K
  • Calculus and Beyond Homework Help
Replies
8
Views
2K
  • Calculus and Beyond Homework Help
Replies
2
Views
1K
  • Special and General Relativity
Replies
28
Views
2K
  • Calculus and Beyond Homework Help
Replies
9
Views
1K
  • Calculus and Beyond Homework Help
Replies
12
Views
937
  • Calculus and Beyond Homework Help
Replies
6
Views
2K
  • Sci-Fi Writing and World Building
Replies
18
Views
1K
Back
Top