CS计算机代考程序代写 algorithm In [1]:

In [1]:
import sympy

Computing the efficiency of the search using upward search algorithm
$\lambda$
In [3]:
lm=sympy.Symbol(“𝜆”)
x=sympy.Symbol(“x”)
pmf= sympy.exp(-lm)*lm**x/sympy.factorial(x)
Es= sympy.Sum((x+1)*pmf,(x,0, sympy.oo)).doit()
#Es
# We want to get the expected number of searches for the algorithms
# first x: with respect to x; 0, sympy.oo: from 0 to positive infinitity
Es.subs({lm:49})
Out[3]:
$\displaystyle 𝜆 + 1$

Computing the efficiency of the search using upward/downward search algorithm.
0,1,2, 3,…, $\lfloor \lambda \rfloor$: number of searches $\lfloor \lambda \rfloor+2-x$
$\lfloor \lambda \rfloor+1$,$\lfloor \lambda \rfloor+2$,… : number of searches $x-\lfloor \lambda \rfloor+1$
In [3]:
#downward search
Part1=sympy.Sum( (sympy.floor(lm)+2-x)*pmf ,(x, 0, sympy.floor(lm))).doit()
#upward search
Part2=sympy.Sum( (x-sympy.floor(lm)+1)*pmf ,(x, sympy.floor(lm)+1, sympy.oo)).doit()

Es=Part1+Part2
Result1=Es.simplify().subs({lm:49})
#numerical evaluation
sympy.N(Result1)
Out[3]:
$\displaystyle 7.11359711041175$
In [0]: