Unit 5: Naive Pattern Search - Subjective Questions

CSE329 — Prelude To Competitive Coding • Practice Questions with Detailed Answers

20 questions

1

Define the naïve pattern search problem. Explain the working of the naïve pattern searching algorithm with a suitable example.

2

Explain the KMP (Knuth-Morris-Pratt) algorithm. How does it improve upon the naïve approach?

3

What is the LPS (Longest Prefix Suffix) array in the KMP algorithm? Construct the LPS array for the pattern P = "ABABCABAB".

4

Describe the Rabin-Karp algorithm for pattern searching. What role does hashing play in it?

5

Compare the KMP algorithm and the Rabin-Karp algorithm in terms of approach, time complexity, and use cases.

6

What is a Suffix Array? Explain how it is constructed and give its applications.

7

Explain how to check if two strings are rotations of each other. Provide an efficient algorithm with an example.

8

Describe the Largest Connected Component on a Grid problem. Explain the approach to solve it.

9

Explain how to check whether one string is a substring of another using the naïve approach. Write the pseudocode and analyze its complexity.

10

Explain the concept of Longest Prefix which is also a Suffix (proper prefix-suffix). How is it computed, and why is it important in string algorithms?

11

Distinguish between a proper prefix, a proper suffix, and a border of a string with examples.

12

Explain Lexicographical Sorting of strings. How does it differ from numerical sorting? Illustrate with an example.

13

Describe how to split a string into substrings based on a delimiter. Discuss different approaches with examples.

14

Derive the time complexity of the naïve pattern matching algorithm in the best, average, and worst cases with justification.

15

Given the pattern P = "AABAACAABAA", construct the LPS array and trace how KMP uses it during a mismatch.

16

In the Rabin-Karp algorithm, explain the concept of rolling hash and spurious hits. Why is a prime modulus used?

17

Explain how a suffix array can be used to search for a pattern in a text. What is the time complexity of this search?

18

Write an algorithm to find the shortest period of a string using the LPS array. Illustrate with the string "abcabcabc".

19

Discuss common problems based on naive pattern search and explain how naïve search can still be useful despite its inefficiency.

20

Write a program logic (pseudocode) to lexicographically sort a list of strings and explain a practice problem where lexicographical ordering is essential.