Computer Science: An Overview: Global Edition (12th Edition)

Published by Pearson Higher Education
ISBN 10: 1292061162
ISBN 13: 978-1-29206-116-0

Chapter 8 - Data Abstractions - Chapter Review Problems - Page 408: 4

Answer

See the explanation

Work Step by Step

Here's a Python function that fulfills the described functionality: ```python def set_zeroes(matrix): rows, cols = len(matrix), len(matrix[0]) zero_rows, zero_cols = set(), set() # Find rows and columns with zeros for i in range(rows): for j in range(cols): if matrix[i][j] == 0: zero_rows.add(i) zero_cols.add(j) # Set entire rows to zero for row in zero_rows: matrix[row] = [0] * cols # Set entire columns to zero for col in zero_cols: for i in range(rows): matrix[i][col] = 0 ``` This function takes a matrix as input and sets the entire row and column to zero if any element in the matrix is zero.
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.