diff --git a/Task2/Comp_coding/Famous C++ algorithms/bubble_sort.cpp b/Task2/Comp_coding/Famous C++ algorithms/bubble_sort.cpp index 651295b..dbbbbbb 100644 --- a/Task2/Comp_coding/Famous C++ algorithms/bubble_sort.cpp +++ b/Task2/Comp_coding/Famous C++ algorithms/bubble_sort.cpp @@ -30,7 +30,7 @@ int main() cout << "Sorted array: \n"; int i; - for (i = 0; i < size; i++) + for (i = 0; i < N; i++) cout << " " << arr[i]; return 0; diff --git a/Task2/Comp_coding/Famous C++ algorithms/bubble_sort.exe b/Task2/Comp_coding/Famous C++ algorithms/bubble_sort.exe new file mode 100644 index 0000000..6296d81 Binary files /dev/null and b/Task2/Comp_coding/Famous C++ algorithms/bubble_sort.exe differ diff --git a/Task2/Famous C++ algorithms/BreathFirst_search.cpp b/Task2/Famous C++ algorithms/BreathFirst_search.cpp new file mode 100644 index 0000000..faf39fa --- /dev/null +++ b/Task2/Famous C++ algorithms/BreathFirst_search.cpp @@ -0,0 +1,90 @@ +#include +using namespace std; + +// adjacency list representation +class Graph +{ + + // No. of vertices + int V; + + // Pointer to an array containing adjacency lists + vector> adj; + +public: + // Constructor + Graph(int V); + + // 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.resize(V); +} + +void Graph::addEdge(int v, int w) +{ + // Add w to v’s list. + adj[v].push_back(w); +} + +void Graph::BFS(int s) +{ + // Mark all the vertices as not visited + vector visited; + visited.resize(V, false); + + // Create a queue for BFS + list queue; + + // Mark the current node as visited and enqueue it + visited[s] = true; + queue.push_back(s); + + 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 an adjacent has not been visited, + // then mark it visited and enqueue it + for (auto adjacent : adj[s]) + { + if (!visited[adjacent]) + { + visited[adjacent] = true; + queue.push_back(adjacent); + } + } + } +} + +// Driver code +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); // starting node + + return 0; +} diff --git a/Task2/Famous C++ algorithms/DepthFirst_Search.cpp b/Task2/Famous C++ algorithms/DepthFirst_Search.cpp new file mode 100644 index 0000000..9aa3429 --- /dev/null +++ b/Task2/Famous C++ algorithms/DepthFirst_Search.cpp @@ -0,0 +1,62 @@ +#include +using namespace std; + +// Graph class represents a directed graph +// using adjacency list representation +class Graph +{ +public: + map visited; + map> adj; + + // Function to add an edge to graph + void addEdge(int v, int w); + + // DFS traversal of the vertices + // reachable from v + void DFS(int v); +}; + +void Graph::addEdge(int v, int w) +{ + // Add w to v’s list. + adj[v].push_back(w); +} + +void Graph::DFS(int v) +{ + // Mark the current node as visited and + // print it + visited[v] = true; + cout << v << " "; + + // Recur for all the vertices adjacent + // to this vertex + list::iterator i; + for (i = adj[v].begin(); i != adj[v].end(); ++i) + if (!visited[*i]) + DFS(*i); +} + +// Driver code +int main() +{ + // Create a graph given in the above diagram + Graph g; + 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 Depth First Traversal" + " (starting from vertex 2) \n"; + + // Function call + g.DFS(2); // starting node + + return 0; +} + +// improved by Vishnudev C diff --git a/Task2/Famous C++ algorithms/binary_search.cpp b/Task2/Famous C++ algorithms/binary_search.cpp index e69de29..6d3145e 100644 --- a/Task2/Famous C++ algorithms/binary_search.cpp +++ b/Task2/Famous C++ algorithms/binary_search.cpp @@ -0,0 +1,38 @@ +#include +using namespace std; + +// An iterative binary search function. +int binarySearch(int arr[], int l, int r, int x) +{ + while (l <= r) + { + int m = l + (r - l) / 2; + + // Check if x is present at mid + if (arr[m] == x) + return m; + + // If x greater, ignore left half + if (arr[m] < x) + l = m + 1; + + // If x is smaller, ignore right half + else + r = m - 1; + } + + // If we reach here, then element was not present + return -1; +} + +int main() +{ + int arr[] = {2, 3, 4, 10, 40}; + int x = 10; + int n = sizeof(arr) / sizeof(arr[0]); + int result = binarySearch(arr, 0, n - 1, x); + (result == -1) + ? cout << "Element is not present in array" + : cout << "Element is present at index " << result; + return 0; +} diff --git a/gitfetch.js b/gitfetch.js index 1724d01..5bf27c6 100644 --- a/gitfetch.js +++ b/gitfetch.js @@ -84,7 +84,14 @@ const profiles = [ { githubUsername: "vaibhavsahu1290", linkedinID: "vaibhav-sahu-ba5a8528b" }, { githubUsername: "Rimjhim-mm", linkedinID: "rimjhim-tiwari-a391a7253" }, { githubUsername: "Ayus3h", linkedinID: "ayush-yadav-57134728b" }, - { githubUsername: "drifterDev", linkedinID: "mateo-álvarez-murillo-34679b259" }, + { + githubUsername: "drifterDev", + linkedinID: "mateo-álvarez-murillo-34679b259", + }, + { + githubUsername: "theharism", + linkedinID: "muhammad-haris-0b6a6b1b7", + }, // Add more profiles as needed