mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2025-05-18 12:02:53 +02:00
chore: better Prettier config for easier reviews
This commit is contained in:
@ -2,6 +2,6 @@
|
||||
|
||||
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
|
||||
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
|
||||
| [Bubble sort](https://wikipedia.org/wiki/Bubble_sort) | O(n) | O(n²) | O(n²) |
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------- | --------- | ------------ | ---------- |
|
||||
| [Bubble sort](https://wikipedia.org/wiki/Bubble_sort) | O(n) | O(n²) | O(n²) |
|
||||
|
@ -2,6 +2,6 @@
|
||||
|
||||
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
|
||||
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
|
||||
| [Insertion sort](https://wikipedia.org/wiki/Insertion_sort) | O(n) | O(n²) | O(n²) |
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------------- | --------- | ------------ | ---------- |
|
||||
| [Insertion sort](https://wikipedia.org/wiki/Insertion_sort) | O(n) | O(n²) | O(n²) |
|
||||
|
@ -2,6 +2,6 @@
|
||||
|
||||
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
|
||||
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
|
||||
| [Merge sort](https://wikipedia.org/wiki/Merge_sort) | O(n log(n)) | O(n log(n)) | O(n log(n)) |
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| --------------------------------------------------- | ----------- | ------------ | ----------- |
|
||||
| [Merge sort](https://wikipedia.org/wiki/Merge_sort) | O(n log(n)) | O(n log(n)) | O(n log(n)) |
|
||||
|
@ -2,6 +2,6 @@
|
||||
|
||||
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
|
||||
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
|
||||
| [Bubble sort](https://wikipedia.org/wiki/Bubble_sort) | O(n) | O(n²) | O(n²) |
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------- | --------- | ------------ | ---------- |
|
||||
| [Bubble sort](https://wikipedia.org/wiki/Bubble_sort) | O(n) | O(n²) | O(n²) |
|
||||
|
@ -2,6 +2,6 @@
|
||||
|
||||
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
|
||||
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
|
||||
| [Insertion sort](https://wikipedia.org/wiki/Insertion_sort) | O(n) | O(n²) | O(n²) |
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------------- | --------- | ------------ | ---------- |
|
||||
| [Insertion sort](https://wikipedia.org/wiki/Insertion_sort) | O(n) | O(n²) | O(n²) |
|
||||
|
@ -2,6 +2,6 @@
|
||||
|
||||
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
|
||||
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
|
||||
| [Merge sort](https://wikipedia.org/wiki/Merge_sort) | O(n log(n)) | O(n log(n)) | O(n log(n)) |
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| --------------------------------------------------- | ----------- | ------------ | ----------- |
|
||||
| [Merge sort](https://wikipedia.org/wiki/Merge_sort) | O(n log(n)) | O(n log(n)) | O(n log(n)) |
|
||||
|
@ -2,6 +2,6 @@
|
||||
|
||||
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
|
||||
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
|
||||
| [Bubble sort](https://wikipedia.org/wiki/Bubble_sort) | O(n) | O(n²) | O(n²) |
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------- | --------- | ------------ | ---------- |
|
||||
| [Bubble sort](https://wikipedia.org/wiki/Bubble_sort) | O(n) | O(n²) | O(n²) |
|
||||
|
@ -1,14 +1,14 @@
|
||||
import readline from 'node:readline'
|
||||
import readline from "node:readline"
|
||||
|
||||
const numbers = []
|
||||
const readlineInterface = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
output: process.stdout,
|
||||
})
|
||||
readlineInterface.on('line', (value) => {
|
||||
readlineInterface.on("line", (value) => {
|
||||
numbers.push(Number(value))
|
||||
})
|
||||
readlineInterface.on('close', solution)
|
||||
readlineInterface.on("close", solution)
|
||||
|
||||
function solution() {
|
||||
const sortedNumbers = bubbleSort(numbers.slice(1))
|
||||
@ -17,7 +17,7 @@ function solution() {
|
||||
})
|
||||
}
|
||||
|
||||
function bubbleSort (numbersInput) {
|
||||
function bubbleSort(numbersInput) {
|
||||
const numbers = [...numbersInput]
|
||||
for (let index1 = 0; index1 < numbers.length; index1++) {
|
||||
for (let index2 = 0; index2 < numbers.length - index1 - 1; index2++) {
|
||||
|
@ -1,14 +1,14 @@
|
||||
import readline from 'node:readline'
|
||||
import readline from "node:readline"
|
||||
|
||||
const numbers = []
|
||||
const readlineInterface = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
output: process.stdout,
|
||||
})
|
||||
readlineInterface.on('line', (value) => {
|
||||
readlineInterface.on("line", (value) => {
|
||||
numbers.push(Number(value))
|
||||
})
|
||||
readlineInterface.on('close', solution)
|
||||
readlineInterface.on("close", solution)
|
||||
|
||||
function solution() {
|
||||
const sortedNumbers = nativeSort(numbers.slice(1))
|
||||
@ -17,6 +17,6 @@ function solution() {
|
||||
})
|
||||
}
|
||||
|
||||
function nativeSort (numbers) {
|
||||
function nativeSort(numbers) {
|
||||
return numbers.sort((number1, number2) => number1 - number2)
|
||||
}
|
||||
|
@ -2,6 +2,6 @@
|
||||
|
||||
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
|
||||
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
|
||||
| [Insertion sort](https://wikipedia.org/wiki/Insertion_sort) | O(n) | O(n²) | O(n²) |
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------------- | --------- | ------------ | ---------- |
|
||||
| [Insertion sort](https://wikipedia.org/wiki/Insertion_sort) | O(n) | O(n²) | O(n²) |
|
||||
|
@ -1,14 +1,14 @@
|
||||
import readline from 'node:readline'
|
||||
import readline from "node:readline"
|
||||
|
||||
const numbers = []
|
||||
const readlineInterface = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
output: process.stdout,
|
||||
})
|
||||
readlineInterface.on('line', (value) => {
|
||||
readlineInterface.on("line", (value) => {
|
||||
numbers.push(Number(value))
|
||||
})
|
||||
readlineInterface.on('close', solution)
|
||||
readlineInterface.on("close", solution)
|
||||
|
||||
function solution() {
|
||||
const sortedNumbers = insertionSort(numbers.slice(1))
|
||||
|
@ -2,6 +2,6 @@
|
||||
|
||||
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
|
||||
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
|
||||
| [Merge sort](https://wikipedia.org/wiki/Merge_sort) | O(n log(n)) | O(n log(n)) | O(n log(n)) |
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| --------------------------------------------------- | ----------- | ------------ | ----------- |
|
||||
| [Merge sort](https://wikipedia.org/wiki/Merge_sort) | O(n log(n)) | O(n log(n)) | O(n log(n)) |
|
||||
|
@ -1,14 +1,14 @@
|
||||
import readline from 'node:readline'
|
||||
import readline from "node:readline"
|
||||
|
||||
const numbers = []
|
||||
const readlineInterface = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
output: process.stdout,
|
||||
})
|
||||
readlineInterface.on('line', (value) => {
|
||||
readlineInterface.on("line", (value) => {
|
||||
numbers.push(Number(value))
|
||||
})
|
||||
readlineInterface.on('close', solution)
|
||||
readlineInterface.on("close", solution)
|
||||
|
||||
function solution() {
|
||||
const sortedNumbers = mergeSort(numbers.slice(1))
|
||||
@ -17,14 +17,14 @@ function solution() {
|
||||
})
|
||||
}
|
||||
|
||||
function divideArray (numbers) {
|
||||
function divideArray(numbers) {
|
||||
const middle = Math.round(numbers.length / 2)
|
||||
const left = numbers.slice(0, middle)
|
||||
const right = numbers.slice(middle)
|
||||
return [left, right]
|
||||
}
|
||||
|
||||
function merge (numbers1, numbers2) {
|
||||
function merge(numbers1, numbers2) {
|
||||
let indexNumbers1 = 0
|
||||
let indexNumbers2 = 0
|
||||
const result = []
|
||||
@ -46,7 +46,7 @@ function merge (numbers1, numbers2) {
|
||||
return result
|
||||
}
|
||||
|
||||
function mergeSort (numbers) {
|
||||
function mergeSort(numbers) {
|
||||
if (numbers.length <= 1) {
|
||||
return numbers
|
||||
}
|
||||
|
@ -2,6 +2,6 @@
|
||||
|
||||
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
|
||||
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
|
||||
| [Bubble sort](https://wikipedia.org/wiki/Bubble_sort) | O(n) | O(n²) | O(n²) |
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------- | --------- | ------------ | ---------- |
|
||||
| [Bubble sort](https://wikipedia.org/wiki/Bubble_sort) | O(n) | O(n²) | O(n²) |
|
||||
|
@ -2,6 +2,6 @@
|
||||
|
||||
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
|
||||
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
|
||||
| [Insertion sort](https://wikipedia.org/wiki/Insertion_sort) | O(n) | O(n²) | O(n²) |
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------------- | --------- | ------------ | ---------- |
|
||||
| [Insertion sort](https://wikipedia.org/wiki/Insertion_sort) | O(n) | O(n²) | O(n²) |
|
||||
|
@ -2,6 +2,6 @@
|
||||
|
||||
Created by [@theoludwig](https://github.com/theoludwig) on 29 June 2021.
|
||||
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| ----------------------------------------------------------- | ----------- | ------------ | ----------- |
|
||||
| [Merge sort](https://wikipedia.org/wiki/Merge_sort) | O(n log(n)) | O(n log(n)) | O(n log(n)) |
|
||||
| Algorithm | Best Case | Average Case | Worst Case |
|
||||
| --------------------------------------------------- | ----------- | ------------ | ----------- |
|
||||
| [Merge sort](https://wikipedia.org/wiki/Merge_sort) | O(n log(n)) | O(n log(n)) | O(n log(n)) |
|
||||
|
Reference in New Issue
Block a user