Notebook - Welcome to Notebook

Contact/Report Bugs
You can contact me at: bkenwright@xbdev.net












Visualization example showing sort function comparison Sort algorithm is dependent on factors such as data type size order meta charset utf 8 style body height 1000px font family monospace font size x small bigContainer text align center big width 100 height 100 canvas border 1px solid black td vertical align top td first child vertical align middle thead text align center style link href https code jquery com ui 1 10 4 themes ui lightness jquery ui css rel stylesheet script src https code jquery com jquery 1 10 2 js script script src https code jquery com ui 1 10 4 jquery ui js script script var SortVisualizer function canvas this ctx canvas getContext 2d SortVisualizer prototype get function id var v this num this num id this num id 0 if id swap v Math floor v 2 return v SortVisualizer prototype runSort function sortFn size type type type random size size 50 this steps var self this var ascendingValues function ii size return ii var descendingValues function ii size return size ii 1 var manyEqualValues function ii size return 1 Math floor ii 10 10 var equalValues function ii size return Math floor size 2 var totallyRandom function ii size return self rand size var slightlyRandom function ii size return Math min size 1 Math max 0 ii 1 self rand 3 var makeRandomArray function size valueFn swapIndexFn var array for var ii 0 ii size ii array push valueFn ii size if swapIndexFn for var ii 0 ii size ii var a swapIndexFn ii size var b swapIndexFn ii size var t array a array a array b array b t for var ii 0 ii size ii self addStep ii array ii start return array var types random valueFn ascendingValues swapFn totallyRandom similar valueFn ascendingValues swapFn slightlyRandom ascending valueFn ascendingValues descending valueFn descendingValues mostEqual valueFn manyEqualValues swapFn totallyRandom equal valueFn equalValues var t types type var array makeRandomArray size t valueFn t swapFn sortFn array this SortVisualizer prototype addStep function index value type this steps push index index value value type type SortVisualizer prototype cancelTask function if this requestId undefined console log request canceled cancelRequestAnimtionFrame this requestId cancelTimeout this requestId this requestId undefined SortVisualizer prototype queueTask function fn var self this var bk function self requestId undefined fn if this requestId undefined throw task already queued this requestId requestAnimationFrame bk this requestId setTimeout bk 1000 SortVisualizer prototype playback function fn var index 0 var self this var steps this steps var ctx this ctx var size 0 var maxValue 0 this num cycles 0 var totalCycles 0 var cycleCount 0 var cyclesPerFrame 10 var columnState var columnsModified var time 0 var timeToRestore 20 var requestId undefined ctx fillStyle black ctx fillRect 0 0 ctx canvas width ctx canvas height steps forEach function step switch step type case start size Math max size step index 1 maxValue Math max maxValue step value columnState step index index step index time 0 value step value state start break default self num step type 0 break var queueNextStep function self queueTask processStep var modifyColumn function step var state columnState step index state value step value if state state start state state cmp state state step type state time time timeToRestore return true return false var drawColumn function step color var width ctx canvas width size var height ctx canvas height step value maxValue var x width step index var y ctx canvas height height ctx fillStyle black ctx fillRect x 0 width ctx canvas height ctx fillStyle color ctx fillRect x y width height var restoreColumns function var checkTime time columnState forEach function state if state state start if state time checkTime state state start drawColumn state white Each function returns the number of cycles it takes TODO Seems like we could simulate cache times since we know which elements have been references at what time var stepFuncs start function step drawColumn step white return 0 cmp function step if modifyColumn step drawColumn step blue return 3 swap function step drawColumn step red modifyColumn step return 6 copy function step drawColumn step purple modifyColumn step return 4 set function step drawColumn step orange modifyColumn step return 2 var drawAllColumns function var index 0 var drawNextColumn function if index columnState length columnState index state start drawColumn columnState index rgb 0 255 0 restoreColumns self queueTask drawNextColumn time drawNextColumn var processStep function var done false while done if index steps length fn false drawAllColumns done true else var step steps index var typeFn stepFuncs step type if typeFn throw unknown step type self num step type self num step type self num step type 1 1 var cycles typeFn step totalCycles cycles cycleCount cycles self num cycles totalCycles if cycleCount cyclesPerFrame cycleCount cyclesPerFrame queueNextStep fn true done true time restoreColumns processStep SortVisualizer prototype destroy function this cancelTask SortVisualizer prototype rand function range return Math floor Math random range SortVisualizer prototype swap function array a b var temp array a array a array b array b temp this addStep a array a swap this addStep b array b swap SortVisualizer prototype copy function array src dst array dst array src this addStep dst array dst copy SortVisualizer prototype set function array ndx value array ndx value this addStep ndx value set SortVisualizer prototype cmp function array ndx value this addStep ndx array ndx cmp return array ndx value SortVisualizer prototype gt function array ndx value return this cmp array ndx value 0 SortVisualizer prototype lt function array ndx value return this cmp array ndx value 0 SortVisualizer prototype ge function array ndx value return this cmp array ndx value 0 SortVisualizer prototype le function array ndx value return this cmp array ndx value 0 SortVisualizer prototype eq function array ndx value return this cmp array ndx value 0 SortVisualizer prototype ne function array ndx value return this cmp array ndx value 0 script script var log function msg var console document getElementById console var div document createElement div div appendChild document createTextNode msg console appendChild div var quickSort function array sv var sort function start end var n end start if n 1 return var r start sv rand n sv swap array start r sv var k start for var i start 1 i end i if sv le array i array start sv swap array k i sv sv swap array start k sv sort start k sort k 1 end sort 0 array length var quickSortLR function array sv var sort function array start end if end start 1 return var pivotIndex start var pivot array pivotIndex var sp start 1 var ep end while ep sp while ep sp sv ge array ep pivot ep if ep sp break sv copy array ep pivotIndex pivotIndex ep while ep sp sv le array sp pivot sp if ep sp break sv copy array sp pivotIndex pivotIndex sp sv set array pivotIndex pivot sort array start pivotIndex 1 sort array pivotIndex 1 end sort array 0 array length 1 var quickSort3 function array sv var sort function a l r if r l return var i l 1 var j r var p l 1 var q r var v a r for while sv lt a i v while sv gt a j v if j l break if i j break sv swap a i j if sv eq a i v this compare is nearly free because the swap above just accessed these values if a i v p sv swap a p i if sv eq a j v if a j v q sv swap a j q sv swap a i r j i 1 i i 1 for var k l k p k j sv swap a k j for var k r 1 k q k i sv swap a i k sort a l j sort a i r sort array 0 array length 1 var mergeSort function array sv var n array length var scratch array slice var merge function l r m var i l var j m 1 if l r return while i m j r if sv lt array i array j sv set scratch i j m 1 array i i else sv set scratch i j m 1 array j j for i m i sv set scratch i j m 1 array i for j r j sv set scratch i j m 1 array j for var k l k r k sv set array k scratch k for var run 1 run n run 2 for var i 0 i n i 2 run merge i Math min i 2 run 1 n 1 Math min i run 1 n 1 var bubbleSort function array sv var n array length for var i 0 i n i var swapped false for var j n 1 j i 1 j if sv lt array j array j 1 sv swap array j j 1 swapped true if swapped break var selectionSort function array sv var n array length for var i 0 i n i var k i for var j i 1 j n j if sv lt array j array k k j sv swap array i k var insertionSort function array sv var n array length for var i 1 i n i var v array i var j 0 for j i j if sv gt array j v break for var k i k j k sv copy array k 1 k sv set array j v var shellSort function array sv var n array length https oeis org A102549 701 301 132 57 23 10 4 1 forEach function gap for var i gap i n i var v array i var j i for j gap j gap if sv le array j gap v break for var k i k j k gap sv copy array k gap k sv set array j v function var createCanvas function width height var canvas document createElement canvas canvas width width canvas height height return canvas var bigSv undefined dialog form dialog autoOpen false height 900 width 900 modal true close function bigSv destroy bigSv undefined var showSort function algo type var big document getElementById big var width Math max 300 body width 200 var height Math max 300 body height 200 big width width 50 big height height 60 if bigSv undefined throw visualization already in progress bigSv new SortVisualizer big bigSv runSort algo sortFn Math max 100 Math min 300 width type bigSv playback function dialog form dialog title algo name type dialog option width width dialog option height height dialog open var types random similar ascending descending mostEqual equal var algorithms name quicksort sortFn quickSort name quicksortLR sortFn quickSortLR name quicksort3 sortFn quickSort3 name merge sortFn mergeSort name bubblesort sortFn bubbleSort name selection sortFn selectionSort name insertion sortFn insertionSort name Shell sortFn shellSort var stats label num set id set label num cpy id copy label num cmp id cmp label num swp id swap label num cyc id cycles var tbody document getElementById t var thead document getElementById h types forEach function type var td document createElement td td appendChild document createTextNode type thead appendChild td algorithms forEach function algo var tr document createElement tr var td document createElement td var div document createElement div div appendChild document createTextNode algo name td appendChild div tr appendChild td types forEach function type var td document createElement td var canvas createCanvas 100 50 td appendChild canvas var addDivSpan function parent msg var div document createElement div div appendChild document createTextNode msg var span document createElement span div appendChild span parent appendChild div return span var statElems stats forEach function stat statElems push stat stat elem addDivSpan td stat label var sv new SortVisualizer canvas sv runSort algo sortFn 50 type sv playback function statElems forEach function s s elem innerText sv get s stat id td click function showSort algo type tr appendChild td tbody appendChild tr console log ready script table thead tr id h td td tr thead tbody id t tbody table pre id console pre div id dialog form title Sort div id bigContainer canvas id big canvas div div

