4949 - [ Merge Sort In Place Algorithm] ( #merge-sort-in-place-algorithm )
5050 - [ Find Median Values (With Merge Sort Algorithm)] ( #find-median-values-with-merge-sort-algorithm )
5151 - [ Quick Sort] ( #quick-sort )
52+ - [ Why Quick sort is used in Array and Merge Sort in Linked List?] ( #why-quick-sort-is-used-in-array-and-merge-sort-in-linked-list )
5253- [ Mathematics & Stats You should know] ( #mathematics--stats-you-should-know )
5354 - [ How to initialize array of size n?] ( #how-to-initialize-array-of-size-n )
5455 - [ How many zeros in 1 Billion] ( #how-many-zeros-in-1-billion )
7374 - [ Binary Search on sorted Array Algorithm] ( #binary-search-on-sorted-array-algorithm )
7475 - [ Reverse Linked List Algorithm] ( #reverse-linked-list-algorithm )
7576 - [ Merge Sort Algorithm] ( #merge-sort-algorithm )
77+ - [ Quick Sort Algorithm] ( #quick-sort-algorithm )
7678 - [ Breadth-First Binary Tree Traversal] ( #breadth-first-binary-tree-traversal )
7779 - [ Depth-First Binary Tree Traversal] ( #depth-first-binary-tree-traversal )
7880 - [ Insert in MIN-HEAP] ( #insert-in-min-heap )
106108 - [ Reverse linked list] ( #reverse-linked-list )
107109 - [ Find the merge point of 2 Linked List] ( #find-the-merge-point-of-2-linked-list )
108110- [ Binary Search for competitive programming from zero to advanced] ( #binary-search-for-competitive-programming-from-zero-to-advanced )
111+ - [ Binary Search Concept] ( #binary-search-concept )
112+ - [ Binary Search Basic Problems] ( #binary-search-basic-problems )
113+ - [ Binary Search Advanced Questions] ( #binary-search-advanced-questions )
109114- [ References] ( #references )
110115
111116> Coding interview question answers in JavaScript for Facebook, Amazon, Google, Microsoft or any company.
@@ -580,7 +585,7 @@ Merge Sort Implementation Visualization:
580585
581586<p class =" codepen " data-height =" 300 " data-theme-id =" dark " data-default-tab =" js,result " data-slug-hash =" yLMQvbv " data-user =" roopkt " style =" height : 300px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" >
582587 <span >See the Pen <a href =" https://codepen.io/roopkt/pen/yLMQvbv " >
583- Merge Sort In-place Answer</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@roopkt </a >)
588+ Merge Sort In-place Answer</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@rupeshtiwari </a >)
584589 on <a href =" https://codepen.io " >CodePen</a >.</span >
585590</p >
586591
@@ -635,6 +640,10 @@ When Browser's are not using Merge sort they most of the time use Quick sort var
635640- [ quick sort in-place] ( src/algorithms/sorting/quick-sort/quick-sort-inplace.mjs )
636641- [ quick sort ] ( src/algorithms/sorting/quick-sort/quick-sort.mjs )
637642
643+ ### Why Quick sort is used in Array and Merge Sort in Linked List?
644+
645+ In Quick sort we do not create auxiliary arrays. Therefore, it is good choice for Array to use quick sort. However in merge sort we create 2 auxiliary arrays. Therefore, linked list is a good choice.
646+
638647## Mathematics & Stats You should know
639648
640649### How to initialize array of size n?
@@ -643,7 +652,7 @@ Example create an array containing numbers from 0 to 9.
643652` [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] `
644653
645654``` js
646- var y = new Array.from (Array (10 ).keys ())
655+ var y = new Array.from (Array (10 ).keys ());
647656```
648657
649658![ ] ( https://i.imgur.com/mVBT7jl.png )
@@ -829,7 +838,7 @@ All Mandatory algorithm source code [download here](https://codepen.io/collectio
829838
830839<p class =" codepen " data-height =" 300 " data-theme-id =" dark " data-default-tab =" js,result " data-slug-hash =" XWRrPBE " data-user =" roopkt " style =" height : 300px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" >
831840 <span >See the Pen <a href =" https://codepen.io/roopkt/pen/XWRrPBE " >
832- Binary Search on Sorted Array Algorithm</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@roopkt </a >)
841+ Binary Search on Sorted Array Algorithm</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@rupeshtiwari </a >)
833842 on <a href =" https://codepen.io " >CodePen</a >.</span >
834843</p >
835844
@@ -839,7 +848,7 @@ All Mandatory algorithm source code [download here](https://codepen.io/collectio
839848
840849<p class =" codepen " data-height =" 300 " data-theme-id =" dark " data-default-tab =" js " data-slug-hash =" WNjegBp " data-user =" roopkt " style =" height : 300px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" >
841850 <span >See the Pen <a href =" https://codepen.io/roopkt/pen/WNjegBp " >
842- Merge Sort Algorithm</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@roopkt </a >)
851+ Merge Sort Algorithm</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@rupeshtiwari </a >)
843852 on <a href =" https://codepen.io " >CodePen</a >.</span >
844853</p >
845854
@@ -849,7 +858,17 @@ All Mandatory algorithm source code [download here](https://codepen.io/collectio
849858
850859<p class =" codepen " data-height =" 300 " data-theme-id =" dark " data-default-tab =" js " data-slug-hash =" WNjegBp " data-user =" roopkt " style =" height : 300px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" >
851860 <span >See the Pen <a href =" https://codepen.io/roopkt/pen/WNjegBp " >
852- Merge Sort Algorithm</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@roopkt </a >)
861+ Merge Sort Algorithm</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@rupeshtiwari </a >)
862+ on <a href =" https://codepen.io " >CodePen</a >.</span >
863+ </p >
864+
865+ ### Quick Sort Algorithm
866+
867+ ![ ] ( https://i.imgur.com/LAouqTY.png )
868+
869+ <p class =" codepen " data-height =" 300 " data-theme-id =" dark " data-default-tab =" js,result " data-slug-hash =" OJpBYKz " data-user =" rupeshtiwari " style =" height : 300px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" >
870+ <span >See the Pen <a href =" https://codepen.io/rupeshtiwari/pen/OJpBYKz " >
871+ Quick Sort In-place Implementation: Answer</a > by Rupesh Tiwari (<a href =" https://codepen.io/rupeshtiwari " >@rupeshtiwari </a >)
853872 on <a href =" https://codepen.io " >CodePen</a >.</span >
854873</p >
855874
@@ -859,15 +878,15 @@ All Mandatory algorithm source code [download here](https://codepen.io/collectio
859878
860879<p class =" codepen " data-height =" 300 " data-theme-id =" dark " data-default-tab =" js,result " data-slug-hash =" XWRroaz " data-user =" roopkt " style =" height : 300px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" >
861880 <span >See the Pen <a href =" https://codepen.io/roopkt/pen/XWRroaz " >
862- Binary Tree Traversal</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@roopkt </a >)
881+ Binary Tree Traversal</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@rupeshtiwari </a >)
863882 on <a href =" https://codepen.io " >CodePen</a >.</span >
864883</p >
865884
866885### Depth-First Binary Tree Traversal
867886
868887 <p class =" codepen " data-height =" 300 " data-theme-id =" dark " data-default-tab =" js,result " data-slug-hash =" ExmYGze " data-user =" roopkt " style =" height : 300px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" >
869888 <span >See the Pen <a href =" https://codepen.io/roopkt/pen/ExmYGze " >
870- </a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@roopkt </a >)
889+ </a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@rupeshtiwari </a >)
871890 on <a href =" https://codepen.io " >CodePen</a >.</span >
872891</p >
873892
@@ -879,7 +898,7 @@ All Mandatory algorithm source code [download here](https://codepen.io/collectio
879898
880899<p class =" codepen " data-height =" 300 " data-theme-id =" dark " data-default-tab =" js,result " data-slug-hash =" PomwXJX " data-user =" roopkt " style =" height : 300px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" >
881900 <span >See the Pen <a href =" https://codepen.io/roopkt/pen/PomwXJX " >
882- Practice</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@roopkt </a >)
901+ Practice</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@rupeshtiwari </a >)
883902 on <a href =" https://codepen.io " >CodePen</a >.</span >
884903</p >
885904
@@ -889,7 +908,7 @@ All Mandatory algorithm source code [download here](https://codepen.io/collectio
889908
890909<p class =" codepen " data-height =" 300 " data-theme-id =" dark " data-default-tab =" js,result " data-slug-hash =" PomwXJX " data-user =" roopkt " style =" height : 300px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" >
891910 <span >See the Pen <a href =" https://codepen.io/roopkt/pen/PomwXJX " >
892- Practice</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@roopkt </a >)
911+ Practice</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@rupeshtiwari </a >)
893912 on <a href =" https://codepen.io " >CodePen</a >.</span >
894913</p >
895914
@@ -901,8 +920,8 @@ All Mandatory algorithm source code [download here](https://codepen.io/collectio
901920
902921** O(Log(n)) time | Space O(1)**
903922
904- For 1 insert operation, avg case is O(lgn ) and worst case is O(n)
905- For n insert operations, avg case is O(nlgn ) and worst case is O(n^2)
923+ For 1 insert operation, avg case is O(log(n) ) and worst case is O(n)
924+ For n insert operations, avg case is O(n log(n) ) and worst case is O(n^2)
906925
907926![ ] ( https://i.imgur.com/8fWHF2B.png )
908927
@@ -926,7 +945,7 @@ For n insert operations, avg case is O(nlgn) and worst case is O(n^2)
926945
927946<p class =" codepen " data-height =" 300 " data-theme-id =" dark " data-default-tab =" js,result " data-slug-hash =" rNmBqWQ " data-user =" roopkt " style =" height : 300px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" >
928947 <span >See the Pen <a href =" https://codepen.io/roopkt/pen/rNmBqWQ " >
929- Binary Search Tree Implementation</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@roopkt </a >)
948+ Binary Search Tree Implementation</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@rupeshtiwari </a >)
930949 on <a href =" https://codepen.io " >CodePen</a >.</span >
931950</p >
932951
@@ -945,15 +964,15 @@ Download solutions to [Facebook Recruiting Portal Coding](https://www.facebookre
945964
946965<p class =" codepen " data-height =" 265 " data-theme-id =" dark " data-default-tab =" js,result " data-user =" roopkt " data-slug-hash =" MWpxezz " style =" height : 265px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" data-pen-title =" Graph: DFS Question (easy) " >
947966 <span >See the Pen <a href =" https://codepen.io/roopkt/pen/MWpxezz " >
948- Graph: DFS Question (easy)</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@roopkt </a >)
967+ Graph: DFS Question (easy)</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@rupeshtiwari </a >)
949968 on <a href =" https://codepen.io " >CodePen</a >.</span >
950969</p >
951970
952971#### Depth First Search Answer
953972
954973<p class =" codepen " data-height =" 560 " data-theme-id =" dark " data-default-tab =" js,result " data-user =" roopkt " data-slug-hash =" NWpJrjg " style =" height : 560px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" data-pen-title =" Graph: DFS Answer (easy) " >
955974 <span >See the Pen <a href =" https://codepen.io/roopkt/pen/NWpJrjg " >
956- Graph: DFS Answer (easy)</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@roopkt </a >)
975+ Graph: DFS Answer (easy)</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@rupeshtiwari </a >)
957976 on <a href =" https://codepen.io " >CodePen</a >.</span >
958977</p >
959978
@@ -1030,15 +1049,15 @@ Delete 15 from BST
10301049
10311050 <p class =" codepen " data-height =" 265 " data-theme-id =" dark " data-default-tab =" js,result " data-user =" roopkt " data-slug-hash =" wvJRxJp " style =" height : 265px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" data-pen-title =" Delete node in BST Question " >
10321051 <span>See the Pen <a href="https://codepen.io/roopkt/pen/wvJRxJp">
1033- Delete node in BST Question</a> by Rupesh Tiwari (<a href="https://codepen.io/roopkt">@roopkt </a>)
1052+ Delete node in BST Question</a> by Rupesh Tiwari (<a href="https://codepen.io/roopkt">@rupeshtiwari </a>)
10341053 on <a href="https://codepen.io">CodePen</a>.</span>
10351054 </p >
10361055
10371056[ Answer] ( https://codepen.io/roopkt/pen/bGqOxyN )
10381057
10391058<p class =" codepen " data-height =" 265 " data-theme-id =" dark " data-default-tab =" js,result " data-user =" roopkt " data-slug-hash =" rNyovyL " style =" height : 265px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" data-pen-title =" Delete node in BST Answer " >
10401059 <span >See the Pen <a href =" https://codepen.io/roopkt/pen/rNyovyL " >
1041- Delete node in BST Answer</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@roopkt </a >)
1060+ Delete node in BST Answer</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@rupeshtiwari </a >)
10421061 on <a href =" https://codepen.io " >CodePen</a >.</span >
10431062</p >
10441063<script async src =" https://cpwebassets.codepen.io/assets/embed/ei.js " ></script >
@@ -1067,15 +1086,15 @@ Example: Find in-order successor of `6`?
10671086
10681087<p class =" codepen " data-height =" 265 " data-theme-id =" dark " data-default-tab =" js,result " data-user =" roopkt " data-slug-hash =" YzZdMxa " style =" height : 265px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" data-pen-title =" Find In-order Successor in BST Question " >
10691088 <span >See the Pen <a href =" https://codepen.io/roopkt/pen/YzZdMxa " >
1070- Find In-order Successor in BST Question</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@roopkt </a >)
1089+ Find In-order Successor in BST Question</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@rupeshtiwari </a >)
10711090 on <a href =" https://codepen.io " >CodePen</a >.</span >
10721091</p >
10731092
10741093[ Answer] ( https://codepen.io/roopkt/pen/bGqOxyN )
10751094
10761095<p class =" codepen " data-height =" 327 " data-theme-id =" dark " data-default-tab =" js,result " data-user =" roopkt " data-slug-hash =" bGqOxyN " style =" height : 327px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" data-pen-title =" Find In-order Successor in BST Answer " >
10771096 <span >See the Pen <a href =" https://codepen.io/roopkt/pen/bGqOxyN " >
1078- Find In-order Successor in BST Answer</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@roopkt </a >)
1097+ Find In-order Successor in BST Answer</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@rupeshtiwari </a >)
10791098 on <a href =" https://codepen.io " >CodePen</a >.</span >
10801099</p >
10811100
@@ -1160,7 +1179,7 @@ Try `Binary Search`.
11601179
11611180<p class =" codepen " data-height =" 300 " data-theme-id =" dark " data-default-tab =" js,result " data-slug-hash =" dyvwPej " data-user =" roopkt " style =" height : 300px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" >
11621181 <span >See the Pen <a href =" https://codepen.io/roopkt/pen/dyvwPej " >
1163- Reverse Linked List: Answer</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@roopkt </a >)
1182+ Reverse Linked List: Answer</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@rupeshtiwari </a >)
11641183 on <a href =" https://codepen.io " >CodePen</a >.</span >
11651184</p >
11661185
@@ -1175,27 +1194,43 @@ Try `Binary Search`.
11751194
11761195<p class =" codepen " data-height =" 265 " data-theme-id =" dark " data-default-tab =" js,result " data-user =" roopkt " data-slug-hash =" poeqBBb " style =" height : 265px ; box-sizing : border-box ; display : flex ; align-items : center ; justify-content : center ; border : 2px solid ; margin : 1em 0 ; padding : 1em ;" data-pen-title =" Find merge point of 2 linked list Answer " >
11771196 <span >See the Pen <a href =" https://codepen.io/roopkt/pen/poeqBBb " >
1178- Find merge point of 2 linked list Answer</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@roopkt </a >)
1197+ Find merge point of 2 linked list Answer</a > by Rupesh Tiwari (<a href =" https://codepen.io/roopkt " >@rupeshtiwari </a >)
11791198 on <a href =" https://codepen.io " >CodePen</a >.</span >
11801199</p >
11811200
11821201## Binary Search for competitive programming from zero to advanced
11831202
1203+ Binary Search is used to solve 2 kinds of problems:
1204+ 1- Search problems, find real numbers.
1205+ 2- Optimization problems. Maximize element x keeping y minimum. Or minimize element x keeping y maximum.
1206+
1207+ ### Binary Search Concept
1208+
11841209- Watch [ Code School Binary Search Videos] ( https://www.youtube.com/watch?v=j5uXyPJ0Pew&list=PL2_aWCzGMAwL3ldWlrii6YeLszojgH77j )
1185- - Watch this [ Binary Search video and do problems] ( https://www.youtube.com/watch?v=GU7DpgHINWQ&list=PLl0KD3g-oDOHpWRyyGBUJ9jmul0lUOD80 )
1186- - Do all basic problems related to binary search [ that I have given in this link] ( https://codepen.io/collection/vBORpO ) .
1210+ - Watch this [ Binary Search conceptual video from Errichto and do problems] ( https://www.youtube.com/watch?v=GU7DpgHINWQ&list=PLl0KD3g-oDOHpWRyyGBUJ9jmul0lUOD80 )
11871211
1212+ ### Binary Search Basic Problems
11881213
1214+ - Do all basics problems related to binary search [ that I have given in this link] ( https://codepen.io/collection/vBORpO )
1215+ - Next do all below advanced problems
11891216
1217+ ### Binary Search Advanced Questions
11901218
1219+ Below problems are lying under optimization problems. Just watch Book Allocation and Aggressive Cows videos to understand optimization logic. Once you understood them after that for rest problems you need to apply same logic.
1220+
1221+ - [ Book Allocation] ( https://www.youtube.com/watch?v=Ss9ta1zmiZo&t=1335s )
1222+ - [ Aggressive Cows] ( https://www.youtube.com/watch?v=TC6snf6KPdE )
1223+ - ROTI (SPOJ)
1224+ - Painter's Partition
1225+ - EKO (SPOJ)
1226+ - PARATA (SPOJ)
11911227
11921228## References
11931229
11941230- http://btholt.github.io/four-semesters-of-cs/
11951231- https://btholt.github.io/four-semesters-of-cs-part-two/
11961232- [ Binary Tree Visualization] ( https://www.cs.usfca.edu/~galles/visualization/BST.html )
1197- - [[ Part 3] Binary Search, Competitive Programming Series | from Zero to Advanced] ( https://www.youtube.com/watch?v=cLkcNeiploY&list=PL4PCksYQGLJOcaPLgeMFaxaHigPFjBuTG&index=4 )
1198-
1233+ - [[ Part 3] Binary Search, Competitive Programming Series | from Zero to Advanced] ( https://www.youtube.com/watch?v=cLkcNeiploY&list=PL4PCksYQGLJOcaPLgeMFaxaHigPFjBuTG&index=4 )
11991234
12001235<script async src =" https://cpwebassets.codepen.io/assets/embed/ei.js " ></script >
12011236<script data-ad-client =" ca-pub-1700383344966810 " async =" " src =" https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js " data-checked-head =" true " ></script >
0 commit comments