Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Devise a recursive algorithm that counts the number of times the integer 0 occurs in a list of integers.

Exercises 70–77 deal with some unusual sequences, informally called

self-generating sequences, produced by simple recurrence relations or rules. In particular, Exercises 70–75 deal with the sequence\(\left\{ {{\bf{a}}\left( {\bf{n}} \right)} \right\}\)defined by\({\bf{a}}\left( {\bf{n}} \right){\bf{ = n - a}}\left( {{\bf{a}}\left( {{\bf{n - 1}}} \right)} \right)\)for\({\bf{n}} \ge {\bf{1}}\)and\({\bf{a}}\left( {\bf{0}} \right){\bf{ = 0}}\).(This sequence, as well as those in Exercises 74 and 75, are defined in Douglas Hofstader’s fascinating book Gödel, Escher, Bach ((Ho99)).

\(\)

Short Answer

Expert verified

Recursive algorithm has been found.

Step by step solution

Achieve better grades quicker with Premium

  • Unlimited AI interaction
  • Study offline
  • Say goodbye to ads
  • Export flashcards

Over 22 million students worldwide already upgrade their learning with Vaia!

01

Introduction

A recursive function is a function that its value at any point can be calculated from the values of the function at some previous points. For example, suppose a function\({\bf{f}}\left( {\bf{k}} \right){\bf{ = f}}\left( {{\bf{k - 2}}} \right){\bf{ + f}}\left( {{\bf{k - 3}}} \right)\)which is defined over non negative integer.

02

Step 2: Devise a recursive algorithm

Recurrence for number of multiplication used in algorithm:

\(T\left( 1 \right) = 0\), since the number of multiplications (base case)

Let\(T\left( n \right)\)be the number of multiplications that the function power\(\left( {b,n} \right)\)uses to compute\({b^n}\).

A recursive algorithm that counts the number of times the integer 0 occurs in q list of integers:

Procedure zero count

\(\left( {{x_1},{x_2},.............{x_n}:{\rm{ list of integers}}} \right)\)

If\(n = 1\)then

If\({x_1} = 0\)then zero count\(\left( {{x_1},{x_2},.............{x_n}} \right): = 1\)

Else zero count\(\left( {{x_1},{x_2},.............{x_n}} \right): = 0\)

Else

If\({x_n} = 0\)then zero count

\(\left( {{x_1},{x_2},.............{x_n}} \right): = {\rm{ zero count + }}\left( {{x_1},{x_2},.............{x_{n + 1}}} \right) + 1\)

Else zero count

\({\rm{zero count}}\left( {{x_1},{x_2},.............{x_n}} \right): = {\rm{zero count }}\left( {{x_1},{x_2},.............{x_{n - 1}}} \right)\)

Hence, recursive algorithm has been found.[a1] [a2]

[a2]Explain what each part of the program does

Then, again give the complete program at the end

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

How does the number of multiplications used by the algorithm in Exercise 26 compare to the number of multiplications used by Algorithm 2 to evaluate ana?

(a) Find the formula for 12+14+18++12n by examining the values of this expression for small values of n.

(b) Prove the formula you conjectured in part (a).

Let P (n) be the statement that a postage of n cents can be formed using just 3-cent stamps and 5-cent stamps. The parts of this exercise outline a strong induction proof that P (n) is true for n ≥ 8.

a) Show that the statements P (8), P (9), and P (10) are true, completing the basis step of the proof.

b) What is the inductive hypothesis of the proof?

c) What do you need to prove in the inductive step?

d) Complete the inductive step for k ≥ 10.

e) Explain why these steps show that this statement is true whenever n ≥ 8.

A jigsaw puzzle is put together by successively joining pieces that fit together into blocks. A move is made each time a piece is added to a block, or when two blocks are joined. Use strong induction to prove that no matter how the moves are carries out, exactlyn -1 moves are required to assemble a puzzle with n pieces.

The well-ordering property can be used to show that there is a unique greatest common divisor of two positive integers. Let a and be positive integers, and let S be the set of positive integers of the form as+bt, where s and t are integers.

a) Show that s is nonempty.

b) Use the well-ordering property to show that s has a smallest element .

c) Show that if d is a common divisor of a and b, then d is a divisor of c.

d) Show that c I a and c I b. [Hint: First, assume that cXa. Then a=qc+r, where 0<r<c. Show that rS, contradicting the choice of c.]

e) Conclude from (c) and (d) that the greatest common divisor of a and b exists. Finish the proof by showing that this greatest common divisor is unique.

See all solutions

Recommended explanations on Math Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free