15 Git Commands Every Developer Should Know.

git commands

Git is a distributed version control system designed to manage software code changes and collaboration between developers. It is an essential tool for any software development project as it helps developers to track changes to their codebase, work on code collaboratively with other team members, and maintain different versions of their codebase.


In this article, I am going to share the list of 15 important git commands that every developer should know because you all are going to use them once in your coding journey.

  • git init: Initializes a new Git repository in your local directory.
  • git clone: Creates a copy of an existing Git repository on your local machine.
  • git add: Adds changes to your working directory to the staging area for the next commit.
  • git commit: Creates a new commit with the changes from the staging area and adds a commit message.
  • git status: Shows the status of your working directory and staging area, including which files have been modified, added, or deleted.
  • git log: Shows a list of all commits in the repository, including the commit message, author, and timestamp.
  • git branch: Lists all branches in the repository or creates a new branch.
  • git checkout: Switches to a different branch or restores files from a previous commit.
  • git merge: Merges changes from one branch into another.
  • git push: Uploads your local commits to a remote repository.
  • git pull: Downloads changes from a remote repository to your local machine.
  • git fetch: Downloads changes from a remote repository to your local machine, but does not merge them into your local branches.
  • git reset: Resets changes in your working directory to a previous commit or unstages changes from the staging area.
  • git revert: Reverses a commit and creates a new commit with the changes reversed.
  • git tag: Creates a new tag for a specific commit or lists all existing tags.

These are just some of the many Git commands available, but they cover the most essential tasks you need to manage your Git repository effectively.

C++ Program for Concatenation of Array.

Given an integer array nums of length n, create a new array ans of length 2n such that ans is the concatenation of two nums arrays. 

  • ans[i] = nums[i] and ans[i+n] = nums[i]
  • 0 <= i < n

Example:
Input: nums = [3, 2, 4]
Output: ans = [3, 2, 4, 3, 2, 4]

Input: nums = [1, 3, 2, 4]
Output: ans = [1, 3, 2, 4, 1, 3, 2, 4]
Explaination: 
ans = [nums[0], nums[1], nums[2], nums[3], nums[0], nums[1], nums[2], nums[3]]

Algorithm 1:
  • Declare two integer arrays nums and ans of size n and 2n respectively.
  • Read the values of the array nums from the user.
  • Use a loop to copy the elements of nums into the first half of ans, i.e., from ans[0] to ans[n-1].
  • Use another loop to copy the elements of nums into the second half of ans, i.e., from ans[n] to ans[2n-1].
  • Print the elements of ans to the console.
C++ Code Implementation:
//C++ Program to concatenation of array
#include<iostream>
using namespace std;

//Concatenation function
void getConcatenation(int n, int nums[], int ans[]){
     // copying elements of nums into the first half of ans
   for(int i = 0; i < n; i++) {
      ans[i] = nums[i];
   }

   // copying elements of nums into the second half of ans
   for(int i = 0; i < n; i++) {
      ans[i+n] = nums[i];
   }
}
int main(){

    int nums[] = {1, 3, 2, 8};
    //size of given array
    int size = sizeof(nums)/sizeof(nums[0]);
    int ans[size*2];

    getConcatenation(size, nums, ans);

    for(int i = 0; i < 2*size; i++){
        cout<<ans[i]<<" ";
    }
}
Output:
1 3 2 8 1 3 2 8
  • Time Complexity: O(n) where is the size of the given array.
  • Space Complexity: O(2n) where 2n is the size of the answer array.

Algorithm 2:

In this algorithm, we are iterating over the output array ans and assigning nums[i % n] to ans[i], where % is the modulo operator. This ensures that we repeat the elements of nums from the beginning once we reach the end of the array. 

C++ Code Implementation:
//C++ Program to concatenation of array
#include<iostream>
#include<vector>
using namespace std;

//Concatenation function
vector<int> concatenateArrays(int n, int nums[]) {
   
    vector<int> ans(2 * n);
    for (int i = 0; i < 2 * n; i++) {
        ans[i] = nums[i % n];
    }
    return ans;
}
 
int main(){

    int nums[] = {1, 3, 2, 8};
    //size of given array
    int size = sizeof(nums)/sizeof(nums[0]);

    vector<int> ans  = concatenateArrays(size, nums);

    for(int i = 0; i < 2*size; i++){
        cout<<ans[i]<<" ";
    }
}
Output:
1 3 2 8 1 3 2 8
  • Time Complexity: O(n) where is the size of the given array.
  • Space Complexity: O(2n) where 2n is the size of the answer array.

Java Program to Check Even and Odd Number.

In this program, we will check if the given number is even or odd. To solve this program we must have a basic understanding of if...else statement in Java.


Algorithm for the Java program to check whether a given number is even or odd:

  • Step 1: Start
  • Step 2: Read the input number from the user
  • Step 3: Check if the input number is even or odd:
  • a. If the number is divisible by 2 with no remainder, then it is even
  • b. If the number is not divisible by 2 with a remainder of 1, then it is odd
  • Step 4: Print the result to the console
  • Step 5: End


Java Code Implementation:

import java.util.Scanner;

public class EvenOdd {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int num = input.nextInt();
        if (num % 2 == 0) {
            System.out.println(num + " is even");
        } else {
            System.out.println(num + " is odd");
        }
    }
}
Output:
Enter a number: 12
12 is even

We use an if-else statement to check whether the num is even or odd. We do this by checking whether num is divisible by 2 using the modulo operator %. If num % 2 is 0, then num is even; otherwise, it is odd.

Finally, we print out the result using the println method of the System.out object.

Binary Tree Data Structure in C++

A Binary Tree is a hierarchical data structure in which each node has at most two children, referred to as left child and right child. A binary tree can represent various problems, including hierarchical data, searching, and sorting.


Representation of Binary Tree.

In a binary tree, each node contains a value, and it has two pointers to the left and right child nodes. If a child node does not exist, the pointer is null. The root node is the topmost node of the tree, and it has no parent. The leaf nodes are nodes that have no children, and they are at the bottom of the tree.

A binary tree can be represented in two ways: 
  • Array-based: In the array-based representation, the tree is stored in an array, and the position of each node is determined based on its index.
  • Node-based: In the node-based representation, each node is stored in a separate object, and it contains pointers to its children.
Binary Tree Example

In C++ we represent a tree node of a tree we use structure or class.  
// Method 1: Using "struct" to make
struct Node {
	int data;
	struct Node* left;
	struct Node* right;
};

// Method 2: Using "class" to make
class Node {
public:
	int data;
	Node* left;
	Node* right;
};

Usage of Binary Tree.

  • Hierarchical Data: Binary Trees are used to represent hierarchical data such as family trees, organization charts, file systems, and more.
  • Searching: Binary Trees can be used to perform efficient searching of data. Binary search trees, a type of binary tree, provide fast searching and insertion operations.
  • Sorting: Binary Trees can be used for sorting data efficiently. Heaps, a type of binary tree, are used for heap sort and priority queues.
  • Compression: Binary Trees are used in data compression algorithms such as Huffman coding.

Some Important Terms Used in Tree Data Structure.

  • Node: A node is a basic unit of a tree that contains data and pointers to its child nodes.
  • Root: The root is the topmost node of a tree, from which all other nodes are descendants.
  • Parent: A parent is a node that has one or more child nodes.
  • Child: A child is a node that has a parent node.
  • Sibling: Siblings are nodes that have the same parent node.
  • Leaf: A leaf is a node that has no children.
  • Height: The height of a tree is the length of the longest path from the root node to the leaf node.
  • Depth: The depth of a node is the length of the path from the root node to that node.
  • Degree: The degree of a node is the number of children it has.
  • Subtree: A subtree is a tree that is formed by a node and all its descendants.
  • Binary Tree: A binary tree is a tree data structure in which each node has at most two children.
  • Balanced Tree: A balanced tree is a tree data structure in which the height of the left and right subtrees of any node differ by at most one.
  • Traversal: Traversal refers to the process of visiting every node in a tree data structure exactly once.
  • Search: Search refers to the process of finding a specific node in a tree data structure.
  • Insertion: Insertion refers to the process of adding a new node to a tree data structure.

