fix: converted single to triple backticks (#36228)
This commit is contained in:
@@ -56,21 +56,22 @@ Bubble Sort هي أبسط خوارزمية الفرز التي تعمل من خ
|
||||
|
||||
سيستخدم هذا الرمز الفرز الفقاعي لفرز الصفيف.
|
||||
|
||||
`let arr = [1, 4, 7, 45, 7,43, 44, 25, 6, 4, 6, 9];
|
||||
let sorted = false
|
||||
|
||||
while(!sorted) {
|
||||
sorted = true
|
||||
for(var i=0; i < arr.length; i++) {
|
||||
if(arr[i] < arr[i-1]) {
|
||||
let temp = arr[i];
|
||||
arr[i] = arr[i-1];
|
||||
arr[i-1] = temp;
|
||||
sorted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
```js
|
||||
let arr = [1, 4, 7, 45, 7,43, 44, 25, 6, 4, 6, 9];
|
||||
let sorted = false
|
||||
|
||||
while(!sorted) {
|
||||
sorted = true
|
||||
for(var i=0; i < arr.length; i++) {
|
||||
if(arr[i] < arr[i-1]) {
|
||||
let temp = arr[i];
|
||||
arr[i] = arr[i-1];
|
||||
arr[i-1] = temp;
|
||||
sorted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### الخصائص:
|
||||
|
||||
|
||||
@@ -16,28 +16,29 @@ localeTitle: فرز دلو
|
||||
|
||||
### رمز زائف لدلو الفرز:
|
||||
|
||||
`void bucketSort(float[] a,int n)
|
||||
|
||||
{
|
||||
|
||||
for(each floating integer 'x' in n)
|
||||
|
||||
{
|
||||
|
||||
insert x into bucket[n*x];
|
||||
|
||||
}
|
||||
|
||||
for(each bucket)
|
||||
|
||||
{
|
||||
|
||||
sort(bucket);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
`
|
||||
```
|
||||
void bucketSort(float[] a,int n)
|
||||
|
||||
{
|
||||
|
||||
for(each floating integer 'x' in n)
|
||||
|
||||
{
|
||||
|
||||
insert x into bucket[n*x];
|
||||
|
||||
}
|
||||
|
||||
for(each bucket)
|
||||
|
||||
{
|
||||
|
||||
sort(bucket);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### معلومات اكثر:
|
||||
|
||||
|
||||
@@ -8,26 +8,27 @@ localeTitle: فرز الفرز
|
||||
|
||||
### مثال:
|
||||
|
||||
`For simplicity, consider the data in the range 0 to 9.
|
||||
Input data: 1, 4, 1, 2, 7, 5, 2
|
||||
1) Take a count array to store the count of each unique object.
|
||||
Index: 0 1 2 3 4 5 6 7 8 9
|
||||
Count: 0 2 2 0 1 1 0 1 0 0
|
||||
|
||||
2) Modify the count array such that each element at each index
|
||||
stores the sum of previous counts.
|
||||
Index: 0 1 2 3 4 5 6 7 8 9
|
||||
Count: 0 2 4 4 5 6 6 7 7 7
|
||||
|
||||
The modified count array indicates the position of each object in
|
||||
the output sequence.
|
||||
|
||||
3) Output each object from the input sequence followed by
|
||||
decreasing its count by 1.
|
||||
Process the input data: 1, 4, 1, 2, 7, 5, 2. Position of 1 is 2.
|
||||
Put data 1 at index 2 in output. Decrease count by 1 to place
|
||||
next data 1 at an index 1 smaller than this index.
|
||||
`
|
||||
```
|
||||
For simplicity, consider the data in the range 0 to 9.
|
||||
Input data: 1, 4, 1, 2, 7, 5, 2
|
||||
1) Take a count array to store the count of each unique object.
|
||||
Index: 0 1 2 3 4 5 6 7 8 9
|
||||
Count: 0 2 2 0 1 1 0 1 0 0
|
||||
|
||||
2) Modify the count array such that each element at each index
|
||||
stores the sum of previous counts.
|
||||
Index: 0 1 2 3 4 5 6 7 8 9
|
||||
Count: 0 2 4 4 5 6 6 7 7 7
|
||||
|
||||
The modified count array indicates the position of each object in
|
||||
the output sequence.
|
||||
|
||||
3) Output each object from the input sequence followed by
|
||||
decreasing its count by 1.
|
||||
Process the input data: 1, 4, 1, 2, 7, 5, 2. Position of 1 is 2.
|
||||
Put data 1 at index 2 in output. Decrease count by 1 to place
|
||||
next data 1 at an index 1 smaller than this index.
|
||||
```
|
||||
|
||||
### التنفيذ
|
||||
|
||||
|
||||
@@ -104,21 +104,22 @@ localeTitle: ترتيب بالإدراج
|
||||
|
||||
في ما يلي تطبيق تم إلغاء تنفيذه في جافا سكريبت:
|
||||
|
||||
`function insertion_sort(A) {
|
||||
var len = array_length(A);
|
||||
var i = 1;
|
||||
while (i < len) {
|
||||
var x = A[i];
|
||||
var j = i - 1;
|
||||
while (j >= 0 && A[j] > x) {
|
||||
A[j + 1] = A[j];
|
||||
j = j - 1;
|
||||
}
|
||||
A[j+1] = x;
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
`
|
||||
```
|
||||
function insertion_sort(A) {
|
||||
var len = array_length(A);
|
||||
var i = 1;
|
||||
while (i < len) {
|
||||
var x = A[i];
|
||||
var j = i - 1;
|
||||
while (j >= 0 && A[j] > x) {
|
||||
A[j + 1] = A[j];
|
||||
j = j - 1;
|
||||
}
|
||||
A[j+1] = x;
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
يتم تنفيذ سريع في سويفت كما هو موضح أدناه:
|
||||
|
||||
@@ -141,37 +142,39 @@ localeTitle: ترتيب بالإدراج
|
||||
|
||||
يظهر مثال Java أدناه:
|
||||
|
||||
`public int[] insertionSort(int[] arr)
|
||||
for (j = 1; j < arr.length; j++) {
|
||||
int key = arr[j]
|
||||
int i = j - 1
|
||||
while (i > 0 and arr[i] > key) {
|
||||
arr[i+1] = arr[i]
|
||||
i -= 1
|
||||
}
|
||||
arr[i+1] = key
|
||||
}
|
||||
return arr;
|
||||
`
|
||||
```
|
||||
public int[] insertionSort(int[] arr)
|
||||
for (j = 1; j < arr.length; j++) {
|
||||
int key = arr[j]
|
||||
int i = j - 1
|
||||
while (i > 0 and arr[i] > key) {
|
||||
arr[i+1] = arr[i]
|
||||
i -= 1
|
||||
}
|
||||
arr[i+1] = key
|
||||
}
|
||||
return arr;
|
||||
```
|
||||
|
||||
### الإدراج الإدراج في ج ...
|
||||
|
||||
`void insertionSort(int arr[], int n)
|
||||
{
|
||||
int i, key, j;
|
||||
for (i = 1; i < n; i++)
|
||||
{
|
||||
key = arr[i];
|
||||
j = i-1;
|
||||
while (j >= 0 && arr[j] > key)
|
||||
{
|
||||
arr[j+1] = arr[j];
|
||||
j = j-1;
|
||||
}
|
||||
arr[j+1] = key;
|
||||
}
|
||||
}
|
||||
`
|
||||
```C
|
||||
void insertionSort(int arr[], int n)
|
||||
{
|
||||
int i, key, j;
|
||||
for (i = 1; i < n; i++)
|
||||
{
|
||||
key = arr[i];
|
||||
j = i-1;
|
||||
while (j >= 0 && arr[j] > key)
|
||||
{
|
||||
arr[j+1] = arr[j];
|
||||
j = j-1;
|
||||
}
|
||||
arr[j+1] = key;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### الخصائص:
|
||||
|
||||
|
||||
@@ -12,14 +12,15 @@ localeTitle: دمج التصنيف
|
||||
|
||||
وضعه في الإنجليزية بسيطة ، نقوم بتحليل المشكلة الفرعية إلى جزأين في كل خطوة ولدينا بعض العمل الخطي الذي يتعين علينا القيام به لدمج النصفين اللذين تم فرزهما معاً في كل خطوة.
|
||||
|
||||
`T(n) = 2T(n/2) + n
|
||||
= 2(2T(n/4) + n/2) + n
|
||||
= 4T(n/4) + n + n
|
||||
= 4(2T(n/8) + n/4) + n + n
|
||||
= 8T(n/8) + n + n + n
|
||||
= nT(n/n) + n + ... + n + n + n
|
||||
= n + n + ... + n + n + n
|
||||
`
|
||||
```
|
||||
T(n) = 2T(n/2) + n
|
||||
= 2(2T(n/4) + n/2) + n
|
||||
= 4T(n/4) + n + n
|
||||
= 4(2T(n/8) + n/4) + n + n
|
||||
= 8T(n/8) + n + n + n
|
||||
= nT(n/n) + n + ... + n + n + n
|
||||
= n + n + ... + n + n + n
|
||||
```
|
||||
|
||||
بإحصاء عدد التكرارات لـ n في المجموع في النهاية ، نرى أن هناك lg n + 1 منهم. وبالتالي فإن وقت التشغيل هو n (lg n + 1) = n lg n + n. نلاحظ أن ng n + n <n lg n + n lg n = 2n lg n لـ n> 0 ، وبالتالي فإن وقت التشغيل هو O (n lg n).
|
||||
|
||||
@@ -68,8 +69,9 @@ const merge = (يسار ، يمين) => { var result = \[\]؛ بينما (left.l
|
||||
|
||||
console.log (mergeSort (list)) // \[3، 4، 8، 15، 16، 23، 42\]
|
||||
|
||||
`### Implementation in C
|
||||
`
|
||||
```
|
||||
### Implementation in C
|
||||
```
|
||||
|
||||
C
|
||||
|
||||
@@ -143,11 +145,12 @@ int m = l + (rl) / 2؛
|
||||
return 0;
|
||||
`
|
||||
|
||||
`### Implementation in C++
|
||||
|
||||
Let us consider array A = {2,5,7,8,9,12,13}
|
||||
and array B = {3,5,6,9,15} and we want array C to be in ascending order as well.
|
||||
`
|
||||
```
|
||||
### Implementation in C++
|
||||
|
||||
Let us consider array A = {2,5,7,8,9,12,13}
|
||||
and array B = {3,5,6,9,15} and we want array C to be in ascending order as well.
|
||||
```
|
||||
|
||||
ج ++ vcess mergesort (int A \[\]، int size _a، int B \[\]، int size_ b، int C \[\]) { رمز token _a ، الرمز المميز_ b ، الرمز المميز _c ؛ for (token_ a = 0، token _b = 0، token_ c = 0؛ token _a_ _a && token _b__ __ب؛ ) { إذا (A \[token _a\] <= B \[token_ b\]) C \[token _c ++\] = A \[token_ a ++\]؛ آخر C \[token _c ++\] = B \[token_ b ++\]؛ }__
|
||||
|
||||
@@ -165,8 +168,9 @@ int m = l + (rl) / 2؛
|
||||
|
||||
}
|
||||
|
||||
`### Implementation in Python
|
||||
`
|
||||
```
|
||||
### Implementation in Python
|
||||
```
|
||||
|
||||
الثعبان درجة الحرارة = لا شيء def def (arr، left، right): درجة الحرارة العالمية ، الانقلابات mid = (يسار + يمين) // 2 لأني في النطاق (يسار ، يمين + 1): درجة الحرارة \[i\] = arr \[i\]
|
||||
|
||||
|
||||
@@ -14,65 +14,66 @@ localeTitle: فرز سريع
|
||||
|
||||
تنفيذ سريع في JavaScript:
|
||||
|
||||
`const arr = [6, 2, 5, 3, 8, 7, 1, 4]
|
||||
|
||||
const quickSort = (arr, start, end) => {
|
||||
|
||||
if(start < end) {
|
||||
|
||||
// You can learn about how the pivot value is derived in the comments below
|
||||
let pivot = partition(arr, start, end)
|
||||
|
||||
// Make sure to read the below comments to understand why pivot - 1 and pivot + 1 are used
|
||||
// These are the recursive calls to quickSort
|
||||
quickSort(arr, start, pivot - 1)
|
||||
quickSort(arr, pivot + 1, end)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const partition = (arr, start, end) => {
|
||||
let pivot = end
|
||||
// Set i to start - 1 so that it can access the first index in the event that the value at arr[0] is greater than arr[pivot]
|
||||
// Succeeding comments will expound upon the above comment
|
||||
let i = start - 1
|
||||
let j = start
|
||||
|
||||
// Increment j up to the index preceding the pivot
|
||||
while (j < pivot) {
|
||||
|
||||
// If the value is greater than the pivot increment j
|
||||
if (arr[j] > arr[pivot]) {
|
||||
j++
|
||||
}
|
||||
|
||||
// When the value at arr[j] is less than the pivot:
|
||||
// increment i (arr[i] will be a value greater than arr[pivot]) and swap the value at arr[i] and arr[j]
|
||||
else {
|
||||
i++
|
||||
swap(arr, j, i)
|
||||
j++
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//The value at arr[i + 1] will be greater than the value of arr[pivot]
|
||||
swap(arr, i + 1, pivot)
|
||||
|
||||
//You return i + 1, as the values to the left of it are less than arr[i+1], and values to the right are greater than arr[i + 1]
|
||||
// As such, when the recursive quicksorts are called, the new sub arrays will not include this the previously used pivot value
|
||||
return i + 1
|
||||
}
|
||||
|
||||
const swap = (arr, firstIndex, secondIndex) => {
|
||||
let temp = arr[firstIndex]
|
||||
arr[firstIndex] = arr[secondIndex]
|
||||
arr[secondIndex] = temp
|
||||
}
|
||||
|
||||
quickSort(arr, 0, arr.length - 1)
|
||||
console.log(arr)
|
||||
`
|
||||
```javascript
|
||||
const arr = [6, 2, 5, 3, 8, 7, 1, 4]
|
||||
|
||||
const quickSort = (arr, start, end) => {
|
||||
|
||||
if(start < end) {
|
||||
|
||||
// You can learn about how the pivot value is derived in the comments below
|
||||
let pivot = partition(arr, start, end)
|
||||
|
||||
// Make sure to read the below comments to understand why pivot - 1 and pivot + 1 are used
|
||||
// These are the recursive calls to quickSort
|
||||
quickSort(arr, start, pivot - 1)
|
||||
quickSort(arr, pivot + 1, end)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const partition = (arr, start, end) => {
|
||||
let pivot = end
|
||||
// Set i to start - 1 so that it can access the first index in the event that the value at arr[0] is greater than arr[pivot]
|
||||
// Succeeding comments will expound upon the above comment
|
||||
let i = start - 1
|
||||
let j = start
|
||||
|
||||
// Increment j up to the index preceding the pivot
|
||||
while (j < pivot) {
|
||||
|
||||
// If the value is greater than the pivot increment j
|
||||
if (arr[j] > arr[pivot]) {
|
||||
j++
|
||||
}
|
||||
|
||||
// When the value at arr[j] is less than the pivot:
|
||||
// increment i (arr[i] will be a value greater than arr[pivot]) and swap the value at arr[i] and arr[j]
|
||||
else {
|
||||
i++
|
||||
swap(arr, j, i)
|
||||
j++
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//The value at arr[i + 1] will be greater than the value of arr[pivot]
|
||||
swap(arr, i + 1, pivot)
|
||||
|
||||
//You return i + 1, as the values to the left of it are less than arr[i+1], and values to the right are greater than arr[i + 1]
|
||||
// As such, when the recursive quicksorts are called, the new sub arrays will not include this the previously used pivot value
|
||||
return i + 1
|
||||
}
|
||||
|
||||
const swap = (arr, firstIndex, secondIndex) => {
|
||||
let temp = arr[firstIndex]
|
||||
arr[firstIndex] = arr[secondIndex]
|
||||
arr[secondIndex] = temp
|
||||
}
|
||||
|
||||
quickSort(arr, 0, arr.length - 1)
|
||||
console.log(arr)
|
||||
```
|
||||
|
||||
تنفيذ فرز سريع في C
|
||||
|
||||
|
||||
@@ -59,50 +59,51 @@ QuickSort و MergeSort و HeapSort هي خوارزميات الفرز على أ
|
||||
|
||||
تنفيذ في C:
|
||||
|
||||
`void countsort(int arr[],int n,int place){
|
||||
|
||||
int i,freq[range]={0}; //range for integers is 10 as digits range from 0-9
|
||||
|
||||
int output[n];
|
||||
|
||||
for(i=0;i<n;i++)
|
||||
|
||||
freq[(arr[i]/place)%range]++;
|
||||
|
||||
for(i=1;i<range;i++)
|
||||
|
||||
freq[i]+=freq[i-1];
|
||||
|
||||
for(i=n-1;i>=0;i--){
|
||||
|
||||
output[freq[(arr[i]/place)%range]-1]=arr[i];
|
||||
|
||||
freq[(arr[i]/place)%range]--;
|
||||
|
||||
}
|
||||
|
||||
for(i=0;i<n;i++)
|
||||
|
||||
arr[i]=output[i];
|
||||
|
||||
}
|
||||
|
||||
void radixsort(ll arr[],int n,int maxx){ //maxx is the maximum element in the array
|
||||
|
||||
int mul=1;
|
||||
|
||||
while(maxx){
|
||||
|
||||
countsort(arr,n,mul);
|
||||
|
||||
mul*=10;
|
||||
|
||||
maxx/=10;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
`
|
||||
```
|
||||
void countsort(int arr[],int n,int place){
|
||||
|
||||
int i,freq[range]={0}; //range for integers is 10 as digits range from 0-9
|
||||
|
||||
int output[n];
|
||||
|
||||
for(i=0;i<n;i++)
|
||||
|
||||
freq[(arr[i]/place)%range]++;
|
||||
|
||||
for(i=1;i<range;i++)
|
||||
|
||||
freq[i]+=freq[i-1];
|
||||
|
||||
for(i=n-1;i>=0;i--){
|
||||
|
||||
output[freq[(arr[i]/place)%range]-1]=arr[i];
|
||||
|
||||
freq[(arr[i]/place)%range]--;
|
||||
|
||||
}
|
||||
|
||||
for(i=0;i<n;i++)
|
||||
|
||||
arr[i]=output[i];
|
||||
|
||||
}
|
||||
|
||||
void radixsort(ll arr[],int n,int maxx){ //maxx is the maximum element in the array
|
||||
|
||||
int mul=1;
|
||||
|
||||
while(maxx){
|
||||
|
||||
countsort(arr,n,mul);
|
||||
|
||||
mul*=10;
|
||||
|
||||
maxx/=10;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### معلومات اكثر:
|
||||
|
||||
|
||||
@@ -43,8 +43,9 @@ localeTitle: اختيار نوع
|
||||
|
||||
تبديل الدالة (A، x، y) { var temp = A \[x\]؛ A \[x\] = A \[y\]؛ A \[ص\] = درجة الحرارة }
|
||||
|
||||
`### Implementation in Python
|
||||
`
|
||||
```
|
||||
### Implementation in Python
|
||||
```
|
||||
|
||||
الثعبان def seletion _sort (arr): إن لم يكن arr: عودة arr لأني في المدى (len (arr)): دقيقة_ ط = ط لـ j في النطاق (i + 1، len (arr)): إذا كان \[j\] <arr \[min _i\]: دقيقة_ ط = ي arr \[i\] ، arr \[min _i\] = arr \[min_ i\] ، arr \[i\] \`\` \`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user