Bubble Sort in Qualcomm Code

    A funny find shared today by fj333 user with Reddit . Understanding the proprietary code of Qualcomm Technologies for Android, which appeared a year ago, he discovered that an unknown programmer decided to use bubble sorting in the production code in order to find ... the maximum in the array.

    You can view the source file via a link to Github or under a cat, and any owner of a device with Qualcomm Snapdragon 200 MSM8610 running Android can evaluate it in work.

    As is known to anyone who is familiar with sorting algorithms, bubble sorting is an educational algorithm, and is usually not used in industrial code because of its inefficiency ; the fact is that in the worst and average cases it has complexity O (n2 ) , in addition, its capacitive complexity in this case is O (n) . Whom this did not convince - even Barack Obama does not recommend using bubble sorting.

    And all this is not taking into account the fact that a simple search would have been enough to find the maximum.

    #ifndef ABS
    #define ABS(x)            (((x) < 0) ? -(x) : (x))
    #endif
    /*==============================================================================
     * Function:           bubblesort
     *
     * Description: Subroutine for sorting 1-D array elements
     *
     * Parameters: double *x    --->   input one-dimensional array
     *             int n        --->   size of input array
     *             int *m       --->   indices of sorted elements
     *============================================================================*/
    void bubblesort(double *x, int n, int *m)
    {
      int i, j, t1;
      double t2;
      for(i = 0; i < n; i++)
        m[i] = i;
      for(i = 0; i < n; i++) {
        for(j = 0; j    input one-dimensional array
     *             int n        --->   size of input array
     *============================================================================*/
    double absmax(double *x, int n)
    {
      int j, *l;
      int index = 0;
      double *y;
      l = (int *)malloc(n * sizeof(int));
      if (NULL == l) {
        CDBG("%s: Error mem alloc for l.\n", __func__);
        return -1;
      }
      y = (double *)malloc(n * sizeof(double));
      if (NULL == y) {
        free(l);
        CDBG("%s: Error mem alloc for y.\n", __func__);
        return -1;
      }
      for(j = 0; j < n; j++)
        y[j] = ABS(x[j]);
      bubblesort(y, n, l);
      index = l[0];
      free(l);
      free(y);
      return ABS(x[index]);
    }

    Has a Code Review been conducted? The story is silent about this ...

    Also popular now: