1How 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
Correct Answer: It examines elements one by one
Explanation:
Sequential search checks each element in order until the target is found or the list ends.
Incorrect! Try again.
2What is the worst-case time complexity of sequential search on a list of elements?
Sequential Search
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
In the worst case, sequential search must examine all elements.
Incorrect! Try again.
3What 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
Correct Answer: It compares the pattern with the text
Explanation:
The brute-force method aligns the pattern at each possible text position and compares corresponding characters.
Incorrect! Try again.
4For 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.
Correct Answer:
Explanation:
A pattern of length can begin at any of the valid starting positions.
Incorrect! Try again.
5After 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
Correct Answer: One position
Explanation:
Naive pattern matching shifts the pattern one position to the right after each unsuccessful alignment.
Incorrect! Try again.
6Which 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
Correct Answer: No preprocessing
Explanation:
The naive algorithm directly compares characters and does not require a preprocessing phase.
Incorrect! Try again.
7Which 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
Correct Answer: Hash-value comparison
Explanation:
Rabin-Karp compares hash values of the pattern and text windows to identify possible matches.
Incorrect! Try again.
8What 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
Correct Answer: Verify the characters directly
Explanation:
Equal hash values may result from a collision, so the actual characters must be compared.
Incorrect! Try again.
9What 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
Correct Answer: Two strings have the same hash
Explanation:
A collision occurs when different strings produce the same hash value.
Incorrect! Try again.
10Which 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
Correct Answer: LPS table
Explanation:
KMP builds the LPS table, which records the longest proper prefix that is also a suffix.
Incorrect! Try again.
11What 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
Correct Answer: Longest Proper Prefix which is also a Suffix
Explanation:
LPS identifies reusable prefix and suffix information after a mismatch.
Incorrect! Try again.
12What 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.
Correct Answer:
Explanation:
KMP preprocesses the pattern in time and searches the text in time.
Incorrect! Try again.
13What 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
Correct Answer: All suffixes in sorted order
Explanation:
A suffix array records the starting positions of a string's suffixes in lexicographically sorted order.
Incorrect! Try again.
14Which 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
Correct Answer: Array
Explanation:
An array stores characters at indexed positions, allowing direct access to a character by its index.
Incorrect! Try again.
15What 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
Correct Answer: String prefixes
Explanation:
Each path from the root spells a prefix formed by the characters on its edges or nodes.
Incorrect! Try again.
16Which operation is a trie especially useful for?
Trie (Prefix Tree)
Easy
A.Graph coloring
B.Matrix multiplication
C.Prefix searching
D.Numeric integration
Correct Answer: Prefix searching
Explanation:
A trie organizes strings by shared prefixes, making prefix searches efficient.
Incorrect! Try again.
17What 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
Correct Answer: Find the two nearest points
Explanation:
The closest-pair problem asks for the pair of points having the minimum distance.
Incorrect! Try again.
18What is the time complexity of checking every pair among points?
Closest-Pair Problem
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
There are pairs, so checking every pair takes time.
Incorrect! Try again.
19What 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
Correct Answer: The smallest convex boundary containing all points
Explanation:
The convex hull is the smallest convex shape that encloses every point in the set.
Incorrect! Try again.
20Which 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
Correct Answer: A rubber band around nails
Explanation:
A stretched rubber band around a set of nails forms the outer convex boundary, like a convex hull.
Incorrect! Try again.
21A 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
Correct Answer: 5 comparisons
Explanation:
The search compares 11 with 14, 8, 23, 5, and finally 11, giving 5 comparisons.
Incorrect! Try again.
22A 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.
Correct Answer:
Explanation:
The average of the possible comparison counts is .
Incorrect! Try again.
23Using 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
Correct Answer: 9 comparisons
Explanation:
There are alignments. Each alignment compares all 3 characters, so the total is .
Incorrect! Try again.
24For 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.
Correct Answer:
Explanation:
There are possible alignments, and up to characters may be compared at each alignment.
Incorrect! Try again.
25Using 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
Correct Answer: Positions 0 and 2
Explanation:
The substrings beginning at indices 0 and 2 are both ABA. Naive matching can detect overlapping occurrences.
Incorrect! Try again.
26The 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
Correct Answer: 12 comparisons
Explanation:
The pattern is tested at four alignments. Each requires 3 comparisons, including the successful alignment, for a total of .
Incorrect! Try again.
27In 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
Correct Answer: 8
Explanation:
The new window represents 63, and . The rolling-hash update gives the same result.
Incorrect! Try again.
28During 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
Correct Answer: Verify their characters directly
Explanation:
Different strings can have the same hash because of collisions. Character-by-character verification confirms whether the match is genuine.
Incorrect! Try again.
29What 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.
Correct Answer:
Explanation:
If collisions occur at many alignments, each candidate window may require up to character comparisons, producing time.
Incorrect! Try again.
30What 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]
Correct Answer: [0, 0, 1, 2, 0, 1, 2, 3, 4]
Explanation:
Each LPS value records the longest proper prefix that is also a suffix for the pattern prefix ending at that position.
Incorrect! Try again.
31KMP 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
Correct Answer: 3
Explanation:
The LPS value for ABABA is 3 because ABA is its longest proper prefix that is also a suffix.
Incorrect! Try again.
32Using 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
Correct Answer: Positions 0, 1, and 2
Explanation:
The pattern occurs at indices 0, 1, and 2. KMP uses the LPS array after each match, allowing overlapping occurrences.
Incorrect! Try again.
33What 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]
Correct Answer: [5, 3, 1, 0, 4, 2]
Explanation:
The sorted suffixes are a, ana, anana, banana, na, and nana, starting at indices 5, 3, 1, 0, 4, and 2.
Incorrect! Try again.
34A 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.
Correct Answer:
Explanation:
Binary search examines suffixes, and each suffix comparison may inspect up to pattern characters.
Incorrect! Try again.
35How 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
Correct Answer: 8 nodes
Explanation:
The trie has one root, four nodes for the shared ca branches forming cat and car, and three nodes for dog, totaling 8.
Incorrect! Try again.
36A 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.
Correct Answer:
Explanation:
The prefix requires following edges. Once its node is reached, the stored count can be returned immediately.
Incorrect! Try again.
37Which pair is closest among the points , , , and ?
Closest-Pair Problem
Medium
A. and
B. and
C. and
D. and
Correct Answer: and
Explanation:
Their distance is , which is smaller than the distances between the other listed pairs.
Incorrect! Try again.
38What 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.
Correct Answer:
Explanation:
The recurrence is , which solves to .
Incorrect! Try again.
39For points , , and , what orientation does the ordered triplet have?
Convex Hull
Medium
A.Counterclockwise
B.Undefined
C.Clockwise
D.Collinear
Correct Answer: Counterclockwise
Explanation:
The cross product is positive, so the turn from to is counterclockwise.
Incorrect! Try again.
40Consider the points , , , , and . Which sequence gives the convex hull in counterclockwise order starting from ?
Convex Hull
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The four corner points form the boundary of the square. The point lies strictly inside and is not part of the convex hull.
Incorrect! Try again.
41An 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.
Correct Answer:
Explanation:
The stopping position is the minimum of uniformly selected positions. The expected minimum discrete order statistic is .
Incorrect! Try again.
42Four 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
Correct Answer: with expectation
Explanation:
Keys should be ordered by decreasing successful-search probability. The expectation is .
Incorrect! Try again.
43A 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.
Correct Answer:
Explanation:
There are alignments. Each compares three matching characters and then mismatches on , giving comparisons.
Incorrect! Try again.
44For 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.
Correct Answer:
Explanation:
Every one of the alignments matches the first characters and fails on the final character, so each alignment costs comparisons.
Incorrect! Try again.
45The 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.
Correct Answer:
Explanation:
Shifts require four comparisons each, while shifts fail on the first comparison. Thus the total is .
Incorrect! Try again.
46Rabin-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.
Correct Answer:
Explanation:
Here . The update is , matching .
Incorrect! Try again.
47Using 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
Correct Answer: hash hits, spurious
Explanation:
The pattern hash is . Windows also hash to , but only is an exact match, giving three spurious hits.
Incorrect! Try again.
48A 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.
Correct Answer:
Explanation:
If every alignment has the same hash as the pattern, each of the windows may require verification comparisons.
Incorrect! Try again.
49Using zero-based indexing, what is the KMP prefix-function array for the pattern ?
Knuth-Morris-Pratt Algorithm
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Each value gives the longest proper prefix that is also a suffix of the prefix ending at that position. In particular, the sixth character falls back from length to before extending to .
Incorrect! Try again.
50For , 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.
Correct Answer:
Explanation:
The expected character at state is , so KMP falls back to the border of length . The incoming then extends it to , giving state .
Incorrect! Try again.
51KMP 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
Correct Answer: Positions ; fall back to state
Explanation:
The longest proper border of is , of length . Falling back to that state preserves overlaps and produces matches at shifts .
Incorrect! Try again.
52For 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.
Correct Answer:
Explanation:
A length- string has substring occurrences. Subtracting repeated prefixes counted by adjacent LCP values gives .
Incorrect! Try again.
53A 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.
Correct Answer:
Explanation:
Suffixes beginning with the pattern form one contiguous suffix-array interval. Each binary-search comparison may inspect characters, and reporting costs .
Incorrect! Try again.
54A 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.
Correct Answer:
Explanation:
The branch has five distinct nonempty prefixes: . The branch has six: . Including the root gives .
Incorrect! Try again.
55A 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.
Correct Answer:
Explanation:
The compacted trie has leaves, and every internal node has at least two children. Such a rooted tree has at most internal nodes, hence at most nodes.
Incorrect! Try again.
56In 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.
Correct Answer:
Explanation:
Partitioning the relevant region into smaller cells shows that at most seven later points can lie close enough to require comparison.
Incorrect! Try again.
57A 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.
Correct Answer:
Explanation:
Repeated sorting adds work at the root scale and comparable aggregate costs across levels, yielding .
Incorrect! Try again.
58For the point set , which sequence lists exactly the convex-hull vertices in counterclockwise order, starting at ?
Convex Hull
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
These six points form successive counterclockwise turns and contain all remaining points. Removing any listed vertex would exclude an extreme point, while the other points lie inside the polygon.
Incorrect! Try again.
59In 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
Correct Answer: Retain only the farthest point on each equal-angle ray
Explanation:
Nearer points on the same ray lie between the pivot and the farthest point, so they cannot be hull vertices when collinear boundary points are excluded.
Incorrect! Try again.
60In 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
Correct Answer: Choose the farthest collinear point; running time is
Explanation:
Selecting the farthest point prevents interior collinear boundary points from becoming hull vertices. Jarvis march scans all points for each of the hull vertices.
Incorrect! Try again.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill.
The rest comes out of a student's own pocket: the domain, the storage,
and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it.
What it pays for →