partition(low, high) {
    let pivot_idx = high;
    this.steps.push({action: "pivot", idx: pivot_idx});
    let pivot = this.arr[pivot_idx];
    let i = low;
    this.steps.push({action: "activate", idx: i});
    for (let j = low; j < high; j++) {
      if (j > low) {
        this.steps.push({action: "iterate", idx: j, offset: j - low});
      }
      if (this.arr[j] < pivot) {
        if (i !== j) {
          [this.arr[i], this.arr[j]] = [this.arr[j], this.arr[i]];
          this.steps.push({action: "swap", from: j, to: i});
        }
        i++;
        this.steps.push({action: "increment", idx: i});
      }
    }
    this.steps.push({action: "dim", idx: high - 1});
    [this.arr[i], this.arr[pivot_idx]] = [this.arr[pivot_idx], this.arr[i]];
    this.steps.push({action: "swapPivot", from: pivot_idx, to: i});
    // this.steps.push({action: "sort", idx: i});
    return i;
  }
/* naive implementation - choose the last element as pivot element */
naive implementation - choose the last element as pivot element
naive implementation - choose the last element as pivot element
partition(low, high) {
    let pivot_idx = high;
    this.steps.push({action: "pivot", idx: pivot_idx});
    let pivot = this.arr[pivot_idx];
    let i = low;
    this.steps.push({action: "activate", idx: i});
    for (let j = low; j < high; j++) {
      if (j > low) {
        this.steps.push({action: "iterate", idx: j, offset: j - low});
      }
      if (this.arr[j] < pivot) {
        if (i !== j) {
          [this.arr[i], this.arr[j]] = [this.arr[j], this.arr[i]];
          this.steps.push({action: "swap", from: j, to: i});
        }
        i++;
        this.steps.push({action: "increment", idx: i});
      }
    }
    this.steps.push({action: "dim", idx: high - 1});
    [this.arr[i], this.arr[pivot_idx]] = [this.arr[pivot_idx], this.arr[i]];
    this.steps.push({action: "swapPivot", from: pivot_idx, to: i});
    return i;
  }
partition ( low , high ) { let pivot_idx = high ; this . steps . push ( { action : "pivot" , idx : pivot_idx } ) ; let pivot = this . arr [ pivot_idx ] ; let i = low ; this . steps . push ( { action : "activate" , idx : i } ) ; for ( let j = low ; j < high ; j ++ ) { if ( j > low ) { this . steps . push ( { action : "iterate" , idx : j , offset : j - low } ) ; } if ( this . arr [ j ] < pivot ) { if ( i !== j ) { [ this . arr [ i ] , this . arr [ j ] ] = [ this . arr [ j ] , this . arr [ i ] ] ; this . steps . push ( { action : "swap" , from : j , to : i } ) ; } i ++ ; this . steps . push ( { action : "increment" , idx : i } ) ; } } this . steps . push ( { action : "dim" , idx : high - 1 } ) ; [ this . arr [ i ] , this . arr [ pivot_idx ] ] = [ this . arr [ pivot_idx ] , this . arr [ i ] ] ; this . steps . push ( { action : "swapPivot" , from : pivot_idx , to : i } ) ; return i ; }
naive implementation - choose the last element as pivot element
naive implementation - choose the last element as pivot element
// this.steps.push({action: "sort", idx: i});