A function using recursion to determine number of stops between airports in MATLAB

Hey everyone, I have this MATLAB assignment that i need to create a function to solve the following question:
For the first one we let array (matrix) A, n x 2 represent n direct flight connections between cities which are represented by numbers. Cities i and j are directly connected if there is a row k in A such that A(k,1)=i and A(k,2)=j. Write a function, status = Connected(x,y,A) which would return 1 if city y can be reached from city x with stopovers (any number of them) and 0 otherwise.
For example if
A =
5 7
7 9
9 4
7 6
Then one can get directly from 7 to 9 and indirectly from 5 to 4 (two stopovers), as well as from 5 to 6 (one stopover at 7).
I know that we need to use recursion. I've also noticed that if x is connected to y and y is connected to z then x is connected to z. We should use this rule for the recursive call.
Base condition should just test for direct connectivity, aka check if x and y form one of the rows in A

1 Comment

You have accidentally omitted asking any question. What specifically are you asking for assistance with? For example, do you know how to define a function? Do you know what "recursion" means?

Answers (0)

This question is closed.

Products

Asked:

on 30 Mar 2011

Closed:

on 10 Jan 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!