🇫🇷 Version française

Computer Science (NSI) - Terminal Year (Correction)

Software Ecodesign: Algorithmic Complexity and Energy Footprint

1. Theoretical Complexity Analysis

* **Selection Sort:** Its time complexity in the worst, best, and average case is in O(n2). Two nested loops iterate through the data structure, generating a number of operations proportional to n2.

* **Merge Sort:** Based on the "divide and conquer" paradigm, its time complexity is in O(n log n) in all cases.

2. Python Implementation (Merge Sort)

def fusion(left, right):
    result = []
    i = 0
    j = 0
    while i < len(left) and j < len(right):
        if left[i] < right[j]:
            result.append(left[i])
            i += 1
        else:
            result.append(right[j])
            j += 1
    return result + left[i:] + right[j:]

def tri_fusion(t):
    if len(t) <= 1:
        return t
    mid = len(t) // 2
    left = tri_fusion(t[:mid])
    right = tri_fusion(t[mid:])
    return fusion(left, right)

3. Energy Evaluation and EDD Impact

For n = 10,000 elements:

The efficiency ratio results in hundreds of times fewer processor instructions. Multiplied by one million daily requests, choosing an inappropriate algorithm keeps processor cores running at full capacity unnecessarily, inducing direct and wasteful electrical overconsumption in servers. Software ecodesign thus demonstrates that code optimization is an ecological lever just as relevant as hardware efficiency.