0
0
DSA Javascriptprogramming~5 mins

Search in 2D Matrix in DSA Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main idea behind searching in a 2D matrix where each row and column is sorted?
Start from the top-right corner and move left if the current number is greater than the target, or move down if it is smaller. This way, you eliminate a row or column each step.
Click to reveal answer
beginner
Why is starting from the top-right corner effective in searching a sorted 2D matrix?
Because from the top-right, moving left decreases the value and moving down increases the value, helping to decide the direction to move based on comparison with the target.
Click to reveal answer
intermediate
What is the time complexity of searching in a sorted 2D matrix using the top-right corner approach?
O(m + n), where m is the number of rows and n is the number of columns, because each step moves either one row down or one column left.
Click to reveal answer
beginner
Show the step-by-step search process for target 5 in this matrix: [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
Start at top-right (7): 7 > 5, move left to 4: 4 < 5, move down to 5: found target.
Click to reveal answer
beginner
What happens if the target is not in the matrix when using the top-right corner search method?
The search moves out of the matrix boundaries (row index exceeds or column index becomes negative), and the target is concluded to be absent.
Click to reveal answer
In a sorted 2D matrix, where should you start searching for a target to use the efficient approach?
ATop-right corner
BBottom-left corner
CTop-left corner
DBottom-right corner
If the current number is greater than the target during the search, what is the next move?
AMove down
BMove right
CMove left
DMove up
What is the time complexity of searching in a sorted 2D matrix using the top-right corner method?
AO(m * n)
BO(m + n)
CO(1)
DO(log(m * n))
If the target is smaller than the current number, which direction do you move?
ALeft
BDown
CRight
DUp
What condition ends the search when the target is not found?
AColumn index < 0 only
BColumn index > number of columns
CRow index < 0
DRow index >= number of rows or column index < 0
Explain how to search for a target in a 2D matrix where each row and column is sorted.
Think about how to eliminate rows or columns step by step.
You got /5 concepts.
    Describe the time complexity and why the top-right corner approach is efficient for searching in a sorted 2D matrix.
    Consider how many steps maximum the search can take.
    You got /4 concepts.