Looking for [25-26] Algorithmique avancée 2 [S3] [SPE] test answers and solutions? Browse our comprehensive collection of verified answers for [25-26] Algorithmique avancée 2 [S3] [SPE] at moodle.esme.fr.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
Consider the infix traversal of a binary tree:
def infix_traversal(node):
if node:
infix_traverse(node.left)
print(node.val)
infix_traverse(node.right)
What is the time complexity?
Consider the dichotomous (binary) search algorithm in a sorted array:
def binary_search_recursive(arr, x, low=0, high=None):
if high is None:
high = len(arr) -
1
if low > high:
return -1 mid = (low + high) //
2
if arr[mid] == x:
return mid
elif arr[mid] < x:
return binary_search_recursive(arr, x, mid + 1, high)
else:
return binary_search_recursive(arr, x, low, mid - 1)
What is its time complexity in the worst case?
Consider the following function:
def fib_naif(n):
if n <= 1:
return n
return fib_naif(n - 1) + fib_naif(n - 2)
What is the time complexity of this function?
Consider the following recursive function:
def uk(n, acc=1):
if n == 0:
return acc
else:
return uk (n-1, 4*acc)
What is the time complexity of this function?
Consider the following algorithm for calculating x^n:
def fast_power(x, n):
if n == 0:
return 1
elif n % 2 == 0:
p = fast_power(x, n/
2)
return p * p
else:
p = fast_power(x, (n
-1)/2)
return x * p * p
What is the time complexity of this function?
Considérons l’algorithme suivant :
def algorithm_A(m, n): i =
1 j =
1
while (i <= m) and (j <= n):
i = i +
1 j = j +
1Quelle est la complexité temporelle de cet algorithme, sachant que n et m sont strictement positif ?
Consider the following algorithm (insertion sort):
def sort(array): n = len(array)
for i in range(1, n):
key = array[i]
j = i -
1
while j >= 0 and array[j] > key:
array[j +
1] = array [j]
j = j -
1 array[j +
1] = key
print(array)
return array
What is the time complexity
in the worst case?Considérons l’algorithme suivant :
def algorithm_B(m, n): i =
1 j =
1
while (i <= m) or (j <= n):
i = i +
1 j = j +
1Quelle est la complexité temporelle de cet algorithme, sachant que n et m sont strictement positif ?
Considérons l’algorithme suivant :
def algorithm_C(m, n): i =
1 j =
1
while (j <= n):
if i <= m:
i = i +
1
else:
j = j +
1Quelle est la complexité temporelle de cet algorithme, sachant que n et m sont strictement positif ?