Advantage of Binary Tree.

  • Fast Search: Binary Trees provide fast searching of data as they have a logarithmic time complexity of O(log n).
  • Efficient Storage: Binary Trees use memory efficiently as they only store the data and the pointers to their children.
  • Easy Traversal: Binary Trees can be easily traversed in different ways such as Inorder, Preorder, and Postorder.
  • Flexible: Binary Trees can be easily modified by adding, deleting, or updating nodes.
  • Balanced Trees: Balanced Binary Trees such as AVL Trees and Red-Black Trees provide efficient searching, insertion, and deletion operations.

10 Essential Windows Shortcuts Every User Should Know.

Windows Shortcuts

Windows shortcuts are an incredibly powerful and efficient way to navigate and control your PC. They allow you to quickly perform tasks and access features without having to waste time clicking through menus or using a mouse. In this article, we will cover 10 essential Windows shortcuts that every user should know.


Windows Key + D

The Windows Key + D shortcut will quickly minimize all open windows and take you straight to your desktop. This is a handy shortcut when you need to access files or folders on your desktop or when you want to quickly switch between applications.


Windows Key + E

The Windows Key + E shortcut will launch Windows Explorer, giving you quick access to all of your files and folders. This is a great way to quickly browse through your files and find what you need without having to open up individual folders.


Windows Key + L

The Windows Key + L shortcut is a quick way to lock your computer when you need to step away from your desk. This is a useful shortcut if you work in an office or public space and want to keep your computer secure.


Windows Key + R

The Windows Key + R shortcut will open the Run dialog box, allowing you to quickly launch programs, files, and folders by typing in their names. This is a great way to quickly access programs or files that you use frequently.


Ctrl + C / Ctrl + X / Ctrl + V

These are the three most common keyboard shortcuts used for copying, cutting, and pasting. Simply select the text or files you want to copy or cut, use Ctrl + C or Ctrl + X, then navigate to where you want to paste the text or files and use Ctrl + V.


Windows Key + Tab

The Windows Key + Tab shortcut is a great way to quickly switch between open applications. It works similarly to Alt + Tab, but with a more visual interface that allows you to see all of your open windows at once.


Ctrl + Z / Ctrl + Y

These shortcuts are used for undoing and redoing actions. If you make a mistake, use Ctrl + Z to undo your last action. If you change your mind and want to redo your action, use Ctrl + Y.


Windows Key + I

The Windows Key + I shortcut will open the Settings app, which is the central hub for managing your Windows settings. From here, you can manage everything from your display settings to your security and privacy settings.


Alt + F4

The Alt + F4 shortcut is a quick way to close an open application. It is a great way to quickly shut down a program that has frozen or is not responding.


Ctrl + Shift + Esc

The Ctrl + Shift + Esc shortcut will open the Task Manager, which is a powerful tool for managing and monitoring your system processes. You can use the Task Manager to see which applications are using the most resources and to close any programs that are causing problems.


Conclusion.

These 10 essential Windows shortcuts will help you navigate and control your PC more efficiently. By using these shortcuts, you can save time and streamline your workflow, making you a more productive and efficient computer user.

Swap Two Numbers in Java.

We can swap two numbers in Java with multiple approaches and in this article, we are going to discuss all those approaches in detail with code.


Approach 1: Using a third variable

In this approach, we use a third variable to swap the values of the two variables.


Java Example Code:

int a = 10;
int b = 20;
int temp;

temp = a;
a = b;
b = temp;

System.out.println("a = " + a); // Output: a = 20
System.out.println("b = " + b); // Output: b = 10

Approach 2: Using arithmetic operations

In this approach, we can use arithmetic operations like addition, subtraction, multiplication, and division to swap the values of the two variables.

Java Example Code:
int a = 10;
int b = 20;

a = a + b; // a = 30
b = a - b; // b = 10
a = a - b; // a = 20

System.out.println("a = " + a); // Output: a = 20
System.out.println("b = " + b); // Output: b = 10

Approach 3: Using the XOR operator

In this approach, we can use the XOR (^) operator to swap the values of the two variables.

Java Example Code:

int a = 10;
int b = 20;

a = a ^ b; // a = 30 (11110)
b = a ^ b; // b = 10 (01010)
a = a ^ b; // a = 20 (10100)

System.out.println("a = " + a); // Output: a = 20
System.out.println("b = " + b); // Output: b = 10
All these approaches have the same time complexity of O(1) as they take constant time to swap the values of two variables. (alert-success)

Difference Between Default and Parameterless Constructor in C++

