Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

5 1 0 4 2 3 0 1 2 3 4 5 a 1 . a is a list of 'int' 2 . Length of

510423
012345
a
1. a is a list of 'int'
2. Length of list a is NOT known. YOU CANNOT CALL len(a)
3. If the length of the list is 6(as shown above)
the content of the array is guaranteed to be between 0 to 5.
THERE IS NO REPETATION of numbers
a =[5,1,0,4,2,3];
int h = hop(a,3);
Your task is to find the number of hops to get 3, which is defined as follows:
The top level call is as follows:
a[3]=4
a[4]=2
a[2]=0
a[0]=5
a[5]=3
h = Number of hop is =4
You start from a[x], in this case x =3, a[3]=4, and keep looping
until you get x, which is 3. The number of times you hoped, in this example, is h =4.
One way, to write, using while loop is:
Now write "hop" subroutine as follows:
1. You cannot change interface of hop function
2. You cannot use global/static variables
3. You cannot use any loop statements
like while, do, for and goto
4. You cannot call any function except _hop
5. Your code should not be more than 10 lines
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions

Question

2 What are the implications for logistics strategy?

Answered: 1 week ago

Question

Determine the amplitude and period of each function.

Answered: 1 week ago

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago