Monday, 24 November 2014

Minimum Edit Distance using Dynamic Programming

The Minimum edit distance between two strings is the minimum number of editing operations required to transform string into other string. Minimum Edit distance use Insertion, Deletion and Substitution operation to transform string into other.

Here I am writing c program to get minimum edit distance between to string using dynamic programming.

Code

public class MinEditDistance
{
public static void main(String[] args)
{
String X="#"+"EXECUTION";
String Y="#"+"INTENTION";
int X_l=X.length();
int Y_l=Y.length();
int D[][]=new int[X_l][Y_l];//Distance Array


//Initialize first row with its index
for (int i = 0; i < X_l; i++)
{
D[i][0]=i;
}
//Initialize first column with its index
for (int j = 0; j < Y_l; j++)
{
D[0][j]=j;
}

for (int i = 1; i < X_l; i++)
{
for (int j = 1; j < Y_l; j++)
{
int min=99999; //reset to infinity
//Get minimum from all
if(X.charAt(i)==Y.charAt(j))
{
min=D[i-1][j-1];
}
if(min > (D[i-1][j-1]+2))
{
min=D[i-1][j-1]+2;
}
if(min > (D[i][j-1]+1))
{
min=D[i][j-1]+1;
}
if(min> (D[i-1][j]+1))
{
min=D[i-1][j]+1;
}

D[i][j]=min;
}
}

//Display Distance Matrix
for (int j = 0; j < Y_l; j++)
{
System.out.print("\t"+Y.charAt(j));
}
System.out.println();
for (int i = 0; i < X_l; i++)
{
System.out.print(X.charAt(i)+"  ");
for (int j = 0; j < Y_l; j++)
{
System.out.print("\t"+D[i][j]);
}
System.out.println();
}

System.out.println("mINIMUM eDIT dISTANCE IS "+D[X_l-1][Y_l-1]);
}

}

Friday, 21 November 2014

Kite cutting problem using Dynamic programming program

Cloth cutting or kite cutting problem is well known problem of DP (Dynamic programming) used in real life.
Here we have sheet of 9x10 and we want to divide it in such a way that we get maximum value.
 Price of subsheets are     2x3=50 and 3x5=100.

Code


public class kite_cutting 
{
public static void main(String strd[]) 
{
int M=9,N=10; //Given SIze of sheet= 9x10
M++; //Make space for 0
N++;
int sheet[][]=new int[M][N];
sheet[2][3]=50; //Already given the value 2x3=50
sheet[3][2]=50;
sheet[3][5]=100;//Already given the value 3x5=50
sheet[5][3]=100;
//initialize first row and column to 0.
for(int i=0;i<M;i++)
sheet[i][0]=0; 
for(int i=0;i<N;i++)
sheet[0][i]=0;
int temp;
//Start DP
for (int i = 0; i < M; i++) 
{
for (int j = 0; j < N; j++) 
{
temp=0;
//Cut the sheet horizontally upto i/2
for (int k = 0; k <= i/2 ; k++) 
{
if(temp<(sheet[k][j]+sheet[i-k][j]))
{
temp=(sheet[k][j]+sheet[i-k][j]);
}
}
//cut the sheet vertically upto j/2
for (int k = 0; k <= j/2 ; k++) 
{
if(temp<(sheet[i][k]+sheet[i][j-k]))
{
temp=(sheet[i][k]+sheet[i][j-k]);
}
}
//store max temp into table
sheet[i][j]=temp;
}
}
//print Table
for (int i = 0; i < M; i++) 
{
System.out.print(i +"||\t");
for (int j = 0; j < N; j++) 
{
System.out.print(sheet[i][j]+"\t");
}
System.out.println();
}
for (int j = 0; j < N; j++)
{
System.out.print("-------------");
}
System.out.print("\n\t");
for (int j = 0; j < N; j++)
{
System.out.print(j+"\t");
}
System.out.println("\n Maximum values we get from sheet is "+sheet[M-1][N-1]);
}

}


Download Source Code in Java
click on above link to get source code







Sunday, 16 November 2014

MultiLevel and Distributed Cache

Multi Level Cache and Distributed cache are widely used today for multiprocessor and cluster applications.

Download PPT


Thank You For Reading

Advanced Cache Concepts: Snoopy and Directory Cache coherence protocol


  • Since all the processors share the same address space, it is possible for more than one processor to cache an address at the same time.(coherence issue).
  • If one processor updates the data item without informing the other processor, inconsistency may result and cause incorrect execution.(consistency issue).
  • To solve this problem we suggest below two cache coherence protocols
                  1. Snoopy protocol

                 2. Directory protocol



