fix(guide): simplify directory structure

This commit is contained in:
Mrugesh Mohapatra
2018-10-16 21:26:13 +05:30
parent f989c28c52
commit da0df12ab7
35752 changed files with 0 additions and 317652 deletions

View File

@ -0,0 +1,124 @@
---
title: Breadth First Search (BFS)
localeTitle: نطاق البحث الأول (BFS)
---
## نطاق البحث الأول (BFS)
Breadth First Search هي واحدة من أكثر خوارزميات الرسم البياني بسيطة. يقوم بتجاوز الرسم البياني عن طريق التحقق أولاً من العقدة الحالية ثم توسيعها بإضافة خلفائها إلى المستوى التالي. يتم تكرار العملية لجميع العقد في المستوى الحالي قبل الانتقال إلى المستوى التالي. إذا تم العثور على الحل يتوقف البحث.
### تصور
![](https://upload.wikimedia.org/wikipedia/commons/4/46/Animated_BFS.gif)
### تقييم
تعقيد الفضاء: O (n)
تعقيد حالة الوقت أسوأ: O (n)
اكتمال بحث First على مجموعة محدودة من العقد وأفضل إذا كانت تكلفة الانتقال من عقدة إلى أخرى ثابتة.
### رمز C ++ لتنفيذ BFS
`// Program to print BFS traversal from a given
// source vertex. BFS(int s) traverses vertices
// reachable from s.
#include<iostream>
#include <list>
using namespace std;
// This class represents a directed graph using
// adjacency list representation
class Graph
{
int V; // No. of vertices
// Pointer to an array containing adjacency
// lists
list<int> *adj;
public:
Graph(int V); // Constructor
// function to add an edge to graph
void addEdge(int v, int w);
// prints BFS traversal from a given source s
void BFS(int s);
};
Graph::Graph(int V)
{
this->V = V;
adj = new list<int>[V];
}
void Graph::addEdge(int v, int w)
{
adj[v].push_back(w); // Add w to v's list.
}
void Graph::BFS(int s)
{
// Mark all the vertices as not visited
bool *visited = new bool[V];
for(int i = 0; i < V; i++)
visited[i] = false;
// Create a queue for BFS
list<int> queue;
// Mark the current node as visited and enqueue it
visited[s] = true;
queue.push_back(s);
// 'i' will be used to get all adjacent
// vertices of a vertex
list<int>::iterator i;
while(!queue.empty())
{
// Dequeue a vertex from queue and print it
s = queue.front();
cout << s << " ";
queue.pop_front();
// Get all adjacent vertices of the dequeued
// vertex s. If a adjacent has not been visited,
// then mark it visited and enqueue it
for (i = adj[s].begin(); i != adj[s].end(); ++i)
{
if (!visited[*i])
{
visited[*i] = true;
queue.push_back(*i);
}
}
}
}
// Driver program to test methods of graph class
int main()
{
// Create a graph given in the above diagram
Graph g(4);
g.addEdge(0, 1);
g.addEdge(0, 2);
g.addEdge(1, 2);
g.addEdge(2, 0);
g.addEdge(2, 3);
g.addEdge(3, 3);
cout << "Following is Breadth First Traversal "
<< "(starting from vertex 2) \n";
g.BFS(2);
return 0;
}
`
#### معلومات اكثر:
[الرسوم البيانية](https://github.com/freecodecamp/guides/computer-science/data-structures/graphs/index.md)
[عمق البحث الأول (DFS)](https://github.com/freecodecamp/guides/tree/master/src/pages/algorithms/graph-algorithms/depth-first-search/index.md)

View File

@ -0,0 +1,105 @@
---
title: Depth First Search (DFS)
localeTitle: عمق البحث الأول (DFS)
---
## عمق البحث الأول (DFS)
يعد Depth First Search واحدًا من أكثر خوارزميات الرسم البياني بسيطة. إنها تعبر الرسم البياني عن طريق التحقق أولاً من العقدة الحالية ومن ثم الانتقال إلى أحد مساعديها لتكرار العملية. إذا لم يكن لدى العقدة الحالية أي اختبار للتحقق ، فإننا ننتقل إلى سابقه وتستمر العملية (بالانتقال إلى سواقة أخرى). إذا تم العثور على الحل يتوقف البحث.
### تصور
![](https://upload.wikimedia.org/wikipedia/commons/7/7f/Depth-First-Search.gif)
### التنفيذ (C ++ 14)
\`\` \`ج ++
# تتضمن
# تتضمن
# تتضمن
# تتضمن
استخدام اسم للمحطة؛
الرسم البياني للفئة { في التلفاز؛ // عدد القمم
`// pointer to a vector containing adjacency lists
vector < int > *adj;
`
عامة: الرسم البياني (كثافة العمليات) ؛ // البناء
``// function to add an edge to graph
void add_edge(int v, int w);
// prints dfs traversal from a given source `s`
void dfs();
void dfs_util(int s, vector < bool> &visited);
``
الرسم البياني :: Graph (int v) { هذا -> v = v؛ adj = new vector <int> \[v\]؛ }
void Graph :: add _edge (int u، int v) { adj \[u\] .الرجوع_ مرة أخرى (v)؛ // add v to u's list adj \[v\] .العودة _(v)؛ // add u to v's list (أزل هذا البيان إذا تم توجيه الرسم البياني!) } void Graph :: dfs () { // زار متجه - لتتبع العقد التي تمت زيارتها خلال DFS تمت زيارة vector <bool> (v، false)؛ // بمناسبة جميع العقد / الرؤوس كما لم تتم زيارته لـ (int i = 0؛ i <v؛ i ++) إذا (! زار \[أنا\]) dfs_ util (i، visited)؛ } // لاحظ استخدام استدعاء من قبل هنا! void Graph :: dfs\_util (int s، vector <bool> & visited) { // قم بتمييز العقدة / قمة الرأس الحالية كما تمت زيارتها زار \[ص\] = صحيح. // إخراجها إلى الإخراج القياسي (الشاشة) cout << s << ""؛
`// traverse its adjacency list and recursively call dfs_util for all of its neighbours!
// (only if the neighbour has not been visited yet!)
for(vector < int > :: iterator itr = adj[s].begin(); itr != adj[s].end(); itr++)
if(!visited[*itr])
dfs_util(*itr, visited);
`
}
انت مين() { // أنشئ رسمًا بيانيًا باستخدام طبقة الرسم البياني التي حددناها أعلاه الرسم البياني (4) ؛ g.add _edge (0، 1)؛ g.add_ edge (0، 2)؛ g.add _edge (1، 2)؛ g.add_ edge (2، 0)؛ g.add _edge (2، 3)؛ g.add_ edge (3، 3)؛
`cout << "Following is the Depth First Traversal of the provided graph"
<< "(starting from vertex 0): ";
g.dfs();
// output would be: 0 1 2 3
return 0;
`
}
`### Evaluation
Space Complexity: O(n)
Worse Case Time Complexity: O(n)
Depth First Search is complete on a finite set of nodes. I works better on shallow trees.
### Implementation of DFS in C++
`
ج ++
# تتضمن
# تتضمن
# تتضمن
استخدام اسم للمحطة؛
الرسم البياني للهيكل { في التلفاز؛ bool \* _adj؛ عامة: الرسم البياني (كثافة العمليات vcount) ؛ void addEdge (int u، int v)؛ void deleteEdge (int u، int v)؛ قوه موجهة_ _DFS (int s) ؛ void DFSUtil (int s، vector_ _وDFS، ناقلات_ _وزار)؛ }؛ Graph :: Graph (int vcount) { هذا-> v = vcount ؛ this-> adj = new bool_ \[vcount\]؛ ل (int i = 0؛ i
void Graph :: addEdge (int u، int w) { هذا-> صفة \[ش\] \[ث\] = صحيح. هذا-> صفة \[ث\] \[ش\] = صحيح. }
void Graph :: deleteEdge (int u، int w) { هذا-> صفة \[ش\] \[ث\] = كاذبة؛ هذا-> صفة \[ث\] \[ش\] = كاذبة؛ }
void Graph :: DFSUtil (int s، vector & DFS ، ناقلات وزار) { زار \[ق\] = صحيح. dfs.push\_back (ق)؛ ل (int i = 0؛ i الخامس، وأنا ++) { if (this-> adj \[s\] \[i\] == true && visited \[i\] == false) DFSUtil (ط، DFS، زار)؛ } }
قوه موجهة الرسم البياني :: DFS (int s) { قوه موجهة زار (هذا-> الخامس)؛ قوه موجهة DFS. DFSUtil (ق، DFS، زار)؛ العودة dfs؛ } \`\` \`
#### معلومات اكثر:
[الرسوم البيانية](https://github.com/freecodecamp/guides/computer-science/data-structures/graphs/index.md)
[نطاق البحث الأول (BFS)](https://github.com/freecodecamp/guides/tree/master/src/pages/algorithms/graph-algorithms/breadth-first-search/index.md)
[عمق البحث الأول (DFS) - ويكيبيديا](https://en.wikipedia.org/wiki/Depth-first_search)

View File

@ -0,0 +1,93 @@
---
title: Dijkstra's Algorithm
localeTitle: خوارزمية Dijkstra
---
# خوارزمية Dijkstra
خوارزمية Dijkstra هي خوارزمية رسم بياني قدمها EW Dijkstra. يجد مسار أقصر مصدر مفرد في الرسم البياني مع حواف غير سالبة. (لماذا؟)
نقوم بإنشاء صفيفين: زيارة والمسافة ، والتي تسجل ما إذا كان يتم زيارة قمة الرأس وما هي المسافة الدنيا من قمة الرأس على التوالي. يتم تعيين المصفوفة التي تمت زيارتها في البداية على أنها خاطئة والمسافة باعتبارها لانهائية.
نبدأ من قمة الرأس المصدر. دع الذروة الحالية تكون u والقرناصات المتاخمة لها v الآن لكل v الذي يكون متجها إلى u ، يتم تحديث المسافة إذا لم يتم زيارتها من قبل والمسافة من u أقل من المسافة الحالية. ثم نختار قمة الرأس التالية بأقل مسافة والتي لم يتم زيارتها.
غالبًا ما يتم استخدام قائمة انتظار الأولوية للوفاء بهذا المطلب الأخير في أقل وقت ممكن. فيما يلي تنفيذ نفس الفكرة باستخدام طابور الأولوية في Java.
`import java.util.*;
public class Dijkstra {
class Graph {
LinkedList<Pair<Integer>> adj[];
int n; // Number of vertices.
Graph(int n) {
this.n = n;
adj = new LinkedList[n];
for(int i = 0;i<n;i++) adj[i] = new LinkedList<>();
}
// add a directed edge between vertices a and b with cost as weight
public void addEdgeDirected(int a, int b, int cost) {
adj[a].add(new Pair(b, cost));
}
public void addEdgeUndirected(int a, int b, int cost) {
addEdgeDirected(a, b, cost);
addEdgeDirected(b, a, cost);
}
}
class Pair<E> {
E first;
E second;
Pair(E f, E s) {
first = f;
second = s;
}
}
// Comparator to sort Pairs in Priority Queue
class PairComparator implements Comparator<Pair<Integer>> {
public int compare(Pair<Integer> a, Pair<Integer> b) {
return a.second - b.second;
}
}
// Calculates shortest path to each vertex from source and returns the distance
public int[] dijkstra(Graph g, int src) {
int distance[] = new int[gn]; // shortest distance of each vertex from src
boolean visited[] = new boolean[gn]; // vertex is visited or not
Arrays.fill(distance, Integer.MAX_VALUE);
Arrays.fill(visited, false);
PriorityQueue<Pair<Integer>> pq = new PriorityQueue<>(100, new PairComparator());
pq.add(new Pair<Integer>(src, 0));
distance[src] = 0;
while(!pq.isEmpty()) {
Pair<Integer> x = pq.remove(); // Extract vertex with shortest distance from src
int u = x.first;
visited[u] = true;
Iterator<Pair<Integer>> iter = g.adj[u].listIterator();
// Iterate over neighbours of u and update their distances
while(iter.hasNext()) {
Pair<Integer> y = iter.next();
int v = y.first;
int weight = y.second;
// Check if vertex v is not visited
// If new path through u offers less cost then update distance array and add to pq
if(!visited[v] && distance[u]+weight<distance[v]) {
distance[v] = distance[u]+weight;
pq.add(new Pair(v, distance[v]));
}
}
}
return distance;
}
public static void main(String args[]) {
Dijkstra d = new Dijkstra();
Dijkstra.Graph g = d.new Graph(4);
g.addEdgeUndirected(0, 1, 2);
g.addEdgeUndirected(1, 2, 1);
g.addEdgeUndirected(0, 3, 6);
g.addEdgeUndirected(2, 3, 1);
g.addEdgeUndirected(1, 3, 3);
int dist[] = d.dijkstra(g, 0);
System.out.println(Arrays.toString(dist));
}
}
`

View File

@ -0,0 +1,47 @@
---
title: Floyd Warshall Algorithm
localeTitle: Floyd Warshall Algorithm
---
## Floyd Warshall Algorithm
خوارزمية Floyd Warshall هي خوارزمية رائعة للعثور على أقصر مسافة بين جميع الرؤوس في الرسم البياني. يحتوي على خوارزمية موجزة جداً و O (V ^ 3) تعقيد وقت (حيث V عدد الرؤوس). يمكن استخدامه مع الأوزان السلبية ، على الرغم من أن دورات الوزن السلبية يجب ألا تكون موجودة في الرسم البياني.
### تقييم
تعقيد الفضاء: O (V ^ 2)
تعقيد وقت حالة أسوأ: O (V ^ 3)
### تنفيذ بايثون
`# A large value as infinity
inf = 1e10
def floyd_warshall(weights):
V = len(weights)
distance_matrix = weights
for k in range(V):
next_distance_matrix = [list(row) for row in distance_matrix] # make a copy of distance matrix
for i in range(V):
for j in range(V):
# Choose if the k vertex can work as a path with shorter distance
next_distance_matrix[i][j] = min(distance_matrix[i][j], distance_matrix[i][k] + distance_matrix[k][j])
distance_matrix = next_distance_matrix # update
return distance_matrix
# A graph represented as Adjacency matrix
graph = [
[0, inf, inf, -3],
[inf, 0, inf, 8],
[inf, 4, 0, -2],
[5, inf, 3, 0]
]
print(floyd_warshall(graph))
`
#### معلومات اكثر:
[الرسوم البيانية](https://github.com/freecodecamp/guides/computer-science/data-structures/graphs/index.md)
[فلويد وارهال - ويكيبيديا](https://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm)

View File

@ -0,0 +1,23 @@
---
title: Graph algorithms
localeTitle: خوارزميات الرسم البياني
---
## خوارزميات الرسم البياني
الخوارزميات البيانية هي مجموعة من الإرشادات التي تجتاز (تزور العقد).
يتم استخدام بعض الخوارزميات للعثور على عقدة محددة أو المسار بين عقدتين معينتين.
### لماذا خوارزميات الرسم البياني مهمة
الرسوم البيانية هي هياكل بيانات مفيدة للغاية والتي يمكن أن تكون نماذج لمشكلات مختلفة. هذه الخوارزميات لها تطبيقات مباشرة على مواقع الشبكات الاجتماعية ، ونمذجة آلة الدولة وغيرها الكثير.
### بعض خوارزميات الرسم البياني المشتركة
بعض خوارزميات الرسم البياني الأكثر شيوعًا هي:
[الرسوم البيانية](https://github.com/freecodecamp/guides/computer-science/data-structures/graphs/index.md)
[نطاق البحث الأول (BFS)](https://github.com/freecodecamp/guides/tree/master/src/pages/algorithms/graph-algorithms/breadth-first-search/index.md)
[عمق البحث الأول (DFS)](https://github.com/freecodecamp/guides/tree/master/src/pages/algorithms/graph-algorithms/depth-first-search/index.md)