Constructor is an important concept to understand in Object Oriented Programming and we have many constructors like default, parameterized, and copy constructors. Many get confused that is there any difference between a default constructor and a parameterless constructor. 


In C++, a default constructor and a parameterless constructor are similar in that they both create objects without requiring any arguments. However, there is a subtle difference between the two.


Default Constructor.

A default constructor is a constructor that the compiler generates automatically if no constructor is defined explicitly for a class. The default constructor has no parameters and initializes the data members of the object to their default values (which are typically zero for numeric types and null or empty for pointers and strings).

Example:

class MyClass {
public:
    MyClass() {
        // Default constructor
        // Initialize data members with default values
    }
};


Parameterless Constructor.

A parameterless constructor, on the other hand, is a constructor that is defined explicitly by the programmer and has no parameters. The programmer can define the behavior of the parameterless constructor to initialize the object in any way they see fit.

Example:

class MyClass {
public:
    MyClass(int value) {
        // Parameterized constructor
        // Initialize data members with the provided 'value'
    }
};

Round Up the Result of Integer Division in C++.

In C++, the integer division of two integers produces a result that is truncated toward zero. For example, if we divide 5 by 2, the result would be 2 instead of 2.5, because the decimal part is truncated. However, there are times when we want the result of integer division to be rounded up to the nearest integer. 


Round Up Integer Division using Formula.

Suppose we want to compute the result of integer division a/b and round it up to the nearest integer. We can do this using the following formula:


int result = (a + b - 1) / b;

The idea behind this formula is that we add b-1 to the numerator, which ensures that the division result is always rounded up. 
Example:
int a = 5;
int b = 2;
int result = (a + b - 1) / b;
result is 3, not 2

In this example, the numerator (a+b-1) is 6, and the denominator (b) is 2. The result of the division is therefore 3, which is the closest integer to 2.5, the exact result of the division.
Note: This formula works only for positive integers. If a or b can be negative, you should use a different formula. (alert-passed)

C++ program that demonstrates how to round up the result of integer division:

//C++ code to round up integer division
#include <iostream>
using namespace std;

int main() {
    int a = 5;
    int b = 2;
    int result = (a + b - 1) / b;
    cout << "The result of " << a << " / " << b << " rounded up is " << result << endl;
    return 0;
}
Output:
The result of 5 / 2 rounded up is 3

Round Up Using Ceil() Function.

C++, you can use the ceil() function from the <cmath> header to round up a floating-point value to the nearest integer. However, it's important to note that ceil() works with floating-point values, not with the result of integer division.
Note: If you want to round up the result of integer division, you would need to convert the integers to floating-point values before using ceil() (alert-success)

C++ Code Implementation:

//C++ code to round up integer uisng ceil fun
#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int a = 5;
    int b = 2;
    double result = ceil(static_cast<double>(a) / b);
    cout << "The result of " << a << " / " << b << " rounded up is " << result << endl;
    return 0;
}
Output:
The result of 5 / 2 rounded up is 3

Depth First Search for Graph in C++.

Depth First Search (DFS) is a graph traversal algorithm that explores a graph by visiting as far as possible along each branch before backtracking. It starts from a given source vertex and recursively explores all of its neighbors, marking each vertex as visited as it traverses the graph. Once it reaches the end of a branch, it backtracks to the last unexplored vertex and continues the search.


Algorithm for Depth First Search.

  • Step 1: Create a visited array and initialize it to false.
  • Step 2: Initialize a stack and push the source vertex onto it.
  • Step 3: While the stack is not empty, do the following:
  • a. Pop a vertex from the stack.
  • b. If the vertex has not been visited, mark it as visited and do the following:
  • i. Process the vertex (e.g., print its value).
  • ii. Get its neighbors and push them onto the stack.
  • Step 4: Repeat step 3 until the stack is empty.

Example with Illustration.

depth first search step 1
Step 1

We have one stack to traverse all vertices and a visited array to mark visited vertices. Push the starting vertex 0 in the stack as the initial condition. 

depth first search step 2
Step 2
Pop the top element of the stack that is 0 and mark that index as visited in the visited array and print it. Push all other neighbor vertices of 0 inside the stack if already not visited.
depth first search step 3
Step 3

