Thursday 29 June 2017

GATE - Graph Theory 7

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Graph Theory 7 Notes 

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

GATE - Graph Theory 8

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Graph Theory 8 Notes 

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

Tuesday 27 June 2017

GATE - Graph Theory 5

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Graph Theory 5 Notes

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

GATE - Graph Theory 6

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Graph Theory 6 Notes

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

Sunday 25 June 2017

GATE - Graph Theory 3

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Graph Theory 3 Notes 

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

GATE - Graph Theory 4

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Graph Theory 4 Notes

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

GATE - Groups 7

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Group Theory 7 Notes 

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

Friday 23 June 2017

GATE - Graph Theory 2

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Graph Theory 2 Notes 

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

GATE - Graph Theory 1

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Graph Theory 1 Notes

Note: The quality of the notes is improved when downloaded or opened in another tab.

Share:

Wednesday 21 June 2017

GATE - Data Structures & Algorithms 2

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Data Structures & Algorithms 2 Notes

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

GATE - Discrete Mathematics 3

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Discrete Mathematics 3 Notes

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

Monday 19 June 2017

GATE - Discrete Mathematics 2

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Discrete Mathematics 2 Notes

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

Thursday 15 June 2017

GATE - Discrete Mathematics 1

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Discrete Mathematics 1 Notes

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

Invert Binary Tree

Invert a binary tree.
For example, convert
     4
   /   \
  2     7
 / \   / \
1   3 6   9
to

     4
   /   \
  7     2
 / \   / \
9   6 3   1



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    void invert(TreeNode *root){
        TreeNode *temp;
        temp = root->left;
        root->left = root->right;
        root->right = temp;
        if(root->left){
            invert(root->left);
        }
        if(root->right){
            invert(root->right);
        }
    }
    TreeNode* invertTree(TreeNode* root) {
        if(root == NULL){
            return NULL;
        }
        invert(root);
        return root;
    }
};
Share:

Saturday 10 June 2017

GATE - Solution to Differential Equations

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Solution to Differential Equations

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

GATE - Random Variable Distributions

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Random Variable Distributions Notes

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.
For example,
Given 1->2->3->3->4->4->5, return 1->2->5.
Given 1->1->1->2->3, return 2->3.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        if(head == NULL || head->next == NULL){
            return head;
        }
        //create a dummy node to avoid the case of head value getting repeated which is difficult to handle
        struct ListNode *res = new struct ListNode(0);
        res->next = head;
        
        struct ListNode *cur = res;
        while(cur->next && cur->next->next){
            //if the next value is same as its next value
            if(cur->next->val == cur->next->next->val){
                int val = cur->next->val;
                //move forward if same value is repeating
                while(cur->next && cur->next->val == val){
                    cur->next = cur->next->next;
                }
            }else{
                cur = cur->next;
            }
        }
        //return next of the dummy node
        return res->next;
    }
};
Share:

Friday 9 June 2017

Git & GitHub - 2 Step by Step Guide

Hi friends,

In the previous post, we discussed the meanings of the terms Git & GitHub and also some of the other things we can do with GitHub. In this post, we will see a detailed step by step process of how to start using the GitHub for our projects. 

Let's now go through the steps of using the GitHub now.
  1. Installing Git and creating a GitHub account
  2. The first step is install Git on our system following the instructions from the Git website.

    Once you have installed the Git on your computer, you also need to create an account on the GitHub website.  

    The following steps will be done through command prompt/terminal.

  3. Initializing Git Repository
  4. The step is to create a new repository/directory (generally called repo) and initializing the git for that repo. This is done by navigating to the directory we want to work in and typing the following command in the command prompt:
    git init


  5. Adding a new file to the repo
  6. Use the echo command in Windows (touch in Linux) to create a sample text file.


    Once you have created the new file, you can use the following command to see which files git knows exists in the repo:
    git status


    Notice that the git officially doesn't track the created file. We need to do commit to make sure git knows this file exists in the repo. 

  7. Adding files to the staging
  8. As in a large application with hundreds of files, we may change only some files and require to commit only those files. So, the add command basically requires us to add the list of files we have made changes to in order to do the commit.


    Notice that after using add command then again checking the status, we see that a new file message has appeared.

  9. Creating a new Repo on GitHub
  10. Now that we have made a commit, we can upload our code to the GitHub website. For this, we need to create a new repository on GitHub by logging onto your GitHub account and clicking the New Repository button. 

    Next, GitHub will ask you some basic information and once you're done filling out the information, press the 'Create repository' button to make your new repo. Next, follow the instructions under the option 'push an existing repository from the command line' section as we've already created a new repo locally.

    Run the above two commands in your command prompt. It will open a window asking you to login in your GitHub account. Once you enter your correct credentials, your commit will take place successfully and you will be able to see the commits in your GitHub profile page.
That's it for the Git & GitHub tutorials. You can now start creating your projects and posting it on GitHub to get attention of the recruiters. 
Share:

GATE - Miscellaneous 3

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Miscellaneous Topics 3 Notes 

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

GATE - Digital Logic Design 2

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Digital Logic Design 2 Notes

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

Wednesday 7 June 2017

GATE - Miscellaneous 1

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Miscellaneous Topics 1 Notes

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

GATE - Miscellaneous 2

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 


Miscellaneous Topics 2 Notes

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

Git & GitHub - 1 Basics

Hi friends,

I have seen many students throughout my undergraduate and graduate studies trying to use Git & GitHub and failing interest soon enough due to lack of good available resources. So, I decided to write myself to help beginners start using Git & GitHub with whatever little knowledge I have on these.

So, let's begin understanding about these two terms first.

Git:  Git is a version control software i.e. while you are building a programming application you can save each little change you make to the application. So, if you make any mistake or you just want to see the previous version of the application to see how it looked before, we can do that using Git. Git is also an open-source application. You can know more about Git from the official Git Website

