Answered step by step
Verified Expert Solution
Question
1 Approved Answer
What are the time and space complexity of the following two algorithms? static void UnHide(char[] row, int index, PrintStream p){ if(row.length == index){ System.out.println(row); p.println(row);
What are the time and space complexity of the following two algorithms?
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