Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hacking Wizards #63

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Task2/Comp_coding/Famous C++ algorithms/bubble_sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Binary file not shown.
90 changes: 90 additions & 0 deletions Task2/Famous C++ algorithms/BreathFirst_search.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include <bits/stdc++.h>
using namespace std;

// adjacency list representation
class Graph
{

// No. of vertices
int V;

// Pointer to an array containing adjacency lists
vector<list<int>> 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<bool> visited;
visited.resize(V, 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);

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;
}
62 changes: 62 additions & 0 deletions Task2/Famous C++ algorithms/DepthFirst_Search.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <bits/stdc++.h>
using namespace std;

// Graph class represents a directed graph
// using adjacency list representation
class Graph
{
public:
map<int, bool> visited;
map<int, list<int>> 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<int>::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
38 changes: 38 additions & 0 deletions Task2/Famous C++ algorithms/binary_search.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <bits/stdc++.h>
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;
}
9 changes: 8 additions & 1 deletion gitfetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down