StudySmarter AI is coming soon!

- :00Days
- :00Hours
- :00Mins
- 00Seconds

A new era for learning is coming soonSign up for free

Suggested languages for you:

Americas

Europe

Q31E

Expert-verifiedFound in: Page 203

Book edition
7th

Author(s)
Kenneth H. Rosen

Pages
808 pages

ISBN
9780073383095

**Devise an algorithm that finds the first term of a sequence of integers that equals some previous term in the sequence.**

An algorithm of determining the first term of a sequence of inters that equals some previous term in the sequence.

** procedure**** **repeated ( ${a}_{1},{a}_{2},...,{a}_{n}:$ list of integers having n > 0 )

$j=2\phantom{\rule{0ex}{0ex}}position:=0$

** while** $j\le n$ and position = 0

will show the position of the first term of a sequence of integers that equals some previous term in the sequence.

First set j equals to 2 and position equals to 0 .

Then use while loop to examine given list and condition for while loop is $j\le n$ and position = 0 .

In while loop set k equal to 1 and use another while loop with condition k < j and position + 0 . Compare ${a}_{j}$ and ${a}_{k}$ using the if loop with condition ${a}_{j}={a}_{k}$ and when if loop becomes true, return then position as and when if loop becomes false then increase k by 1 . After the completion of if loop increase j by 1 .

Here the position is our required answer.

By using the above conditions, the algorithm finds the first term of a sequence of inters that equals some previous term in the sequence can be written as:

**procedure**** **repeated ( ${a}_{1},{a}_{2},..,{a}_{n}:$ list of integers having n > 0 )

j = 2

position : = 0

** while** $j\le n$ and position = 0

94% of StudySmarter users get better grades.

Sign up for free