Unit 2: String Matching Algorithms and Computational Geometry - Practice Quiz

CSE408 — Design And Analysis Of Algorithms 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 How does sequential search look for a target element in a list?

Sequential Search Easy
A. It first sorts all elements
B. It compares only adjacent elements
C. It examines elements one by one
D. It repeatedly divides the list

2 What is the worst-case time complexity of sequential search on a list of elements?

Sequential Search Easy
A.
B.
C.
D.

3 What does brute-force string matching do at each possible position in the text?

Brute-Force String Matching Easy
A. It builds a prefix tree
B. It compares the pattern with the text
C. It hashes the entire text
D. It sorts the pattern characters

4 For a text of length and a pattern of length , how many possible alignments are checked by brute-force matching?

Brute-Force String Matching Easy
A.
B.
C.
D.

5 After a mismatch, how far does the naive pattern-matching algorithm normally shift the pattern?

Naive Pattern Matching Easy
A. Two positions
B. One position
C. Half the pattern
D. The full pattern

6 Which preprocessing step is required by the basic naive pattern-matching algorithm?

Naive Pattern Matching Easy
A. Sorting the text
B. Building a hash table
C. No preprocessing
D. Computing an LPS array

7 Which technique is central to the Rabin-Karp string-matching algorithm?

Rabin-Karp Algorithm Easy
A. Hash-value comparison
B. Geometric partitioning
C. Character sorting
D. Prefix-tree traversal

8 What should Rabin-Karp do when a text window and the pattern have the same hash value?

Rabin-Karp Algorithm Easy
A. Restart from the beginning
B. Verify the characters directly
C. Report a match immediately
D. Sort the matching window

9 What is a hash collision in Rabin-Karp?

Rabin-Karp Algorithm Easy
A. Two strings have the same hash
B. Two strings have equal lengths
C. Two patterns start together
D. Two characters exchange positions

10 Which table is constructed during preprocessing in the KMP algorithm?

Knuth-Morris-Pratt Algorithm Easy
A. LPS table
B. Distance table
C. Hash table
D. Adjacency table

11 What does LPS stand for in the KMP algorithm?

Knuth-Morris-Pratt Algorithm Easy
A. Linear Prefix Scan
B. Longest Pattern Search
C. Last Position Shift
D. Longest Proper Prefix which is also a Suffix

12 What is the time complexity of KMP for a text of length and a pattern of length ?

Knuth-Morris-Pratt Algorithm Easy
A.
B.
C.
D.

13 What does a suffix array store?

Data Structures for String Processing Easy
A. All prefixes in insertion order
B. All hashes in random order
C. All characters in reverse order
D. All suffixes in sorted order

14 Which data structure stores characters in indexed, contiguous positions and allows direct character access?

Data Structures for String Processing Easy
A. Stack
B. Array
C. Graph
D. Queue

15 What do paths from the root of a trie represent?

Trie (Prefix Tree) Easy
A. String prefixes
B. Geometric angles
C. Numeric distances
D. Sorted coordinates

16 Which operation is a trie especially useful for?

Trie (Prefix Tree) Easy
A. Graph coloring
B. Matrix multiplication
C. Prefix searching
D. Numeric integration

17 What is the goal of the closest-pair problem?

Closest-Pair Problem Easy
A. Find all collinear points
B. Find the outermost points
C. Find the two nearest points
D. Find the two largest points

18 What is the time complexity of checking every pair among points?

Closest-Pair Problem Easy
A.
B.
C.
D.

19 What is the convex hull of a set of points?

Convex Hull Easy
A. The smallest convex boundary containing all points
B. The circle centered at the first point
C. The shortest path through all points
D. The longest line joining two points

20 Which everyday analogy commonly describes a convex hull?

Convex Hull Easy
A. A ruler joining every pair
B. A compass drawing equal circles
C. A grid covering all coordinates
D. A rubber band around nails

21 A sequential search is performed on the array [14, 8, 23, 5, 11, 19] to find the key 11. How many element comparisons are made?

Sequential Search Medium
A. 6 comparisons
B. 4 comparisons
C. 3 comparisons
D. 5 comparisons

22 A key is known to be present in an unsorted array of elements, and every position is equally likely to contain it. What is the expected number of comparisons made by sequential search?

Sequential Search Medium
A.
B.
C.
D.

23 Using brute-force string matching, how many character comparisons are made when searching for pattern aaa in text aaaaa, assuming all possible alignments are checked?

Brute-Force String Matching Medium
A. 15 comparisons
B. 9 comparisons
C. 7 comparisons
D. 6 comparisons

24 For a text of length and a pattern of length , which expression gives the worst-case number of character comparisons in brute-force string matching?

Brute-Force String Matching Medium
A.
B.
C.
D.

25 Using 0-based indexing, at which positions does the naive pattern-matching algorithm find pattern ABA in text ABABA?

Naive Pattern Matching Medium
A. Position 0 only
B. Positions 1 and 2
C. Positions 0 and 3
D. Positions 0 and 2

26 The naive algorithm searches for pattern AAB in text AAAAAB. How many character comparisons are performed before the match is found?

Naive Pattern Matching Medium
A. 9 comparisons
B. 10 comparisons
C. 12 comparisons
D. 11 comparisons

27 In Rabin-Karp, decimal digits are hashed using base and modulus . The current window 26 has hash 4. After sliding to window 63, what is the new hash?

Rabin-Karp Algorithm Medium
A. 8
B. 9
C. 6
D. 4

28 During Rabin-Karp matching, a text window and the pattern have equal hash values. What should the algorithm do next?

Rabin-Karp Algorithm Medium
A. Treat the equal hashes as a guaranteed match without examining the actual characters
B. Shift the pattern by its length
C. Recompute every previous window hash
D. Verify their characters directly

29 What is the worst-case time complexity of Rabin-Karp when many text windows have the same hash as the pattern?

Rabin-Karp Algorithm Medium
A.
B.
C.
D.

30 What is the LPS array for the pattern ABABCABAB?

Knuth-Morris-Pratt Algorithm Medium
A. [0, 1, 1, 2, 0, 1, 2, 3, 4]
B. [0, 0, 1, 2, 0, 1, 2, 3, 3]
C. [0, 0, 1, 2, 0, 1, 2, 3, 4]
D. [0, 0, 1, 2, 3, 1, 2, 3, 4]

31 KMP has matched the first five characters ABABA of pattern ABABAC. The next text character causes a mismatch with C. To what matched-prefix length does KMP first fall back?

Knuth-Morris-Pratt Algorithm Medium
A. 3
B. 1
C. 5
D. 0

32 Using 0-based indexing, which starting positions will KMP report when searching for pattern AAA in text AAAAA?

Knuth-Morris-Pratt Algorithm Medium
A. Positions 0, 2, and 4
B. Positions 0 and 2
C. Position 0 only
D. Positions 0, 1, and 2

33 What is the suffix array of the string banana, represented as the starting indices of suffixes in lexicographic order?

Data Structures for String Processing Medium
A. [0, 1, 2, 3, 4, 5]
B. [1, 3, 5, 0, 2, 4]
C. [5, 1, 3, 0, 2, 4]
D. [5, 3, 1, 0, 4, 2]

34 A suffix array for a text of length has already been built. If comparing a pattern of length with a suffix costs , what is the basic binary-search time for finding the pattern?

Data Structures for String Processing Medium
A. because every suffix must be compared completely with the pattern
B.
C.
D.

35 How many nodes are required to store the words cat, car, and dog in a standard trie, including the root and assuming end-of-word markers are not separate nodes?

Trie (Prefix Tree) Medium
A. 9 nodes
B. 7 nodes
C. 8 nodes
D. 10 nodes

36 A trie stores many words and keeps a word-count value at every node. What is the time complexity of counting words beginning with a prefix of length ?

Trie (Prefix Tree) Medium
A.
B.
C.
D.

37 Which pair is closest among the points , , , and ?

Closest-Pair Problem Medium
A. and
B. and
C. and
D. and

38 What is the time complexity of the divide-and-conquer closest-pair algorithm when points are maintained in sorted order during recursion?

Closest-Pair Problem Medium
A.
B. because every possible pair must still be tested after dividing the plane
C.
D.

39 For points , , and , what orientation does the ordered triplet have?

Convex Hull Medium
A. Counterclockwise
B. Undefined
C. Clockwise
D. Collinear

40 Consider the points , , , , and . Which sequence gives the convex hull in counterclockwise order starting from ?

Convex Hull Medium
A.
B.
C.
D.

41 An array of length contains exactly occurrences of a target. Their positions are chosen uniformly from all -element subsets of . Sequential search stops at the first occurrence. What is the expected number of inspected elements?

Sequential Search Hard
A.
B.
C.
D.

42 Four distinct keys have successful-search probabilities , respectively; an unsuccessful search has probability . A failed sequential search examines all four keys. Which ordering minimizes the expected number of comparisons, and what is that expectation?

Sequential Search Hard
A. with expectation
B. with expectation
C. with expectation
D. with expectation

43 A brute-force matcher compares characters left to right and stops an alignment at its first mismatch. For and , how many character comparisons are performed over all possible alignments?

Brute-Force String Matching Hard
A.
B.
C.
D.

44 For text length and pattern searched in , what exact number of character comparisons does left-to-right brute-force matching perform?

Brute-Force String Matching Hard
A.
B.
C.
D.

45 The naive matcher tests every alignment, compares left to right, and stops on the first mismatch. For and , how many total character comparisons are made, including successful alignments?

Naive Pattern Matching Hard
A.
B.
C.
D.

46 Rabin-Karp uses radix , modulus , and window length . The current window is , whose hash is . After shifting to the window , what hash is obtained using the rolling-hash update?

Rabin-Karp Algorithm Hard
A.
B.
C.
D.

47 Using radix and modulus , Rabin-Karp searches for the two-digit pattern in . How many hash hits occur, and how many of them are spurious?

Rabin-Karp Algorithm Hard
A. hash hits, spurious
B. hash hits, spurious
C. hash hits, spurious
D. hash hits, spurious

48 A Rabin-Karp implementation verifies every hash hit character by character. Which worst-case running time remains possible for a single pattern of length in a text of length ?

Rabin-Karp Algorithm Hard
A.
B.
C.
D.

49 Using zero-based indexing, what is the KMP prefix-function array for the pattern ?

Knuth-Morris-Pratt Algorithm Hard
A.
B.
C.
D.

50 For , KMP is in state , meaning that has been matched. If the next text character is , what state is reached after all necessary fallback transitions?

Knuth-Morris-Pratt Algorithm Hard
A.
B.
C.
D.

51 KMP searches for in and must report overlapping matches. Which starting positions are reported, and to which state should it fall back immediately after each complete match?

Knuth-Morris-Pratt Algorithm Hard
A. Positions ; fall back to state
B. Positions ; fall back to state
C. Positions ; fall back to state
D. Positions ; fall back to state

52 For the string , the LCP values between lexicographically adjacent suffixes are . How many distinct nonempty substrings does contain?

Data Structures for String Processing Hard
A.
B.
C.
D.

53 A suffix array for a text of length is searched for a pattern of length using two ordinary binary searches, without LCP acceleration. If occurrences are reported, what is the worst-case query time?

Data Structures for String Processing Hard
A.
B.
C.
D.

54 A standard trie stores terminal status as a flag rather than as a separate node. After inserting , how many nodes does the trie contain, including the root?

Trie (Prefix Tree) Hard
A.
B.
C.
D.

55 A compacted trie stores prefix-free keys and suppresses every nonroot internal node of degree one. What is the maximum possible total number of nodes?

Trie (Prefix Tree) Hard
A.
B.
C.
D.

56 In the planar divide-and-conquer closest-pair algorithm, let be the smaller recursive distance. Candidate strip points are processed in increasing -order. Under the standard packing argument, how many subsequent strip points must each point be compared with at most?

Closest-Pair Problem Hard
A.
B.
C.
D.

57 A divide-and-conquer closest-pair implementation correctly divides by but re-sorts the points in each recursive subproblem by , costing per recursion level. What overall recurrence and running time result?

Closest-Pair Problem Hard
A.
B.
C.
D.

58 For the point set , which sequence lists exactly the convex-hull vertices in counterclockwise order, starting at ?

Convex Hull Hard
A.
B.
C.
D.

59 In Graham scan, several points have the same polar angle from the pivot. If the desired hull excludes nonvertex points lying along an edge, which tie treatment is correct?

Convex Hull Hard
A. Retain an arbitrary tied point from each equal-angle ray
B. Retain all tied points in decreasing distance order
C. Retain only the nearest point on each equal-angle ray
D. Retain only the farthest point on each equal-angle ray

60 In Jarvis march, multiple points may be collinear in the most counterclockwise direction from the current hull vertex. Which rule and complexity statement are correct for a hull with vertices?

Convex Hull Hard
A. Choose the nearest collinear point; running time is
B. Choose the farthest collinear point; running time is
C. Choose the farthest collinear point; running time is
D. Choose any collinear point; running time is