TradingView
GeckoPrimed
2020년 9월 12일 오후 1시 34분

Pinescript Bubble Sort using Arrays 

Bitcoin / United States DollarCoinbase

설명

The new feature of arrays allows for a multitude of new possibilities within Pinescript. This script implements a bubble sort function with most probable efficiency of О(n^2) with a best-case being O(n). This sort does not require large amounts of memory to process and has advantages when sorting small lists of data.

The main advantages: Bubble sort is an in-place sorting algorithm. It does not require extra memory or even stack space like in the case of merge sort or quicksort.

The main disadvantages: In the worst case the time complexity is equal to O(n^2) which is not efficient in comparison to other sorts which can have a time complexity of O(n*logn).

The Pseudocode for a bubble sort is as follows:
begin BubbleSort(list) for all elements of list if list > list[i+1] swap(list, list[i+1]) end if end for return list end BubbleSort


The results of the sort are plotted against the unsorted list and overlayed on the chart.

A big thanks to Alex Grover for the help.
코멘트
alexgrover
Really nice to see users starting using arrays and coming up with this stuff. It's rare for me to like other people scripts but this one was an insta like :3 Keep it up pal !!!
rthomson
Love it! May I kindly ask permission to use in a script I wish to publsh publically?
Acneto
Thanks for the script
StarrLucky
Built-in random() function was implemented. Change random() to random_f() or use new built-in to make this script work again.
더보기