Download PPT


Thank You For Reading.

Create bootable Pen drive using command prompt in windows

Create bootable Pen drive using command prompt in windows

Creating bootable pendrive in windows is very easy task, we can do it without installing any third party software. I am writing the steps to create bootable pen drive for any OS.

  1. Attach your pen drive.( Back up all your important data from Pendrive & Format it)
  2. Open Command Prompt.
  3. Type "DISKPART" in command prompt. It will open new windows.

    4. Type "LIST DISK" in newly open window.

   5. Select your target Pen Drive by just type its number. here I am making "disk 2" as bootable drive. 
                       Type "select disk <DISK NO>"
                        Example: select disk 2.

  6. Execute below commands in Sequence.
  1. clean
  2. create partition primary
  3. select partition 1
  4. active
  5. format fs=ntfs (This take upto 15 minutes depends on your drive size)

         6. assign
         7. exit

7. Now simply copy your OS content into that pen drive.

Now Your PENDRIVE work as bootable pen drive..

THANK YOU FOR READING !!!












Saturday, 9 August 2014

C Program to read array from file in C

Read integer array from File in C

this require 2 files:
1) f.txt : which our array is stored
Data:
1 2 3 4 5 6 7 7 8 9
1 2 3 4 5 6 7 7 8 9
1 2 3 4 5 6 7 7 8 9
1 2 3 4 5 6 7 7 8 9
1 2 3 4 5 6 7 7 8 9

2) Programe file : where code resides
Code:
#include<stdio.h>
void main()
{
FILE *f; 
int R=0,C=0,No_OF_COLUMN=0; //Store Row and Column pointer
int i=0,j=0; //Temperory variable
int ARR[100][100]; //Final array where values to be stored
char ch,c[10];

f=fopen("f.txt","r");
while((ch=(char)fgetc(f))!=EOF)
{
if(ch==' ' )
{
c[i]='\0';
ARR[R][C]=atoi(c); // store value into array
i=0;
C++;//Increament Column pointer
if(No_OF_COLUMN<C)
{
No_OF_COLUMN=C;
}
}
else if(ch == '\n')
{
c[i]='\0';
ARR[R][C]=atoi(c); // store value into array
i=0;
C=0; //reset Column pointer
R++; //increament Row pointer
}
else
{
c[i]=ch;
i++;
//printf("%c",ch);
}
}
fclose(f);
for(i=0;i<R;i++)
{
for(j=0;j<No_OF_COLUMN;j++)
{
printf(" %d ",ARR[i][j]);
}
printf("\n");
}
}

Output:

1 2 3 4 5 6 7 7 8 9
1 2 3 4 5 6 7 7 8 9
1 2 3 4 5 6 7 7 8 9
1 2 3 4 5 6 7 7 8 9
1 2 3 4 5 6 7 7 8 9

Monday, 10 February 2014

Difference between “Content-Provider” and “SQLite Database”

Storing your data in a database is one good way to persist your data, but there's a caveat in Android-databases created in Android are visible only to the application that created them. That is to say, a SQLite database created on Android by one application is usable only by that application, not by other applications.
So, if you need to share data between applications, you need to use the content provider model as recommended in Android. This article presents the basics of content providers and how you can implement one.
ContentProvider is a facade -- an API you can implement that exposes databases to other processes. It can be implemented in a way where the data is stored in a SQLite database, but it does not have to be.
Data is provided by the ContentProvider interface, but exposed by the ContentResolver. You could potentially access the implemented ContentProvider via Activity.getContentResolver().getProvider(). However, doing so would couple the requesting class to the implemented ContentProvider
Further to this standardized pattern, the ContentResolver provides several interesting functionalities. For instance, it will notify any content listener that the data has changed. For example, you could listen to any changes occurring within a user's contacts and act upon it

Free GATE Materials


KANODIA MATERIAL for gate aspirants are very useful to get an over all idea of pattern of question they might ask . The kanodia notes given helps to crack gate but do follow standard text books of respective subjects for better ranking

  1. Meterial 1
  2. Meterial 2
  3. Meterial 3
  4. Meterial 4

Online JOb !!! Earn Money Fast

GATE Material for CS

I am sharing very important GATE exam material for my CS students.  Please go through all materials and books

Books:

DBMS Books:

