تم الحل ✓
categoryبرمجة وتطوير البرمجيات
schoolبكالوريوس
event_available2026-07-14
السؤال
Transcribed Image Text:
Consider the following
program specification for
evaluating a polynomial anx
+an-1x-1 +
...
+ a1x + ao at x
= C:
Input: c, a0, a1, ..., an R
Output: anch + an-1ch-1 +
+ a1c + ao
+...
Consider the following two
implementations of this
program specification:
Implementation 1:
Polynomial_1
Polynomial_1(c, ao, a1, ...
, an)
(1) 1
(2) yao
(3) while in
y+y+a;
(4)
Power(c, i)
(5)
i+i+1
(6) return y
where Power is
implemented as follows:
Power(a, b)
(1) i 0
(2) y 1
y-1
(3) while i < b
(4)
y y* a
(5)
i+i+1
(6) return y
(6) return y
Implementation 2 :
Polynomial_2
Polynomial_2(c, ao, a₁, ...
, an)
(1) 1
(2) yan
(3) while i ≤ n
(4)
y + y * c + an-i
(5)
ii+1
(6) return y
Consider evaluating the
polynomial 2x + x3 + 2x² +
x + 3 at x = 2.
Trace the execution of
Polynomial_1 on this input
by giving the value of y each
time line (3) of Polynomial_1
is executed:
The 1st time line (3) is
executed, y =
The 2nd time line (3) is
executed, y =
The 3rd time line (3) is
executed, y =
The 4th time line (3) is
executed, y =
The 5th time line (3) is
executed, y =
Trace the execution of
Polynomial_2 on this input
by giving the value of y each
time line (3) of Polynomial_2
is executed:
Trace the execution of
Polynomial_2 on this input
by giving the value of y each
time line (3) of Polynomial_2
is executed:
The 1st time line (3) is
executed, y =
The 2nd time line (3) is
executed, y =
The 3rd time line (3) is
executed, y =
The 4th time line (3) is
executed, y =
The 5th time line (3) is
executed, y =
check_circle الجواب — حل مفصل خطوة بخطوة
hourglass_top
🔒
الحل الكامل متاح للمشتركين
اشترك في أرشيف الأسئلة لعرض هذا الحل وآلاف الحلول المفصلة خطوة بخطوة من معلمين معتمدين.