A coding problem requires finding the longest common substring of two strings. What is the optimal approach?
ABrute force checking all substrings - O(n³) time
BDynamic Programming approach - O(n²) time and space
CUsing two pointers - O(n) time
DRecursive approach without memoization
Correct Answer:
B. Dynamic Programming approach - O(n²) time and space
Explanation:
Dynamic Programming is the standard approach for longest common substring problems, building a table of subproblem results with O(n²) time and space complexity.
In a complex algorithm with multiple nested loops, the time complexity is O(n²m) where n and m are independent variables. If n=100 and m=50, approximately how many operations?
A150 operations
B500,000 operations
C1,000,000 operations
D2,500,000 operations
Correct Answer:
B. 500,000 operations
Explanation:
Operations = 100² × 50 = 10,000 × 50 = 500,000 operations. This represents the actual computational load for the given input sizes.
iGET uses cookies for essential site functionality, analytics, and ads personalization (via Google AdSense). By clicking "Accept", you consent to our use of cookies.
Privacy Policy ·
Disclaimer