Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

DO ALL PARTS 3. The following algorithm CountMultiples, takes as input a list of m 1 distinct positive integers and returns the number of list

DO ALL PARTS image text in transcribed image text in transcribed

3. The following algorithm CountMultiples, takes as input a list of m 1 distinct positive integers and returns the number of list elements that are a multiple of some prior list element. For example, on the input 2,6, 5, 9, 8, 3, 15, the algorithm would return 3 because there are 3 list elements that are a multiple of some prior list element 6 is a multiple of 2 8 is a multiple of 2 15 is a multiple of 5 (and it is a multiple of 3) procedure Count Multiples (a1 an: n 1) 1. if n 1 then return 0 2. count 0 3. m Count Multiples (a1, an-1) 4. for 1 to n -1 5. f a divides an then return. m 1 6. return m (a) Prove that CountMultiples is correct. Proof: We can prove that tiples is correct for any input of size n, using strong weak regular induction on n. For the base case, when n 1, Count Multiples returns 0 in line 1. This is correct because Now suppose as the inductive hypothesis that CountMultiples is correct on all inputs of size and we will show that it is correct on all inputs of size n, where n 1. Let a1, an be an arbitrary input of size n

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

Oracle PL/SQL Programming Database Management Systems

Authors: Steven Feuerstein

1st Edition

978-1565921429

More Books

Students also viewed these Databases questions

Question

Discuss the key people management challenges that Dorian faced.

Answered: 1 week ago