Skip to main content

Posts

Showing posts from June, 2020

Linked List Data Structure | Creation and Traversal

Introduction: In this tutorial we will create our linked list. Before writing code let's understand key words related to linked list: 1. Head:    first node of the linked list is called the head of the list. and this node is most important. 2.Tail:       last node is called the tail of the list which must points to  null.            step1: For creating the list first of all let's declare the structure of Nodes of the list: struct Node{ int val; struct Node *next; } step2: write main function: int main(){     int n;     cout<<"enter the number of Nodes:";     cin>>n;     struct Node* head = NULL;     struct Node* temp;     int m;     while(n--){         cout<<"enter the data into nodes:";         cin>>m;    ...

Binary Tree Right Side View | Leetcode Solution

if you know level order traversal then you also know the solution of this question. this question is same as level order traversal with little modification.   vector<int> rightSideView(TreeNode* root) {                 vector<int>mainans;          queue<TreeNode*> q;         if(root==NULL){             return mainans;         }         q.push(root);         q.push(NULL);         TreeNode *ans,*ans1;         while(!q.empty()){               ans=q.front();               ...

Binary Tree Level Order Traversal | Leetcode solution

Let's see this problem from leetcode. if you have already learn about tree traversals, then we know that there are basically two types of traversal technique we have. DFS and BFS. so to solve these kind of problem we will use one of these techniques. even whenever there is question related to traversal in Tree data structure you should only think about these two and you will get the solution. so here we are going to use BFS, because it uses queue data structure and according to the question it will be a good choice.  vector<vector<int>> levelOrder(TreeNode* root) {         vector<vector<int>> mainans;         vector<int>v;         queue<TreeNode*> q;         if(root==NULL){             return mainans;         }  ...

Array vs Linked List

Benefits of Linked List over Array: 1.Deletion and Insertion:  -> Deletion and Insertion in linked is less time consuming over array.    Deletion: if we delete any element from array except last element, then we have to shift all element backward       after the deleted element. so suppose we have an array of 10 integers and if we delete element from index five, then we have to shift element from index 6 to 9 backward. and it will consume more time. while deletion in list is less time consuming. we will see it later. Insertion: if we insert an element in the array except last index, then  we have to shift the remaining element after that index towards right. and it will take more time. while insertion in linked list is much profitable than array. 2.We can dynamically increase the size of the linked list as we allocate memory to nodes at runtime(or dynamically). while in case of array we have to declare it size during writing of code. ...

Linked List Data Structure | Linked List tutorial

What is Linked List? ->Linked List is a data structure. it means it is a way to store our data like array. there are some benefits for which we use Linked List over array which we will see later. ->In practical way, Linked List is collection of Nodes. ->It is a linear data structure. don't think too much, just understand one thing linear means a straight line . so what i want to say is it stores data and forms a structure like a straight line, or linear means we can say that we can traverse it using  a single for loop. this is enough for basic understanding about linear data structure. another linear data structures are Array, Stack, Queue etc. ->let's understand it using some practical examples: you can take any examples in which there is a concept of linking of one to another, you can take an example of a crime thriller movie, where to catch the murderer, police finds the links of one with another and at the end they reach to the murderer. what i want to say is on...

Integrating Frontend to Backend | MERN stack(100% working)

How to Integrate frontend to backend in MERN stack? For integrating the frontend to backend just do two things. Step1: Go and install cors on both side (front end as well as backend)              To install cors simply open the folder into terminal and type npm install cors--save. step 2: just go to your front end section(react app) open package.json file.                 and just add one line into package.json file.           "proxy":"http://localhost:4000" here i am using 4000, so what is 4000 ?. this is the port  on which our backend is listening. so it may be possible that u may have other port number on which your server is listening. so put yours port number on which your backend server is listening. and this proxy thing we have to add in frontend part not in backend part. Now it may be possible that you want to know ...

Group Anagrams solution with explanation:Leetcode solution

what is Anagrams? suppose we have two strings and the characters present in both of the strings are same. then both will be called anagram of each other. eg:" rat" and "art" both are anagram of each other. the characters present in both string are same. eg: "raat" and "art" these are not anagrams of each other. and the reason is that the frequency of "a" in "raat" is 2. while the frequency of "a" in "art" is 1. so these are not anagrams of each other. in short two strings will be anagram of each other if they have same characters and the count(frequency) of each and every character must be same in both strings. Solution: There are different ways to solve this question, so here we are going to use Hashmap to solve this question. cause whenever there is need to search we should go with the data structure which use balanced binary tress or hashing. and we know that Hashmap  uses balanced binary trees. so using...