GitHub: GitHub on the other hand is a collaboration website which always users to publish their Git repositories on the GitHub website. The official page of GitHub can be reached using the GitHub Page Link. GitHub is thus a collaboration tool used by people to interact with Git. 

Now, that we know the difference between the two, we can start learning how to use GitHub. There are five major steps while working with a GitHub project:
  1. Branching - Suppose, we have a working code which is available on a GitHub repository. This is also called as the master. This step is making a branch of the master directory i.e. making the copy of the master before we can make any changes to avoid the application to stop working due to the changes. 
  2. Commit - It is sort of like making changes to the created branch. Whenever we commit the changes made to the code, it stores all of the changes made by creating a snapshot of the project. 
  3. Pull Request - Once we have mode some commits to the project, we open a pull request to the GitHub Website. The pull request compares the branch in which we have made changes to some other branch (may be master). This allows us to see the differences between the two branches to show other people the changes we have made. 
  4. Collaborate - After the pull request, you can collaborate if you find the changes made to the branch are correct. This allows the users to give suggestions about the changes made to the branch which may require to make further changes and do the above steps again.  
  5. Merge - Once the changes made to the branch are accepted, we merge the branch we created and the changes we made and replace it with the master. 
If you want to make changes to an application that is not yours then we require an additional step called Fork.

Fork: Fork creates an exact copy of a Git repository under your GitHub account and you can start using the repository using the above discussed steps.

Cloning Repositories: Sometimes, we may need to download the Git repository and work locally on our computers in case of non-availability of internet. In such as case, we need to clone repositories to start working locally on our computer. The changes made to the cloned repository are not visible on the repository hosted on the GitHub website. 

Now, we see some commonly used Git commands. 
  1. git clone
  2. git pull
  3. git branch
  4. git status
  5. git add
  6. git commit
  7. git push
That's it knowing the basics of Git & GitHub. In the next post, we'll see a detailed step by step process of using these commands for GitHub.
Share:

Tuesday 6 June 2017

GATE - Functions

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Functions Notes

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

GATE - Eigen Values

Hi friends,

This is a post under the series of posts labeled as GATE. I had created short hand written notes during my GATE preparation to revise for various topics. The posts under label GATE include formulae, equations, properties and other important points of various topics in Computer Science subjects summarized into point wise easy to remember hand written notes. 

Eigen Values Notes 

Note: The quality of the notes is improved when downloaded or opened in another tab.


Share:

Four Sum

Given an array of integers, find all combination of four elements in the array whose sum is equal to a given value X.

Idea :
    1) Find all pair sum, requires O(n^2) space
    2) Sort the pair sum.
    3) Find the 4 elements(2 pairs) using the approach in two pair sum solution in O(n^2) time.



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
using namespace std;

struct pairSum{
    int sum, first, second;
};

void findPairSum(int *arr, struct pairSum *temp, int n){
    int k = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            temp[k].sum = arr[i] + arr[j];
            temp[k].first = arr[i];
            temp[k].second = arr[j];
            k++;
        }
    }
}

void merger(struct pairSum *arr, struct pairSum *temp, int low, int mid, int high){
    int i = low, j = mid + 1, k = low;
    while(i <= mid && j <= high){
        if(arr[i].sum <= arr[j].sum){
            temp[k].sum = arr[i].sum;
            temp[k].first = arr[i].first;
            temp[k].second = arr[i].second;
            k++;
            i++;
        } else{
            temp[k].sum = arr[j].sum;
            temp[k].first = arr[j].first;
            temp[k].second = arr[j].second;
            k++;
            j++;
        }
    }
    while(i <= mid){
        temp[k].sum = arr[i].sum;
        temp[k].first = arr[i].first;
        temp[k].second = arr[i].second;
        k++;
        i++;
    }
    while(j <= high){
        temp[k].sum = arr[j].sum;
        temp[k].first = arr[j].first;
        temp[k].second = arr[j].second;
        k++;
        j++;
    }
    for(int i = low; i<= high; i++){
        arr[i].sum = temp[i].sum;
        arr[i].first = temp[i].first;
        arr[i].second = temp[i].second;
    }
}

void mergeSort(struct pairSum *arr, struct pairSum *temp, int low, int high){
    if(low < high){
        int mid = (low + high) / 2;
        mergeSort(arr, temp, low, mid);
        mergeSort(arr, temp, mid + 1, high);
        merger(arr, temp, low, mid, high);
    }
}

void find4Numbers(struct pairSum *arr, int sz, int x){
    struct pairSum *sorted = new pairSum[sz];
    int l = 0, r = sz - 1, sum;
    mergeSort(arr, sorted, 0, sz - 1);
    while(l < r){
        sum = sorted[l].sum + sorted[r].sum;
        if(sum == x && (sorted[l].first != sorted[r].first && sorted[l].first != sorted[r].second
                        && sorted[l].second != sorted[r].first && sorted[l].second != sorted[r].second)){
            cout << "Four elements : " << sorted[l].first << ", " << sorted[l].second << ", " << sorted[r].first << ", " << sorted[r].second << endl;
            return;
        } else if(sum > x){
            r--;
        } else{
            l++;
        }
    }
    cout << "No 4 elements found!" << endl;
    return;
}


int main(){
    int arr[] = {1, 4, 45, 6, 10, 12};
    int x = 56;
    int n = sizeof(arr)/sizeof(arr[0]);
    int sz = n * (n - 1) / 2;
    struct pairSum *pairSums = new struct pairSum[sz];
    findPairSum(arr, pairSums, n);
    find4Numbers(pairSums, sz, x);
    return 0;
}
Share:

Contact Me

Name

Email *

Message *

Popular Posts