Hello everyone, I am quick-frozen fish 🐟, a water front 💦, like the garish 💐, continuous sand sculpture 🌲 Welcome friends to add my wechat: Sudongyuer pull you into the group of my public number: front-end quick-frozen fish progress together, looking forward to growing together with everyone

Preface 🌧 ️

Algorithms are unfamiliar and familiar to the front-end people, and often we don’t value them as much as the back-end engineers do. But in fact, algorithms have an unshakable position for every programmer.

Because the development process is to convert the actual problem into the computer can recognize the instructions, that is, “data structure” said, “design the data structure, in the application of algorithms on the line”.

Of course, learning is also focused, as the front end we do not need to fully grasp the algorithm like back-end development, some of the more partial, not practical type and solution method, as long as a little understanding.

Quick sorting ideas 🦀

  • Partitioning: Randomly select a base from the array, with all elements smaller than the base placed in front of the base and elements larger than the base placed behind it.
  • Recursively: Partition the subarray before and after the base recursively.

Quicksort animation 🌵

Source 🔥

Array.prototype.quickSort = function () {
 const rec=(arr) = >{
   if(arr.length <= 1) {returnarr; }const left=[];
      const right=[];
      const mid=arr[0];
    for(let i=1; i<arr.length; i+=1) {if(arr[i]<mid){
        left.push(arr[i])
      }else{
        right.push(arr[i])
      }
    }
    return [...rec(left),mid,...rec(right)]
};

 const res=rec(this);

 res.forEach((item,index) = > {
   this[index]=item
 });
};

const array = [2.4.3.2.1];

array.quickSort();
console.log(array);
Copy the code

Fractional time complexity :O(n)

Recursive time complexity O(logN)

Time complexity :O(n*logN)

Conclusion 🌞

So fish fish LeetCode algorithm “LeetCode” JavaScript- quick sort ⚡️ is over, algorithm this thing has no shortcut, can only write more practice, more summary, the purpose of the article is actually very simple, is to urge myself to complete the algorithm practice and summary and output, food is not important, but love 🔥, I hope everyone can like my essay, and I also hope to know more like-minded friends through the article. If you also like to toss, welcome to add my friend, sand sculpture together, together progress.

Making 🤖 : sudongyu

Personal blog 👨💻: Frozen fish blog

Vx 👦 : sudongyuer

Write in the last

Guys, if you like my words, give 🐟🐟 a thumbs up 👍 or follow ➕ to support me the most.