ent createElement div div appendChild document createTextNode msg console appendChild div var quickSort function array sv var sort function start end var n end start if n 1 return var r start sv rand n sv swap array start r sv var k start for var i start 1 i end i if sv le array i array start sv swap array k i sv sv swap array start k sv sort start k sort k 1 end sort 0 array length var quickSortLR function array sv var sort function array start end if end start 1 return var pivotIndex start var pivot array pivotIndex var sp start 1 var ep end while ep sp while ep sp sv ge array ep pivot ep if ep sp break sv copy array ep pivotIndex pivotIndex ep while ep sp sv le array sp pivot sp if ep sp break sv copy array sp pivotIndex pivotIndex sp sv set array pivotIndex pivot sort array start pivotIndex 1 sort array pivotIndex 1 end sort array 0 array length 1 var quickSort3 function array sv var sort function a l r if r l return var i l 1 var j r var p l 1 var q r var v a r for while sv lt a i v while sv gt a j v if j l break if i j break sv swap a i j if sv eq a i v this compare is nearly free because the swap above just accessed these values if a i v p sv swap a p i if sv eq a j v if a j v q sv swap a j q sv swap a i r j i 1 i i 1 for var k l k p k j sv swap a k j for var k r 1 k q k i sv swap a i k sort a l j sort a i r sort array 0 array length 1 var mergeSort function array sv var n array length var scratch array slice var merge function l r m var i l var j m 1 if l r return while i m j r if sv lt array i array j sv set scratch i j m 1 array i i else sv set scratch i j m 1 array j j for i m i sv set scratch i j m 1 array i for j r j sv set scratch i j m 1 array j for var k l k r k sv set array k scratch k for var run 1 run n run 2 for var i 0 i n i 2 run merge i Math min i 2 run 1 n 1 Math min i run 1 n 1 var bubbleSort function array sv var n array length for var i 0 i n i var swapped false for var j n 1 j i 1 j if sv lt array j array j 1 sv swap array j j 1 swapped true if swapped break var selectionSort function array sv var n array length for var i 0 i n i var k i for var j i 1 j n j if sv lt array j array k k j sv swap array i k var insertionSort function array sv var n array length for var i 1 i n i var v array i var j 0 for j i j if sv gt array j v break for var k i k j k sv copy array k 1 k sv set array j v var shellSort function array sv var n array length https oeis org A102549 701 301 132 57 23 10 4 1 forEach function gap for var i gap i n i var v array i var j i for j gap j gap if sv le array j gap v break for var k i k j k gap sv copy array k gap k sv set array j v function var createCanvas function width height var canvas document createElement canvas canvas width width canvas height height return canvas var bigSv undefined dialog form dialog autoOpen false height 900 width 900 modal true close function bigSv destroy bigSv undefined var showSort function algo type var big document getElementById big var width Math max 300 body width 200 var height Math max 300 body height 200 big width width 50 big height height 60 if bigSv undefined throw visualization already in progress bigSv new SortVisualizer big bigSv runSort algo sortFn Math max 100 Math min 300 width type bigSv playback function dialog form dialog title algo name type dialog option width width dialog option height height dialog open var types random similar ascending descending mostEqual equal var algorithms name quicksort sortFn quickSort name quicksortLR sortFn quickSortLR name quicksort3 sortFn quickSort3 name merge sortFn mergeSort name bubblesort sortFn bubbleSort name selection sortFn selectionSort name insertion sortFn insertionSort name Shell sortFn shellSort var stats label num set id set label num cpy id copy label num cmp id cmp label num swp id swap label num cyc id cycles var tbody document getElementById t var thead document getElementById h types forEach function type var td document createElement td td appendChild document createTextNode type thead appendChild td algorithms forEach function algo var tr document createElement tr var td document createElement td var div document createElement div div appendChild document createTextNode algo name td appendChild div tr appendChild td types forEach function type var td document createElement td var canvas createCanvas 100 50 td appendChild canvas var addDivSpan function parent msg var div document createElement div div appendChild document createTextNode msg var span document createElement span div appendChild span parent appendChild div return span var statElems stats forEach function stat statElems push stat stat elem addDivSpan td stat label var sv new SortVisualizer canvas sv runSort algo sortFn 50 type sv playback function statElems forEach function s s elem innerText sv get s stat id td click function showSort algo type tr appendChild td tbody appendChild tr console log ready script table thead tr id h td td tr thead tbody id t tbody table pre id console pre div id dialog form title Sort div id bigContainer canvas id big canvas div div

