Answer to Question #254468 in Discrete Mathematics for Mico

Question #254468
Write an algorithm that outputs the smallest element in the sequence: Sà ¢ ‚ , S2... Sn


Use the procedure name find_small and output small.


Make a recursive algorithm for finding the greatest common divisor of any non-negative integers a and b, where a and b are both not equal to zero. Use the procedure name gcd_recurs.
1
Expert's answer
2022-01-10T05:04:03-0500

For the first question. To outputs the smallest element in the sequence.

Input: The sequence s1, s2,...,sn and the length n of the sequence

Output: small, the smallest element in this sequence

procedure find_small(s, n)
  small := s_1 
  i := 2 
  while i ≤ n do 
    begin 
    if s_i < small then // a smaller value was found 
    small := s_i 
    i := i + 1 
    end 
  return(small) 
end find_small

For the second question. To find GCD.

procedure gcd_recurs(a, b)
  begin
    if b = 0 then
      return x;
    else
      call: gcd_recurs(b, a%b);
    endif
   end

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS