Answered step by step
Verified Expert Solution
Question
1 Approved Answer
a)Briefly explain what is the complexity of your algorithm. More specifically, has your solution has an acceptable complexity; is it scalable enough; etc. If not,
a)Briefly explain what is the complexity of your algorithm. More specifically, has your solution has an acceptable complexity; is it scalable enough; etc. If not, what are the reasons behind that? b)Explain the details of your algorithm, and provide its time and space complexity. You must clearly justify how you estimated the complexity of your solution.
c)Compare the complexities between the two versions.
static void UnHide(char[] row, int index, PrintStream p){ if(row.length == index){ System.out.println(row); p.println(row); } else if(row[index] == '#') { row[index] = 'X'; UnHide(row, index + 1, p); row[index] = 'O'; UnHide(row, index + 1, p); row[index] = '#'; } else UnHide(row, index+1, p); } static void IterativeUnhide(String row,PrintStream p){ ArrayLista = new ArrayList<>(); int index; a.add(row); while (!a.isEmpty()){ String temp = a.get(0); a.remove(0); if((index = temp.indexOf('#'))!=-1) { temp = temp.substring(0, index) + 'X' + temp.substring(index + 1); a.add(temp); temp = temp.substring(0, index) + 'O' + temp.substring(index + 1); a.add(temp); } else { System.out.println(temp); p.println(temp); } } }
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