Pop the top element of the stack that is 2 and mark that index as visited in the visited array and print it. Push all other neighbor vertices of 2 inside the stack if already not visited.
depth first search step 4
Step 4
Pop the top element of the stack that is 3 and mark that index as visited in the visited array and print it. Push all other neighbor vertices of 3 inside the stack if already not visited.
depth first search step 5
Step 5
Pop the top element of the stack that is 1 and mark that index as visited in the visited array and print it. Push all other neighbor vertices of 3 inside the stack if already not visited. Here the stack becomes empty which means traversal is complete.

C++ code for DFS (Depth First Search) Traversal using Stack.

//C++ code implementation for DFS Traversal of graph using Stack
#include <iostream>
#include <vector>
#include <stack>
using namespace std;

//function for dfs
void DFS(int V, vector<int> graph[], int start, vector<bool>& visited) {
    stack<int> s;
    s.push(start);

    while (!s.empty()) {
        int v = s.top();
        s.pop();

        if (!visited[v]) {
            visited[v] = true;
            cout << v << " ";

            for (int u : graph[v]) {
                s.push(u);
            }
        }
    }
}

int main() {
    int V = 4;
    vector<int> graph[V];
    graph[0] = {1, 2};
    graph[1] = {0, 2, 3};
    graph[2] = {0, 1, 3};
    graph[3] = {1, 2};

    vector<bool> visited(V, false);
    DFS(V, graph, 0, visited);
    return 0;
}
Output:
0 2 3 1
  • Time Complexity: O(V + E) where V is the number of vertices and E is the number of Edges. Each vertex and each edge is explored exactly once.
  • Space Complexity: O(V + E) as it uses a stack to keep track of vertices and an array to mark visited vertices. In the worst case, the stack will store all vertices of the longest path, which is the maximum the maximum depth of the recursion.


Algorithm for Depth First Search (Recursive).

  • Step 1: Create a visited array and initialize it to false.
  • Step 2: Call the DFS function with the starting vertex as the argument.
  • Step 3: In the DFS function, mark the current vertex as visited and process it (e.g., print its value).
  • Step 4: For each unvisited neighbor of the current vertex, recursively call the DFS function with the neighbor as the argument.
C++ code for DFS (Depth First Search) Traversal using Recursion:

//C++ code implementation for DFS Traversal of graph using Recursion
#include <iostream>
#include <vector>
#include <stack>
using namespace std;

//function for dfs
void DFS(int V, vector<int> graph[], int start, vector<bool>& visited) {
    visited[start] = true;
    cout << start << " ";

    for (int u : graph[start]) {
        if (!visited[u]) {
            DFS(V, graph, u, visited);
        }
    }
}

int main() {
    int V = 4;
    vector<int> graph[V];
    graph[0] = {1, 2};
    graph[1] = {0, 2, 3};
    graph[2] = {0, 1, 3};
    graph[3] = {1, 2};

    vector<bool> visited(V, false);
    DFS(V, graph, 0, visited);
    return 0;
}
Output:
0 1 2 3
  • Time Complexity: O(V + E) where V is the number of vertices and E is the number of Edges.
  • Space Complexity: O(V) as an array to mark visited vertices. The maximum depth of the recursion is the number of vertices.

Breadth First Search (BFS) for Graph in C++

Breadth First Search (BFS) is a graph traversal algorithm that visits all the vertices of a graph in breadth-first order, meaning that it visits all the vertices at the same level before moving on to the next level. The algorithm uses a queue data structure to keep track of the vertices that need to be visited.


How BFS for Graph is different from BFS for Tree Data structure?

The main difference between the graph and the tree BFS traversal is that a tree cannot contain cycles but a graph can contain cycles. To avoid visiting the same vertex again and again we use a boolean visited array to mark the visited vertices.


If we don't mark the visited vertices, the algorithm may revisit vertices that have already been explored and get stuck in an infinite loop. This is especially true in the case of cycles, where a BFS traversal without marking visited vertices could result in an infinite loop.


Algorithm of Breadth First Search:

  • Step 1: Create a queue data structure and add the starting vertex to the queue.
  • Step 2: While the queue is not empty:
  • Step 3: Dequeue the vertex at the front of the queue and mark it as visited.
  • Step 4: Visit all the unvisited neighbors of the dequeued vertex and add them to the queue.
  • Step 5: If all the vertices have been visited, the algorithm is complete.

