Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Function Name: deepestPath Inputs: 1. (cell) A 1xN nested cell array Outputs 1.

ID: 3700478 • Letter: F

Question

Function Name: deepestPath Inputs: 1. (cell) A 1xN nested cell array Outputs 1. (char) A character vector describing the deepest path in the woods. Background Recursion just shook your entire world and sense of well being. You no longer can tell left from right, or a double from a char. To get a grip on reality, you decide to take a long, introspective walk into the depths of a nearby forest. You have several different path options and you are trying to decide which one will give you the longest path before you reach a dead end. You quickly realize the complexity of the situation, and you are about to give up when you find a map! Alas, a solution! The map you found is a map of nested cell arrays, and you immediately know what to do. Function Description: Write a recursive function that will search through a nested cell array to find the maximum depth of nested cells. Then output the string 'The deepest path is ca(1, (true,(4,( trees, ((f8, ' »>description- deepestPath(ca) description The deepest path is 4 cells deep. Notes: . It does not matter what is found inside of the nested cell. You are only concerned with the depth. Hints: . What should the depth be when the input is not a cell/cell array? . You will need a wrapper function to format the output string. . Consider how you can call the recursive function on every element in the cell array

Explanation / Answer

function d = recursive_depth(C)

%C is the nested cell array

d = 0 % initial value

for i=1:length(C)

if isnumeric(C{i})

C{i} %to show the order of traversal

d=d+C{i}

else

d=d+recursive_depth(C{i});

end

end

end

%d will be the required deepest path