Sunday, March 18, 2018

Holography memory - its challenge , implementation and advancement






It was the freshman year of 2006-2007, My friend and I got very much excited about physics , especially Holography and how it can be a thing for the future, its been 10+ years since then and my knowledge about it, still remains limited to the very first & last abstract we wrote about it to pitch the idea of our project interest, sharing today: 

This article provides an overview of holographic memory, a developing three-dimensional data storage system for computers. Holographic memory is a promising technology for data storage as data can be accessed an entire page at a time instead of sequentially. It uses a photosensitive material to record the interference pattern of object wave and reference wave. The nature of photosensitive material is such that the recorded object wave can be reproduced by applying a beam of coherent light to the material that is identical to the reference beam. The LibNO3 photorefractive crystal has been the most mature recording material for holographic memory due to its uniformity, high E-O coefficient, high photon sensitivity and commercial availability. An example of this technology is recording of a hologram. A hologram is a block or sheet of photosensitive material which can theoretically store data equal to one bit per cubic block of the size of the wavelength of light used in writing.  Using light of this wavelength, perfect holographic storage could store 4 gigabits per cubic millimeter. Therefore by using this technology we can store the huge amount of data more compactly. Holographic data storage provides fast access time, as the LASER beams can be moved rapidly without inertia.  When an appropriate photo refractive material is placed at the point of interference, the interference patterns are recorded inside the material. The laser beam is split into reference and signal beam. The data is encoded into the signal beam using a spatial light modulator (SLM) device that translates electronic data (0's and 1's) into an optical pattern of light and dark pixels. The practical example of this type of memory storage is Holographic Versatile Discs(HVD) which can be made rewritable by using reference beam for encoding and decoding by the help of interference and diffraction respectively.It can hold 3.9 terabytes of memory. Holographic memory writes and reads data in parallel in a single flash of lightThe future of holographic memory is very promising. The page access of data that holographic memory creates will provide a window into next generation computing by adding another dimension to stored data. Finding holograms in personal computers might be a bit longer off, however. The large cost of high-tech optical equipment would make small-scale systems implemented with holographic memory impractical. Holographic memory will most likely be used in next generation super computers where cost is not as much of an issue.


Digital Imaging - "What to think of"



 We thought to implement something which can perceive human eyes , but then the technological race lead that very thing "Camera" to go beyond just perceiving. Digital Imaging field is very vast and fast developing, its been incredible part of our daily activities of capturing images and videos.

Lets see what is it take to get a quality image and video for us:

1) Imaging Light
2) Imaging Sensors
3) Imaging Device
4) Image Processing Pipeline
5) Imaging Framework and Application
6) Imaging Quality Details, Ideas, Perspective and Sharing
7) Vision, Computation and Analysis

to be continued ...

Sunday, February 25, 2018

Add two numbers represented as linked List


Add two numbers represented as linked List :

