Practice 2 Example 1: Input: image = [ [1,1,1], [1,1,e], [1,0,1]] sr = e, sc = 0, newColor = 2 Output: [ [2,2,2], [2,2,0], [2,0,1]] An image is represented by a 2-D array of integers, each integer representing the pixel value of the image . Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. Explanation: From the center of the image (with position (sr, sc) = (0, e)), all pixels connected by a path of the same color as the starting pixel are colored with the new color. Note the bottom corner is not colored 2, because it is not 4-directionally connected to the starting pixel. To perform a "flood fill", consider the starting pixel, plus any pixels connected 4-directionally to the starting pixel of the same color as the starting pixel, plus any pixels connected 4-directionally to those pixels (also with the same color as the starting pixel), and so on. Replace the color of all of the aforementioned class FloorDFS { public void static main(String[] args) { int[][] image = . // initialization int newColor = .. // initialization image = floorFill(image, e, e, newColor); } pixels with the newColor. At the end, return the modified image. public int[][]] floodFill(int[][] image, int sr, int sc, int newColor) { }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Topic Video
Question

Please answer the question in the screenshot. The language used here is Java. Please use the starting code. 

 

Practice 2
Example 1:
Input:
image = [
[1,1,1],
[1,1,0],
[1,0,1]]
sr = 0, sc = 0, newColor = 2
Output: [
[2,2,2],
[2,2,0],
[2,0,1]]
An image is represented by a 2-D array
of integers, each integer representing
the pixel value of the image .
Given a coordinate (sr, sc) representing
the starting pixel (row and column) of
the flood fill, and a pixel value
newColor, "flood fill" the image.
Explanation:
From the center of the image (with position (sr, sc) = (0, 0)),
all pixels connected by a path of the same color as the starting
pixel are colored with the new color.
Note the bottom corner is not colored 2, because it is not
4-directionally connected to the starting pixel.
To perform a "flood fill", consider the
starting pixel, plus any pixels
connected 4-directionally to the
starting pixel of the same color as the
starting pixel, plus any pixels
connected 4-directionally to those
pixels (also with the same color as the
starting pixel), and so on. Replace the
color of all of the aforementioned
class FloorDFS {
public void static main(String[] args) {
int[][] image = . // initialization
int newColor = . // initialization
image = floorFill(image, e, e, newColor);
}
pixels with the newColor. At the end,
return the modified image.
public int[][] floodFill(int[][] image, int sr, int sc, int newColor) {
}
Transcribed Image Text:Practice 2 Example 1: Input: image = [ [1,1,1], [1,1,0], [1,0,1]] sr = 0, sc = 0, newColor = 2 Output: [ [2,2,2], [2,2,0], [2,0,1]] An image is represented by a 2-D array of integers, each integer representing the pixel value of the image . Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. Explanation: From the center of the image (with position (sr, sc) = (0, 0)), all pixels connected by a path of the same color as the starting pixel are colored with the new color. Note the bottom corner is not colored 2, because it is not 4-directionally connected to the starting pixel. To perform a "flood fill", consider the starting pixel, plus any pixels connected 4-directionally to the starting pixel of the same color as the starting pixel, plus any pixels connected 4-directionally to those pixels (also with the same color as the starting pixel), and so on. Replace the color of all of the aforementioned class FloorDFS { public void static main(String[] args) { int[][] image = . // initialization int newColor = . // initialization image = floorFill(image, e, e, newColor); } pixels with the newColor. At the end, return the modified image. public int[][] floodFill(int[][] image, int sr, int sc, int newColor) { }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education