• :00Days
• :00Hours
• :00Mins
• 00Seconds
A new era for learning is coming soon Suggested languages for you:

Europe

Answers without the blur. Sign up and see all textbooks for free! Q31E

Expert-verified Found in: Page 203 ### Discrete Mathematics and its Applications

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.

See the step by step solution

## Step 1: Write the steps required to follow to determine Algorithm.

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.

## Step 2: Determine the steps of the algorithm.

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 ### Want to see more solutions like these? 