Bird
0
0
DSA Cprogramming~10 mins

String Pattern Matching Naive in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start the outer loop from the first character of the text.

DSA C
for (int i = 0; i <= n - m; i[1]) {
    // pattern matching logic
}
Drag options to blanks, or click blank then click option'
A++
B--
C+=
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using decrement operator -- causes the loop to run incorrectly.
Using '+=' without a value is invalid syntax.
2fill in blank
medium

Complete the code to compare characters of the pattern and text inside the inner loop.

DSA C
for (int j = 0; j < m; j++) {
    if (text[i + j] [1] pattern[j]) {
        break;
    }
}
Drag options to blanks, or click blank then click option'
A>
B==
C!=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' causes the loop to break on matching characters, which is wrong.
Using '>' or '<' compares ASCII values but is not suitable here.
3fill in blank
hard

Fix the error in the condition that checks if the pattern was found completely.

DSA C
if (j [1] m) {
    printf("Pattern found at index %d\n", i);
}
Drag options to blanks, or click blank then click option'
A==
B<
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '<=' causes false positives before full match.
Using '>' is incorrect because j cannot be greater than m here.
4fill in blank
hard

Fill both blanks to correctly declare and initialize the lengths of text and pattern.

DSA C
int n = strlen([1]);
int m = strlen([2]);
Drag options to blanks, or click blank then click option'
Atext
Bpattern
Cstring
Dinput
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined variables like 'string' or 'input'.
Mixing up text and pattern variables.
5fill in blank
hard

Fill all three blanks to complete the naive pattern matching function header and variable declarations.

DSA C
void [1](char *[2], char *[3]) {
    int n = strlen(text);
    int m = strlen(pattern);
    // matching logic
}
Drag options to blanks, or click blank then click option'
AnaiveSearch
Btext
Cpattern
Dsearch
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect function names like 'search'.
Swapping parameter names or using undefined names.