Input: (7 -> 2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 8 -> 0 -> 7

/*
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
         if (!l1)
             return l2;
         if (!l2)
             return l1;
        int sum = 0, carry = 0;

        ListNode* head1 = reverse(l1);
        ListNode* head2 = reverse(l2);
        ListNode* result = NULL;
        ListNode* temp = NULL;   
        while (head1 || head2 || carry) {
            int v1 = !head1 ? 0 : head1->val;
            int v2 = !head2 ? 0 : head2->val;
            sum = v1 + v2;
            temp = new ListNode((sum + carry) % 10);
            temp->next = result;
            result = temp;
            carry = (sum + carry) / 10;
            head1 = !head1? NULL : head1->next;
            head2 = !head2? NULL : head2->next;
        }
        return result;
    }
   
    ListNode* reverse(ListNode* head) {
        if (!head) return NULL;
        ListNode* newHead = NULL;
        ListNode* next = NULL;
        while (head) {
            next = head->next;
            head->next = newHead;
            newHead = head;
            head = next;
        }
        return newHead;
    }
};

Friday, January 5, 2018

Given a binary tree, check whether it is a mirror of itself/symmetric


Below binary tree [1,2,2,3,4,4,3] is symmetric:
    1
   / \
  2   2
 / \ / \
3  4 4  3

/**
 * 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:
    bool isSymmetric(TreeNode* root) {
         TreeNode* left, *right;
         if (!root)
            return true;
       
         queue<TreeNode*>q1, q2;
         q1.push(root->left);
         q2.push(root->right);
        
        while (!q1.empty() && !q2.empty()) {
            left = q1.front();
            q1.pop();
            right = q2.front();
            q2.pop();
            if (!left && !right)
              continue;
            if (!left || !right)
                return false;
            if (left->val != right->val)
                return false;
            q1.push(left->left);
            q1.push(left->right);
            q2.push(right->right);
            q2.push(right->left); 
        }
        return true;
    }
};


======================================================================================

/**
 * 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:
    bool isSymmetric(TreeNode* root) {
         if (!root)
            return true;
         if (!root->left && !root->right)
             return true;
         if (!root->left || !root->right)
            return false;
         queue<TreeNode*>q1, q2;
         q1.push(root->left);
         q2.push(root->right);
       
    }

};

Saturday, December 30, 2017

Determine the perimeter of the island

Given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells). The island doesn't have "lakes" (water inside that isn't connected to the water around the island). One cell is a square with side length 1. The grid is rectangular, width and height don't exceed 100. Determine the perimeter of the island.

Example:

[[0,1,0,0],
 [1,1,1,0],
 [0,1,0,0],
 [1,1,0,0]]

Answer: 16
Explanation: The perimeter is the 16 yellow stripes in the image below:
 



 class Solution {
public:
    int islandPerimeter(vector<vector<int>>& grid) {
        int row = grid.size();
        int col = grid[0].size();
        if (grid.empty()) return 0;
        int sum = 0, sr = 0, sc = 0;
        for (int i =0; i < row; i ++) {
            for (int j =0; j < col; j++) {
                if (grid[i][j] == 1) {
                    sr = i;
                    sc = j;
                    break;
                }              
            }
        }
      
        sum += addPerimeter(grid, sr, sc, row, col);
        return sum;
    }
  
    int addPerimeter (vector<vector<int>>&grid, int i , int j, int row, int col) {
        if (i < 0 || i >= row || j < 0 || j >= col || grid[i][j] == 0)
            return 1;
        if (grid[i][j] == -1)
            return 0;
      
        grid[i][j] = -1;
      
        return addPerimeter(grid, i+1, j, row, col) +
            addPerimeter(grid, i-1, j, row, col) +
            addPerimeter(grid, i, j+1, row, col) +
            addPerimeter(grid, i, j-1, row, col);   
      
    }
  
};

Perform Flood Fill for a given 2D image/matrix using DFS

solution for Flood fill question using DFS approach :

Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image.
To perform a "flood fill", consider the starting pixel, plus any pixels connected 4-directionally to the starting pixel of the same color as the starting pixel, plus any pixels connected 4-directionally to those pixels (also with the same color as the starting pixel), and so on. Replace the color of all of the aforementioned pixels with the newColor. return the modified image.
Example :
Input: 
image = [[1,1,1],[1,1,0],[1,0,1]]
sr = 1, sc = 1, newColor = 3
Output: [[3,3,3],[3,3,0],[3,0,1]]
Explanation: 
From the center of the image (with position (sr, sc) = (1, 1)), all pixels connected 
by a path of the same color as the starting pixel are colored with the new color.
Note the bottom corner is not colored 3, because it is not 4-directionally connected
to the starting pixel.

class Solution {
public:
    vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int newColor) {
        int row = image.size();
        int col = image[0].size();
        if (sr < 0 || sr >= row || sc < 0 || sc >=col )
            return image;
        int m = image[sr][sc];
        fillcolor(image, sr , sc , row,col, m, newColor);
        return image;
    }
   
    void fillcolor(vector<vector<int>>& image, int r, int c , int row, int col, int m, int newColor) {
        if (r < 0 || r >= row || c < 0 || c >= col || (image[r][c] != m) || (image[r][c] == newColor))
            return;
        image[r][c] = newColor;
        fillcolor(image, r+1, c, row, col, m, newColor);
        fillcolor(image, r-1, c, row, col, m,newColor);
        fillcolor(image, r, c+1, row, col, m,newColor);
        fillcolor(image, r, c-1, row, col, m,newColor);
       
    }
};

Thursday, December 14, 2017

Pascal's Triangle


Given numRows, generate the first numRows of Pascal's triangle.
For example, given numRows = 4,
Return
[    [1],
    [1,1],
   [1,2,1],
  [1,3,3,1] ]

C program : 

int** generate(int numRows, int** columnSizes) {
    int i, j;
    int numColumns = 0;
    *columnSizes = malloc(numRows*sizeof(int));
    int** result = (int**)malloc(numRows*sizeof(int*));
   
    for (i = 0; i < numRows; i++)
        result[i] = (int*)malloc((i+1)*sizeof(int));
   
    for (i = 0; i < numRows; i++) {
       
        result[i][0] = result[i][i] = 1;
        for (j = 0; j < i; j++) {
         result[i][j] = result[i-1][j-1] + result[i-1][j];
        }
        numColumns++;
        *(*columnSizes+i) = numColumns;
    }
    return result;
}


C++ program : 

class Solution {
public:
    vector<vector<int>> generate(int numRows) {
        vector<vector<int>>result(numRows);
        for (int i = 0; i < numRows; i++) {
            result[i].resize(i+1);
            result[i][0] = result[i][i] = 1;
            for (int j = 0; j < i ; j++) {
                result[i][j] = result[i-1][j-1] + result[i-1][j];
            }
        }
       
        return result;
    }
};