Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Let us consider a digital image whose colors are represented by an n x n matrix C. Each entry Cij of this matrix gives the
Let us consider a digital image whose colors are represented by an n x n matrix C. Each entry Cij of this matrix gives the color of the pixel representing the coordinate (i, j) of the image (for instance cn,l corresponds to the color of the pixel at the left bottom corner and C1,n to the right top corner etc. ). For simplicity, let's assume that there are only four colors in this image: BW,R,G (i.e. Cij E {BW, R, G} for all i, j). (a) (7 points) Devise an algorithm in pseudo-code that changes the colors of all Red (R) pixels to Green (G) and all G pixels to R (B and W pixels are unchanged) and keeps the tracks of the total number of changes that take place. Your algorithm takes as input the matrix C and returns a modified n x n matrix Cmod and an integer change counter chnumber. (b) (3 points) Express the number of operations required for this algo- rithm and find the worst-case computational complexity (a big-O estimate). (c) (3 points) Assume now that C contains R and G pixels only in the rightmost 4 columns of the matrix. Modify the previous algorithm to improve the number of coperations. ick Save and Submit to save and submit. Click Save All Answers to save all answers
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started