diff --git a/Contributors.md b/Contributors.md index bb585a2..e7e20ab 100644 --- a/Contributors.md +++ b/Contributors.md @@ -1,40 +1,41 @@ # Contributors -* [Meet Ranoliya](https://github.com/memr5/) -* [ANIMESH BARUA](https://github.com/LIGHT1210) -* [Vatsal Parsaniya](https://github.com/Vatsalparsaniya) -* [hosseinSafari](https://github.com/hosseinSafari) -* [Vishal Agarwal](https://github.com/Vishal260700) -* [Pranav B](https://github.com/Blaze2305) -* [Adityakumar Yadav](https://github.com/AdiY2j) -* [Antônio Dias](https://github.com/antoniofdias) -* [Roberto Torella](https://github.com/ganglio) -* [Satyajit Ghana](https://github.com/satyajitghana) -* [tazzzzzzz](https://github.com/tazzzzzzz) -* [Tiago Pedutti](https://github.com/tiagopedutti) -* [nn123kkk](https://github.com/nn123kkk) -* [Anway](https://github.com/anwaysomani) -* [Sneha Raina](https://github.com/SnehaR26) -* [Ricardo Stoklosa](https://github.com/RicardoStoklosa) -* [Proma Roy](https://github.com/promaroy) -* [Austin Zuniga](https://github.com/AustinZuniga) -* [Kelly Costa](https://github.com/kellydosocorro) -* [Sriram Iyer](https://github.com/ramiyer1998) -* [Miguel](https://github.com/marxlaml) -* [Sameer Kashyap](https://github.com/Sameerkash) -* [Prajwal Kumar](https://github.com/prajwal72) -* [Ahmet Oguz](https://github.com/asotronot) -* [Janeth Fernando](https://github.com/janethavi) -* [Dhira](https://github.com/ddhira123) -* [Subhojyoti Khastagir](https://github.com/Subho13) -* [DelyB](https://github.com/DelyB) -* [Sumedh Jouras](https://github.com/Sumedhj16) -* [NerdOfCode](https://github.com/nerdofcode) -* [Jay Dave](https://github.com/simson1) -* [Ahmad Emir Alfatah](https://github.com/Criptdestroyer) -* [Ayush Dubey](https://github.com/ayushdubey003) -* [Raj Pathare](https://github.com/RajPathare) -* [ehmoovin](https://github.com/moovinfrontend) -* [Muskan](https://github.com/Muskan-goyal6) -* [Tarannum](https://github.com/giTan7) -* [HCamberos](https://github.com/HCamberos) +- [Meet Ranoliya](https://github.com/memr5/) +- [ANIMESH BARUA](https://github.com/LIGHT1210) +- [Vatsal Parsaniya](https://github.com/Vatsalparsaniya) +- [hosseinSafari](https://github.com/hosseinSafari) +- [Vishal Agarwal](https://github.com/Vishal260700) +- [Pranav B](https://github.com/Blaze2305) +- [Adityakumar Yadav](https://github.com/AdiY2j) +- [Antônio Dias](https://github.com/antoniofdias) +- [Roberto Torella](https://github.com/ganglio) +- [Satyajit Ghana](https://github.com/satyajitghana) +- [tazzzzzzz](https://github.com/tazzzzzzz) +- [Tiago Pedutti](https://github.com/tiagopedutti) +- [nn123kkk](https://github.com/nn123kkk) +- [Anway](https://github.com/anwaysomani) +- [Sneha Raina](https://github.com/SnehaR26) +- [Ricardo Stoklosa](https://github.com/RicardoStoklosa) +- [Proma Roy](https://github.com/promaroy) +- [Austin Zuniga](https://github.com/AustinZuniga) +- [Kelly Costa](https://github.com/kellydosocorro) +- [Sriram Iyer](https://github.com/ramiyer1998) +- [Miguel](https://github.com/marxlaml) +- [Sameer Kashyap](https://github.com/Sameerkash) +- [Prajwal Kumar](https://github.com/prajwal72) +- [Ahmet Oguz](https://github.com/asotronot) +- [Janeth Fernando](https://github.com/janethavi) +- [Dhira](https://github.com/ddhira123) +- [Subhojyoti Khastagir](https://github.com/Subho13) +- [DelyB](https://github.com/DelyB) +- [Sumedh Jouras](https://github.com/Sumedhj16) +- [NerdOfCode](https://github.com/nerdofcode) +- [Jay Dave](https://github.com/simson1) +- [Ahmad Emir Alfatah](https://github.com/Criptdestroyer) +- [Ayush Dubey](https://github.com/ayushdubey003) +- [Raj Pathare](https://github.com/RajPathare) +- [ehmoovin](https://github.com/moovinfrontend) +- [Muskan](https://github.com/Muskan-goyal6) +- [Tarannum](https://github.com/giTan7) +- [HCamberos](https://github.com/HCamberos) +- [MuhammadMinhaj](https://github.com/MuhammadMinhaj) diff --git a/Search Algorithms/JavaScript/binarySearch.js b/Search Algorithms/JavaScript/binarySearch.js new file mode 100644 index 0000000..204287f --- /dev/null +++ b/Search Algorithms/JavaScript/binarySearch.js @@ -0,0 +1,26 @@ +// Binary Search +const binarySearch = (x, arr) => { + let left = 0; + let right = arr.length - 1; + + while (left <= right) { + const mid = Math.floor((left + right) / 2); + if (arr[mid] === x) { + return `Congratulations! Found at position ${mid}`; + } + if (arr[mid] < x) { + left = mid + 1; + } else { + right = mid - 1; + } + } + return -1; +}; +const arr = [3, 6, 8, 32, 45, 76, 89, 92, 94, 100]; +const x = binarySearch(76, arr); +const y = binarySearch(200, arr); + +console.log(x); +// Output : Congratulations! Found at position 5 +console.log(y); +// Output : -1 diff --git a/Search Algorithms/JavaScript/linearSearch.js b/Search Algorithms/JavaScript/linearSearch.js new file mode 100644 index 0000000..9542d18 --- /dev/null +++ b/Search Algorithms/JavaScript/linearSearch.js @@ -0,0 +1,17 @@ +// Linear Search +const linearSearch = (x, arr) => { + for (let i = 0; i < arr.length; i++) { + if (arr[i] === x) { + return `Congratulations! Found at position ${i}`; + } + } + return -1; +}; +const arr = [2, 4, 67, 78, 6, 23, 56, 97]; +const x = linearSearch(78, arr); +const y = linearSearch(100, arr); + +console.log(x); +// Output : Congratulations! Found at position 3 +console.log(y); +// Output : -1 diff --git a/Sorting Algorithms/JavaScript/bubbleSort.js b/Sorting Algorithms/JavaScript/bubbleSort.js new file mode 100644 index 0000000..c3847f4 --- /dev/null +++ b/Sorting Algorithms/JavaScript/bubbleSort.js @@ -0,0 +1,25 @@ +// To swap the element of the array +const swap = (arr, index) => { + const temp = arr[index]; + arr[index] = arr[index + 1]; + arr[index + 1] = temp; +}; +// Bubble sort +const bubbleSort = (arr) => { + for (let i = 0; i < arr.length; i++) { + for (let j = 0; j < arr.length - i; j++) { + if (arr[j] > arr[j + 1]) { + swap(arr, j); + } + } + } +}; +const unSortedArray = [43, 67, 25, 98, 32, 1, 5, 8, 2, 35]; + +// Before sorting the array +console.log(unSortedArray); +// Output : [43, 67, 25, 98, 32, 1, 5, 8, 2, 35] +selectionSort(unSortedArray); +// After sorting the array +console.log(unSortedArray); +// Output : [1, 2, 5, 8, 25, 32, 35, 43, 67, 98] diff --git a/Sorting Algorithms/JavaScript/insertionSort.js b/Sorting Algorithms/JavaScript/insertionSort.js new file mode 100644 index 0000000..061031d --- /dev/null +++ b/Sorting Algorithms/JavaScript/insertionSort.js @@ -0,0 +1,22 @@ +// Insertion sort +const insertionSort = (arr) => { + let i, j, element; + for (i = 1; i < arr.length; i++) { + element = arr[i]; + j = i - 1; + while (j >= 0 && arr[j] > element) { + arr[j + 1] = arr[j]; + j = j - 1; + } + arr[j + 1] = element; + } +}; + +const unSortedArray = [34, 67, 32, 12, 56, 2, 65, 21, 32]; +// Before sorting the array +console.log(unSortedArray); +// Output : [34,67,32,12,56,2,65,21,32] +insertionSort(unSortedArray); +// After sorting the array +console.log(unSortedArray); +// Output : [2, 12, 21, 32, 32, 34, 56, 65, 67] diff --git a/Sorting Algorithms/JavaScript/selectionSort.js b/Sorting Algorithms/JavaScript/selectionSort.js new file mode 100644 index 0000000..1342208 --- /dev/null +++ b/Sorting Algorithms/JavaScript/selectionSort.js @@ -0,0 +1,28 @@ +// To swap the element of the array +const swap = (arr, minIndex, currentIndex) => { + const temp = arr[minIndex]; + arr[minIndex] = arr[currentIndex]; + arr[currentIndex] = temp; +}; +// Selection sort +const selectionSort = (arr) => { + let minIndex; + for (let i = 0; i < arr.length; i++) { + minIndex = i; + for (let j = i + 1; j < arr.length; j++) { + if (arr[minIndex] > arr[j]) { + minIndex = j; + } + swap(arr, minIndex, i); + } + } +}; + +const unSortedArray = [267, 1, 23, 62, 62, 76, 7, 9]; +// Before sorting the array +console.log(unSortedArray); +// Output : [267, 1, 23, 62, 62, 76, 7, 9] +selectionSort(unSortedArray); +// After sorting the array +console.log(unSortedArray); +// Output : [1, 9, 7, 62, 23, 62, 76, 267]