Data Structures & AlgorithmsHardProduct-company MCQ pattern
What is the KMP failure (LPS) array for the pattern AABAACAABAA?
- A. 0 1 0 0 1 0 1 2 3 4 5
- B. 0 1 0 1 2 0 1 2 3 4 5
- C. 0 1 0 1 2 1 1 2 3 4 5
- D. 0 1 0 1 2 0 1 2 3 4 4
Correct answer: B. 0 1 0 1 2 0 1 2 3 4 5
LPS[i] is the length of the longest proper prefix of P[0..i] that is also its suffix. After C (no match, 0) the string AABAA repeats from the start, giving 1, 2, 3, 4, 5 for the last five positions.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- The reversal algorithm rotates an array LEFT by k: reverse the first k elements, reverse the rest, then reverse the whole array. What is…
- Which statement about a doubly linked list compared with a singly linked list is FALSE?
- How many of these statements are correct? (i) Merge sort is stable. (ii) Heap sort runs in O(n log n) even in the worst case. (iii) Quick…
- What is the time complexity of this code fragment? c int count = 0; for (int i = 1; i < n; i = 2) for (int j = 0; j < i; j++) count++;
- What is the time complexity of this code fragment? c for (int i = 1; i <= n; i++) for (int j = i; j <= n; j += i) work(); // O(1)
- What value of count does this code print for n = 16? c int count = 0; for (int i = n; i > 0; i /= 2) for (int j = 0; j < i; j++) count++…