0
0
DSA Cprogramming~10 mins

Word Search in Grid Using Backtracking in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the current cell matches the current character of the word.

DSA C
if (board[row][col] == [1]) {
    // proceed with backtracking
}
Drag options to blanks, or click blank then click option'
A'*'
Bword[0]
C'\0'
Dword[index]
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with word[0] always checks only the first character.
Using '*' or '\0' does not check the correct character.
2fill in blank
medium

Complete the code to mark the current cell as visited by replacing it with a special character.

DSA C
char temp = board[row][col];
board[row][col] = [1];

// backtracking calls

board[row][col] = temp;
Drag options to blanks, or click blank then click option'
A'*'
B'#'
C'\0'
D' '
Attempts:
3 left
💡 Hint
Common Mistakes
Using '\0' can cause string termination issues.
Using ' ' (space) might be confusing if spaces are in the grid.
3fill in blank
hard

Fix the error in the recursive call to explore the next character in the word.

DSA C
if (backtrack(board, word, row + 1, col, [1], rows, cols) ||
    backtrack(board, word, row - 1, col, [1], rows, cols) ||
    backtrack(board, word, row, col + 1, [1], rows, cols) ||
    backtrack(board, word, row, col - 1, [1], rows, cols)) {
    return 1;
}
Drag options to blanks, or click blank then click option'
Aindex - 1
Bindex
Cindex + 1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using index without increment causes infinite loops.
Decrementing index goes backward in the word.
4fill in blank
hard

Fill both blanks to check if the current position is out of bounds or the cell is already visited.

DSA C
if (row [1] 0 || row [2] rows || col < 0 || col >= cols || board[row][col] == '*') {
    return 0;
}
Drag options to blanks, or click blank then click option'
A<
B>=
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' for lower bound allows -1 which is invalid.
Using '>' for upper bound misses the last valid index.
5fill in blank
hard

Fill all three blanks to complete the main function that starts the search for the word in the grid.

DSA C
int exist(char** board, int boardSize, int* boardColSize, char* word) {
    for (int i = 0; i < boardSize; i++) {
        for (int j = 0; j < [1]; j++) {
            if (backtrack(board, word, i, j, 0, boardSize, [2])) {
                return [3];
            }
        }
    }
    return 0;
}
Drag options to blanks, or click blank then click option'
A*boardColSize
BboardColSize[0]
C1
DboardSize
Attempts:
3 left
💡 Hint
Common Mistakes
Using boardSize for columns is incorrect.
Returning 0 inside the loop misses found words.