Example with Illustration.

step 1 for bfs traversal
Step 1
The BFS traversal order of the above graph is starting from vertex 0 so we push the vertex 0 inside the queue and mark that index as visited.
 
step 2 for bfs traversal
Step 2
Pop the front element 0 from the queue and print it. Push the adjacent vertices 1 and 2 inside the queue and then mark them as visited.
step 3 for bfs traversal
Step 3

Pop the front element 1 from the queue and print it. Push the adjacent vertices 2 and 3 inside the queue but 2 is already visited so push only 3 and then mark them as visited.
step 4 for bfs traversal
Step 4
Pop the front element 2 from the queue and print it. Push the adjacent vertices 3 inside the queue but 3 is already visited so nothing to push.
step 5 for bfs traversal
Step 5
Pop the front element 3 from the queue and print it. Push the adjacent vertices if any and mark them as visited. We can observe that we have visited all the vertices of the given graph. Stop the process once the queue is empty.

C++ Code for BFS Traversal Using Queue.

Here is an example of BFS implementation in C++ for an undirected graph represented as an adjacency list:

//C++ Code for BFS Traversal of Undirected Graph
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

//breadth first search of traversal
void bfs(int V, vector<int> adj_list[], int start) {
    vector<bool> visited(V, false);
    queue<int> q;
    visited[start] = true;
    q.push(start);
    while (!q.empty()) {
        int current_vertex = q.front();
        q.pop();
        cout << current_vertex << " ";
        for (auto neighbor : adj_list[current_vertex]) {
            if (!visited[neighbor]) {
                visited[neighbor] = true;
                q.push(neighbor);
            }
        }
    }
}

int main() {
    int V = 4;
    vector<int> adj_list[V];
    adj_list[0] = {1, 2};
    adj_list[1] = {0, 2, 3};
    adj_list[2] = {0, 1, 3};
    adj_list[3] = {1, 2};

    bfs(V, adj_list, 0);

    return 0;
}
Output:
0 1 2 3
  • Time Complexity: O(V + E) where V is the number of vertices and E is the number of edges.
  • Space Complexity: O(V) where one visited array of size V is used to mark visited vertices and one queue to store adjacent vertices while traversing.


BFS Traversal for Disconnected Graph.

The above code for BFS Traversal will not work if the given graph is disconnected. To understand this concept we first have to understand what is disconnected graph.

Disconnected Graph.

A disconnected graph is a graph in which there is no path between at least two vertices. In other words, a disconnected graph can be split into two or more connected components, where each component contains a group of vertices that are connected to each other but not connected to the vertices in other components.

Example: 
bfs traversal for disconnected graph
Disconnected Graph

We can traverse the disconnected graph by modifying the above BFS code. Below is the C++ code implementation for the BFS traversal of the disconnected graph.

//C++ Code for BFS Traversal of disconnected graph
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

//breadth first search of traversal
void bfs(int V, vector<int> adj_list[], int start, vector<bool> &visited) {
    
    queue<int> q;
    visited[start] = true;
    q.push(start);
    while (!q.empty()) {
        int current_vertex = q.front();
        q.pop();
        cout << current_vertex << " ";
        for (auto neighbor : adj_list[current_vertex]) {
            if (!visited[neighbor]) {
                visited[neighbor] = true;
                q.push(neighbor);
            }
        }
    }
}

int main() {
    int V = 7;
    vector<int> adj_list[V];
    adj_list[0] = {1, 2};
    adj_list[1] = {0, 2, 3};
    adj_list[2] = {0, 1, 3};
    adj_list[3] = {1, 2};
    adj_list[4] = {5, 6};
    adj_list[5] = {4};
    adj_list[6] = {4};

    vector<bool> visited(V, false);
    //for disconnected graph
    for(int i = 0; i < V; i++){
        if(!visited[i]){
            bfs(V, adj_list, i, visited);
        }
    }

    return 0;
}
Output:
0 1 2 3 4 5 6
  • Time Complexity: O(V + E) where V is the number of vertices and E is the number of edges.
  • Space Complexity: O(V) because we are using a visited array of size V and a queue data structure to store adjacent vertices and it is taken at max V size.

DON'T MISS

Nature, Health, Fitness
© all rights reserved
made with by templateszoo