3dplot
a4print
about
acejs
acejs2
acejs3
aessecurity
angularjs
animbackgroundimage
aseformat
assert
asteroidsjs
backgrounds01
backgrounds02
backgrounds03
barnsleyfern
base26
base64
bib
binary
bodypix
bouncy
box2dweb
breakoutjs
browserversion
buslanes
busybutton
bvhreader
calendar
canvas
canvas2
canvas3
canvasmandelbrot
canvasmandelbrot2
canvasnumbers
canvaszoom
capsule
changingimages
chatgptusingopenai
chatgptusingopenai2
chatgptusingopenai3
checkboxtoggle
chinesetiles
classes
classfeatures
clipboardbutton
clonenode
codedropdown
codemirror
codemirror2
collada
colorpick
columnresizer
contextmenu
convnet
cookiebanner
countdown
countdown2
countdown3
crop
css3dbarchart
css3dbarchart2
css3dbook
css3dscene
csscube
csscube2
csscube3
csscubevideos
cssfilelist
csshas
csspulse
cssresizeaspect
cssspin
csszooming
csvtoarray
customcheckbox
d3datamap
d3js
d3js10
d3js11
d3js2
d3js3
d3js4
d3js5
d3js6
d3js7
d3js8
d3js9
d3jsanimatedgrid
d3jsarctransition
d3jsarctransition2
d3jsaxis
d3jsaxischanging
d3jsbars
d3jsbrushing
d3jsbuslanes
d3jsbuslanes2
d3jscalendar
d3jscheat
d3jsclock
d3jscloudmap
d3jscogs
d3jscolors
d3jscovid
d3jscovid2
d3jscovid3
d3jsdashboard
d3jsdashboard2
d3jsdashboard3
d3jsdatakeyfunction
d3jsdensity
d3jsdragresizing
d3jsdragresizing2
d3jseach
d3jsease
d3jsevents
d3jsflower
d3jsforcegroups
d3jsforces
d3jsforces2
d3jsfractaltree
d3jsgeo
d3jsgroupbars
d3jsgroups
d3jsheatmap
d3jshex
d3jshierarchies
d3jshierarchies2
d3jshistogram
d3jshistogram2
d3jshistogram3
d3jshistogram4
d3jsinterpolate
d3jsjoin
d3jskmean
d3jskmean2
d3jsline
d3jsline2
d3jsline3
d3jsline4
d3jslinetransition
d3jslinetransition0
d3jslinetransition2
d3jsmaplocations
d3jsmaps
d3jsmaps2
d3jsmaps3
d3jsmisc
d3jsmisc2
d3jsmodule
d3jsmodulecolor
d3jsmultistyles
d3jsnobel
d3jsoverlappinggraphs
d3jspanel
d3jspie
d3jspieinterpolate
d3jssankey
d3jssankey2
d3jsscatter
d3jsshapes
d3jsslider
d3jsspending
d3jsspending2
d3jsspiralplot
d3jsspirograph
d3jssquare
d3jsstack
d3jsstackedbar
d3jsstackedbar2
d3jssunburst
d3jssunmoon
d3jssvglines
d3jssymbols
d3jstimelines
d3jsuk
d3jsvoronoi
d3scatterplot
d3timeline
d3timeline2
datalist
datamuse
date
dblclickhighlight
deviceorientation
dictionaryapi
dockermenu
doodlepad
downloadgif
dragdroplistitems
dragrotateresizediv
dragrotateresizediv2
dragrotateresizediv3
dragrotateresizediv4
dragrotateresizefontsize
dragselectbrush
drawlinesdiv
dropdown
dualquaternionimages
dynamicgrid
easefunctions
easeinterpolate3dplots
echart
echart2
echart3
encapsulation
epubviewer
errorstack
excalidraw
excalidraw2
excalidraw3
excalidraw5
expandable
faker
fetchplus
fileupload
fixedtopbar
fonts
fonts2
footerbar
fractalmaze
fractalmaze2
fractalnoiseimage
fractals
fractals2
fractaltree
freesvg
fresnel
froggerjs
gantt
gifgiphyapi
gifhex
gltffromscratch
gradients
griditems
griditems2
griditems3
griditems4
gridworms
heat
hexview
hexview2
highlight
icons
icons2
iframes
ik
imagetracertosvg
imgur
inputfile
invadersjs
ipynb
ipynb2
ipynb3
ipynb4
isbn13
isbn2
jpghex
jquery
jquery2
jqueryui
jqueryui2
jsdraganddrop
jslint
jsobfuscate
jsraytracer
jstree
jstree2
jszip
jszipimages
jszipread
keyframes
l2dwidget
lda
leftmenu
less
less2
lineargradientimage
linenumbers
loadimagefromfile
makepdf
maps
markdown
markdown2
markdownalerts
markdownalerts2
markdownbookmarks
markovimage
markovpixelblocks
mathjax
matrices
matsandvects
mazegamejs
md2tex
metrotiles
metrowindows
milestones
misc
misc2
modules
myipdetails
neataptic
networkstructures
networkstructures2
number
obj
objtojson
openaiimages
opencv
opencv2
opencv3
opencv4
opencv5
outline
p2
p5fractalleaf
p5fractalshape
p5js
p5js2
p5js3
p5jsanimatedcover
p5mengercube
p5snowflakes
palindrome
panel
parallax
paste
paste2
pasteimgfromurl
pdfjs
pdfjs2
pdfkit
pdfkit2
pdfkit3
pdfkit4
pdfkit5
pdfkit6
pdfmake
pdfmake2
pdfmake3
pdfmake4
pdfmake5
pdfmake6
perlin
perlin2
perlin3
perspective
pexels
playground
plotly
plotlynoise
plotlyranddist
plyloader
plyloader2
pngtxtencoder
pongjs
pptxgenjs
prettycode
prism
prn
problems
progress
pseudorandom
px2svg
python
quotes
racergame
random
randomprofilepatterns
randomstring
rating
rayambient
raymonte
raymonteprogressive
raymonteprogressive2
raymontewarmstart
reexpcross
reexpcross2
regex
regexbib
regexpfixbib
regexpmultiline
repeatwordsregexp
resizabletable
resizabletable2
revealjs
revealjs2
revealjsmulti
ritalanguage
ritalanguage2
ritalanguage3
rotateimg
rough
rsapublicprivatekeys
rss
rss2
sankey
scrappingsvg
scrolltext
scrolltext2
scrollwidth
sdfboxinboxtwist
sdfhollowbox
setintervalexception
shareurl
shuffle
sidecomment
similarity
simplehighlighter
simpleplatformgamejs
sinecanvas
sliderpopout
slides
smileys
snowfall
snowman
sound
soundsignal
sphererayintersection
springs
sqljs
steganography
stereogram
stringmatching
svg
svgchaos
svgdragresize
svgdragresize2
svgdragresize3
svgdragrotate
svgdrawing
svglines
svglines2
svglines3
svglines4
svglines5
svglinesmandelbrot
svgpathsdragrotate
svgpathsdragrotateresize
svgpie
svgpie2
svgpie3
svgpiepath
svgpiepath2
svgrandomfaces
symbols
synaptic
synaptic2
synonyms
tablerotatecells
tablerotatecells2
tablerotatecells3
tablerotatecells3b
tablerotatecells4
tables
tablezebra
tabularjs
tabularjs2
tabulatordownload
tagcanvas
tensorflowgan
tensorflowjs
tensorflowjsbasic
tensorflowjscnn
tensorflowjssinewave
tensorflowjssound
tensorflowmobilenet
tetrahedronfractal
tetrahedronfractalfolding
tetris
textarea
textareaauto
textareadiv
textareadiv2
textmaskimage
theirorthere
thesaurus
threejs
threejs2
threejs3
threejs4
threejsgltf
threejstokyo
tiles
toaster
tooltip
transition
transitionexpandabledropdown
treeview
treeview2
tricks
tshirt
tshirt2
tshirt3
turningpages
unsplash
urlblob
urlblob2
userdefinepoints
vector
videos
videos2
visualsort
vue
w2ui
w2uientertextdialog
webcam
webgl
webgl2
webgl3
webgl4
webgl5
webglbasic1
webglbasic2
webglcube
webglfov
webglfrustum
webgljson
webglleaves
webgllighting
webglorthographic
webglpoints1
webglpoints2
webglpoints3
webglsquare
webgltexture1
webgltexture2
webgltexture3
webgltransforms
webgltriangle
webgpu
webgpu10
webgpu11
webgpu12
webgpu13
webgpu14
webgpu15
webgpu16
webgpu17
webgpu2
webgpu3
webgpu4
webgpu5
webgpu6
webgpu7
webgpu8
webgpu9
webgpubars
webgpubuffers
webgpubuffers2
webgpucellnoise
webgpuclouds
webgpuclydescope
webgpucompute
webgpucubemap
webgpucubemap2
webgpudeferred
webgpudepth
webgpudof
webgpudrops
webgpuetha
webgpufire
webgpufractalcubes
webgpuglassrain
webgpugltf
webgpugltf2
webgpugrass
webgpugrid
webgpukernel
webgpukleinian
webgpulabupdates
webgpulighting
webgpumandelbrot
webgpumeta3d
webgpumetaballs
webgpumouse
webgpunoise
webgpunormalmapping
webgpuobj
webgpuparallax
webgpuparallax2
webgpuparallax3
webgpuparallaxshadow
webgpuparallaxshadow2
webgpupixel
webgpuquad
webgpuray1
webgpuraytracing
webgpuraytracing2
webgpushadowmaps
webgpushadowmaps2
webgpusierpinski2d
webgpusierpinski3d
webgpusinusoid
webgpussao
webgpustadiumobj
webgpuswirl
webgputestpipe3
webgputoon
webgputopology
webgputt
webgpuvolcloud
webgpuwater
webgpuwireframe
webgpuwireframe2
webpcanvas
webworkers
webxr
webxr2
wiggly
wikipedia