Database System Concepts
by: Abraham Silberschatz, Henry F. Korth, S. Sudarshan
Download   

*Solutions of DBMS by Silberschatz,korth:

DBMS By Raghu Ramakrishna:

*Solutions of Dbms by Raghu Ramakrishna:                   


Database Handbook:

    Download

Complete Reference SQL- James R. Groff
    Download  pdf

 Computer Networks Books:


Computer Networks by Andrew S. Tanenbaum:
Download ebook

*Solution of book by Tanenbaum:
Download Solutionbook 

Data Structures and Algorithm Analysis:

Data Structures and Algorithms:
(Addison-Wesley Series in Computer Science and Information Pr) 
by: Alfred V. Aho, Jeffrey D. Ullman, John E. Hopcroft:
Download Ebook 

Data Structures and Algorithm Analysis in C
by Mark Allen Weiss :
Download Ebook 

Digital Systems:

Notes of Indian Institute of Science - N.J. Rao
Download

Theory of Computation: 

Introduction to Automata Theory, Languages, and Computation
by John E. Hopcroft : 
Download Ebook 

Computer Architecture:

Computer Architecture 
by Patterson_Hennenssy:

Compiler Design:

Compiler Design - Compilers Principles, Techniques and Tools
By A.V. Aho; J.D.Ullman:
  
Download Ebook

Network Security:

Cryptography and Network Security Principles and Practices,
Fourth Edition -William Stallings 
Download

C programming:  

Let us C 
by Yeswant Kanetkar: 
The C Programming Language
fromTheOReillyAnthology:
C Programming FAQs:
Advanced C:

Books for Engineering Maths:

ADVANCED ENGINEERING MATHEMATICS:

Cominatorics:
Download 

Linear Algebra:

Probability:

Logic:

Set Algebra:

Friday, 7 February 2014

Check My Google page Rank

Check my page Rank


Page rank is most important for bussiness to list your website on first page of google.




Check Page Rank of your Web site pages instantly:

Online JOb !!! Earn Money Fast

Wednesday, 29 January 2014

Create table with border in android

Create table with border in android

Table Layout:

According to the Android developer guide, border lines are not displayed for table layouts. However, often you will find the need to do things such as having vertical separators between table cells and borders around table rows.

Give the TableLayout a background color, give the TableRow another background color and set margin to the TableRow. The amount of the margin is the amount of the “border”. Same for each View in the TableRow.

Code:


We can create table with border. Consider the following main.xml file. 


<?xml version="1.0" encoding="utf-8"?>
<TableLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:stretchColumns="*" android:background="#ff0000">
<TableRow 
          android:background="#00ff00" 
          android:layout_margin="2dip">
<TextView 
         android:text="1st Column"
          android:background="#0000ff"
          android:layout_margin="2dip"/>
<TextView 
             android:text="2nd Column" 
            android:background="#0000ff"
            android:layout_margin="2dip"/>

<TextView 
            android:id="@+id/amount" 
            android:background="#0000ff"
            android:layout_margin="2dip" 
            android:text="3rd col"/>
</TableRow>
</TableLayout>

Now the activity code is below:

Code:

package sample.my.tablelayout;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TableRow.LayoutParams;

public class Article_androidActivity extends Activity 
{

  @Override
      public void onCreate(Bundle savedInstanceState) 
       {
            super.onCreate(savedInstanceState);
            this.setContentView(R.layout.main);
        }
}

Monday, 27 January 2014

ListView in android

Insert ListView in Android App

ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query and converts each item result into a view that's placed into the list.

XML file


<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      >
   <ListView
       android:id="@+id/att_listView"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
     >
     </ListView>       
  </LinearLayout>

Java FIle    


import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class Listview extends Activity {

ListView listview;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listview);

//Initialize ListView
listview=(ListView)findViewById(R.id.att_listView);
//ADd Items in List View
ArrayList<String> list=new ArrayList<String>();
list.add("Apple");
list.add("Banana");
list.add("Orange");
list.add("other Fruits");

//Bind list View to Array Adapter to List and Default list View
ArrayAdapter<String> adapter=new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1,list);
//set Adapter to ListView
listview.setAdapter(adapter);
//ListView onClick Listener
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View arg1, int position,long id)
{
// what ever you want to perform
String item=String.valueOf(adapter.getItemAtPosition(position));
Toast.makeText(getApplicationContext(), item, Toast.LENGTH_SHORT).show();
}
});
}
}

Output