tag:blogger.com,1999:blog-25515012380361386602024-03-29T04:02:58.635-07:00Code Plus Tech TalkDownload Source Codes for mini projects in C, C++, Java, Android, Python and Lab reports in engineering levelsJhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.comBlogger21125tag:blogger.com,1999:blog-2551501238036138660.post-9635266089240510612013-07-29T05:42:00.002-07:002013-08-15T05:05:41.684-07:00Anomaly Detection using Oracle R Enterprise (ORE) | SVM for Anomaly Detection<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
R is an open source scripting language and environment for statistical computing, data analysis & graphics.R provides an integrated suite of software facilities for data manipulation, calculation and graphical display- it's an integrated environment. Around 2 million users in the world are widely using R especially by corporate analysts & data scientists.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Anomaly/Outlier detection has wide applications. It can be used in fraud detection, for example, by detecting unusual usage of credit cards or telecommunication services. In addition, it is useful in customized marketing for identifying the spending behavior of customers with extremely low or extremely high incomes, or in medical analysis for finding unusual responses to various medical treatments.</div>
<div style="text-align: justify;">
</div>
<a name='more'></a><br />
<br />
<div style="text-align: justify;">
Oracle R Enterprise is a flavor of R that enhances the open-source R for analyzing and manipulating data in Oracle database through R, transparently. It helps to use in-database predictive analytics algorithms seamlessly through R. </div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
One of the classification algorithms implemented in ORE is Support Vector Machines. In ORE, the interface function <i>ore.odmSVM </i>is used to train a support vector machine using Oracle Data Mining. It can be used to</div>
<div style="text-align: justify;">
carry out general regression, classification, and anomaly detection. The SVM algorithm automatically handles missing value treatment and the transformation of categorical data, but normalization and outlier detection must be handled manually. So, we need to do feature normalization before feeding the training data to the model. The function <i>predict</i> computes predictions based on the input data and model.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
An example for anomaly detection is shown based on the existing dataset <i>'mtcars'</i> available in R documentation:</div>
<div style="text-align: justify;">
<br /></div>
<b>DATA SET: </b>Motor Trend Car Road Tests<br />
<div style="text-align: justify;">
The data was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973–74 models).</div>
<div style="text-align: justify;">
<b>Features:</b></div>
[1]<span class="Apple-tab-span" style="white-space: pre;"> </span> mpg<span class="Apple-tab-span" style="white-space: pre;"> </span> Miles/(US) gallon<br />
[2]<span class="Apple-tab-span" style="white-space: pre;"> </span> cyl<span class="Apple-tab-span" style="white-space: pre;"> </span> Number of cylinders<br />
[3]<span class="Apple-tab-span" style="white-space: pre;"> </span> disp<span class="Apple-tab-span" style="white-space: pre;"> </span> Displacement (cu.in.)<br />
[4]<span class="Apple-tab-span" style="white-space: pre;"> </span> hp<span class="Apple-tab-span" style="white-space: pre;"> </span> Gross horsepower<br />
[5]<span class="Apple-tab-span" style="white-space: pre;"> </span> drat<span class="Apple-tab-span" style="white-space: pre;"> </span> Rear axle ratio<br />
[6]<span class="Apple-tab-span" style="white-space: pre;"> </span> wt<span class="Apple-tab-span" style="white-space: pre;"> </span> Weight (lb/1000)<br />
[7]<span class="Apple-tab-span" style="white-space: pre;"> </span> qsec<span class="Apple-tab-span" style="white-space: pre;"> </span> 1/4 mile time<br />
[8]<span class="Apple-tab-span" style="white-space: pre;"> </span> vs<span class="Apple-tab-span" style="white-space: pre;"> </span> V/S<br />
[9]<span class="Apple-tab-span" style="white-space: pre;"> </span> am<span class="Apple-tab-span" style="white-space: pre;"> </span> Transmission (0 = automatic, 1 = manual)<br />
[10]<span class="Apple-tab-span" style="white-space: pre;"> </span> gear<span class="Apple-tab-span" style="white-space: pre;"> </span> Number of forward gears<br />
[11]<span class="Apple-tab-span" style="white-space: pre;"> </span> carb<span class="Apple-tab-span" style="white-space: pre;"> </span> Number of carburetors<br />
<br />
<div style="text-align: justify;">
For anomaly detection, we first build a classification model based on support vector machine and then use the anomaly detection approaches. We've used <i>gear, no. of cylinders, V/S</i> ratio as the features for building the anomaly detection model.</div>
<div style="text-align: justify;">
<br /></div>
<b>R Script:</b></div>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-oLd2rs5-zQ1xhNWUoQzgaaMA16uy4OS5elvO33EcdsimT8V_nAweevOIGgSIKJrszvY_VZMsc76vWttFdR8gTmqKaEbJgs6BiaCQ2WU_sUqEjmr_nhjCsUwUAUBNsl9JCShivA7IuVYM/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> library(ORE)
if (!ore.is.connected())
ore.connect("Database_name", "SID","192.168.50.19", "password",port=1521, all=TRUE)
m <- mtcars
m$gear <- as.factor(m$gear)
m$cyl <- as.factor(m$cyl)
m$vs <- as.factor(m$vs)
m$ID <- 1:nrow(m)
MTCARS <- ore.push(m)
svm.mod <- ore.odmSVM(gear ~ .-ID, MTCARS,"classification")
summary(svm.mod)
coef(svm.mod)
svm.res <- predict (svm.mod, MTCARS,"gear")
with(svm.res, table(gear,PREDICTION)) # generate confusion matrix
</code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-oLd2rs5-zQ1xhNWUoQzgaaMA16uy4OS5elvO33EcdsimT8V_nAweevOIGgSIKJrszvY_VZMsc76vWttFdR8gTmqKaEbJgs6BiaCQ2WU_sUqEjmr_nhjCsUwUAUBNsl9JCShivA7IuVYM/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> svm.mod <- ore.odmSVM(~ .-ID, MTCARS,"anomaly.detection")
summary(svm.mod)
svm.res <- predict (svm.mod, MTCARS, "ID")
head(svm.res)
table(svm.res$PREDICTION) </code></pre>
<br />
<div style="text-align: justify;">
Based on the above designed model, we can predict the anomalous design of the cars. The result stored in the <i>svm.res </i>can be used to observe the class of each of the test set. The <i>table </i>function returns the confusion matrix from which we can analyze the accuracy of the algorithm for our particular data set. To present the result obtained through the above model in the Oracle Business Intelligence Enterprise Edition (OBIEE), we can <i>push </i>the above result into the Oracle database and metadata repository (RPD) can be built accordingly.</div>
<div style="text-align: justify;">
<br /></div>
---<br />
<i>(Queries are always welcomed !!)</i><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com2tag:blogger.com,1999:blog-2551501238036138660.post-56749356600445356462013-06-19T09:24:00.000-07:002013-06-19T09:24:42.979-07:00Random Numbers Generation & Chi-Squared Test for their Uniformity in C++<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
Continuous uniformly distributed random numbers means the set of random numbers where probability of any number in any integral within a certain range of values is proportional to the ratio of the interval size to the range. The generated random numbers require to be independent & uniform in distribution. There are many different methods to generate the random numbers. </div>
<div style="text-align: justify;">
They are: </div>
<div style="text-align: justify;">
</div>
<ul>
<li>Random numbers from table. </li>
<li>From hardwired device. </li>
<li>Using pseudo Number generation. </li>
</ul>
<br />
<div>
In linear congruential method, we use one initial number (r<sub>0 </sub>called seed) and few constants. Using the seed and the formula, </div>
<div>
<div>
<i><b>r<sub>i+1</sub> = (r<sub>i</sub> ×a + b) (modulo m) </b></i></div>
<div>
<br />
<a name='more'></a><br /></div>
<div>
Where ‘a’ and ‘b’ are constant and m is that number which is the upper limit of required random </div>
<div>
number. This finds the number in the closed interval [0, m-1].<br />
<br />
The chi-squared test uses the following sample statistics for uniformity test of random numbers:<br />
<br />
X<sup>2</sup> = SUM [ (O<sub>i</sub> - E<sub>i</sub> )<sup>2</sup> / E<sub>i</sub> ], for i=1 to N<br />
Where,<br />
Ei = N/n is expected number and<br />
Where N is the Number of observations and n is the Number of Classes.<br />
Oi = is the observed number<br />
<br />
For given confidence level and degree of freedom, acceptance value is found out from table. If<br />
the calculated value is smaller than the tabulated one, the numbers are accepted for their uniformity of distribution.<br />
<br />
Here, we present the implementation for generation of random numbers using seed = 1, a = 13, b = 1 and m = 19 in C++:<br />
<br /></div>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-oLd2rs5-zQ1xhNWUoQzgaaMA16uy4OS5elvO33EcdsimT8V_nAweevOIGgSIKJrszvY_VZMsc76vWttFdR8gTmqKaEbJgs6BiaCQ2WU_sUqEjmr_nhjCsUwUAUBNsl9JCShivA7IuVYM/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">//Random Number Generation, @Author:Jivan Nepali, Kathmandu, Nepal </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-oLd2rs5-zQ1xhNWUoQzgaaMA16uy4OS5elvO33EcdsimT8V_nAweevOIGgSIKJrszvY_VZMsc76vWttFdR8gTmqKaEbJgs6BiaCQ2WU_sUqEjmr_nhjCsUwUAUBNsl9JCShivA7IuVYM/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int a = 13,b = 1,m = 19,O_freq[20],n = 3,N,E_freq;
int rand[200];
float chi_squared_calc = 0,chi_squared_tab = 5.99,temp_sqr;
rand[1] = 1;
int i,j;
int dobreak=0;
cout<<"\n::GENERATED RANDOM NUMBERS::\n\n";
cout<<"r0\t"<<rand[1]<<"\n";
for (i = 2;; i++)
{
rand[i] = (a*rand[i-1]+b)%m;
for ( j=1;j<=i-1;j++)
{
if(rand[j]==rand[i])
{
dobreak = 1;
}
if(dobreak == 1)
break;
}
if(dobreak == 1)
break;
else
cout<<"r"<<i-1<<"\t"<<rand[i]<<"\n";
}
N = i;
E_freq = N/n;
for(j=1;j<=n;j++)
O_freq[j]=0;
for(j = 1; j <= N; j++){
if(rand[j]>=0 && rand[j]<2*n)
O_freq[1]++;
if(rand[j]>=2*n && rand[j]<4*n)
O_freq[2]++;
if(rand[j]>=4*n && rand[j]<=6*n)
O_freq[3]++;
}
cout<<"\nCOMPUTATION OF CHI-SQUARED\n";
cout<<"\nInterval\tO_i\tE_i\t(O_i-E_i)^2/E_i\n";
cout<<"---------------------------------------------\n";
for(j=1;j<=n;j++){
temp_sqr = pow((O_freq[j]-E_freq),2)/(float)E_freq;
chi_squared_calc += temp_sqr;
cout<<(j-1)*2*n<<" <= r <"<<j*2*n<<"\t"<<O_freq[j]<<"\t"<<E_freq<<"\t"<<temp_sqr<<"\n";
}
cout<<"---------------------------------------------\n";
cout<<"\nCalculated value of chi-squared = "<<chi_squared_calc<<"\n";
cout<<"\nDegree of freedom = "<<n-1<<"\talpha = 0.05%\tTabulated value of chi-squared = 5.99"<<"\n";
cout<<"\n\nConclusion:\n";
if(chi_squared_calc<=chi_squared_tab)
cout<<"The UNIFORM DISTRIBUTION of random numbers ISNOT rejected.\n\n\n";
else
cout<<"The UNIFORM DISTRIBUTION of random numbers IS rejected.\n\n\n";
return 0;
}
</code></pre>
</div>
<br />
Enjoy coding!!!</div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com1tag:blogger.com,1999:blog-2551501238036138660.post-84836926278780772692013-06-12T20:21:00.000-07:002013-06-12T20:21:20.199-07:00Determinant Calculation of Nth Order Square Matrix| Cramer's Rule Implementation in C<div dir="ltr" style="text-align: left;" trbidi="on">
Determinant calculation of a square matrix is widely used in solving many applied Mathematics problems. Some of them are while solving a set of linear equations using Cramer's rule (iff they have unique solutions), calculation of inverse matrix, Eigen values/ Eigen vectors problem and so on.<br />
<br />
The determinant of a square matrix A∈R<sup>n×n</sup> is the real number det(A) defined as follows:<br />
<br />
det(A) = SUM<sub>perm </sub>[sign(ν1,ν2,...,νn)a1ν1a2ν2...anνn]<br />
.<br />
<a name='more'></a><br />
The summation is over all n! permutations(ν1,ν2,...,νn) of the integers 1,2,...,n, and sign(ν1,ν2,...,νn) = +1 or−1 depending on whether the n-tuple (ν1,ν2,...,νn) is an even or odd permutation of (1,2,...,n), respectively. An even (odd) permutation is obtained by an even (odd) number of exchanges of two adjacent elements in the array(1,2,...,n). A matrix A∈R<sup>n×n</sup> is said to be non-singular when its determinant<br />
det(A) is nonzero.<br />
Here, we've presented the determinant calculator of a square matrix in C:<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-oLd2rs5-zQ1xhNWUoQzgaaMA16uy4OS5elvO33EcdsimT8V_nAweevOIGgSIKJrszvY_VZMsc76vWttFdR8gTmqKaEbJgs6BiaCQ2WU_sUqEjmr_nhjCsUwUAUBNsl9JCShivA7IuVYM/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> #include<stdio.h>
void readmatrix(int m[][8], int s){
int i,j;
printf("Enter elements of the matrix: \n");
for(i=0;i<s;i++)
for(j=0;j<s;j++)
scanf("%d", &m[i][j]);
}
int determinant(int m[][8],int s){
int i, j, k, det,cramermatrix[15][15], product, plussum = 0, minussum = 0;
if (s == 2)
det = m[0][0]*m[1][1] - m[0][1]*m[1][0];
else
{
for(i=0;i<s;i++)
for(j=0;j<s;j++)
cramermatrix[i][j] = m[i][j];
for(i=0;i<s;i++)
for(j=s;j<(2*s-1);j++)
cramermatrix[i][j] = m[i][j-s];
for(i=0;i<s;i++){
product = 1;
for(j = 0; j <s; j++)
product = product*cramermatrix[j][i+j];
plussum += product;
}
for(i=s-1;i<(2*s-1);i++){
product = 1;
for(j = 0; j <s; j++)
product = product*cramermatrix[j][i-j];
minussum += product;
}
det = plussum - minussum;
}
return det;
}
int main(){
int matrix[8][8], det, size;
printf("Enter the order of square matrix (n*n) e.g. 4 : ");
scanf("%d", &size);
readmatrix(matrix, size);
det = determinant(matrix, size);
printf("\n The determinant of the given square matrix is\n det = %d\n\n", det);
return 0;
}
</code></pre>
<br />
Sample Output:<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-oLd2rs5-zQ1xhNWUoQzgaaMA16uy4OS5elvO33EcdsimT8V_nAweevOIGgSIKJrszvY_VZMsc76vWttFdR8gTmqKaEbJgs6BiaCQ2WU_sUqEjmr_nhjCsUwUAUBNsl9JCShivA7IuVYM/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> Enter the order of square matrix (n*n) e.g. 4: 3
Enter the elements of the matrix:
3 4 5
0 1 1
0 1 -1
Determinant of the given matrix is
det = -6
</code></pre>
<br />
Enjoy coding !!!<br />
<br />
<br /></div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com2tag:blogger.com,1999:blog-2551501238036138660.post-11383109825423020102013-06-08T06:30:00.001-07:002013-06-08T06:31:48.254-07:00Autodesk AutoCAD 2010 is Already Installed| Problem Re-installing AutoCAD 2010| Solution<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
After facing some of the troubles and uninstalling the AutoDesk AutoCAD 2010, when you try to re-install the AutoCAD, you may often have to go through this problem. This is actually the problem which remained after uninstalling the AutoCAD. Before trying to provide the solution, I would like to suggest to clean up your computer system using some clean up tools such as Windows Installer Clean UP Utility, CCleaner etc. after you uninstall a software.</div>
<div style="text-align: justify;">
</div>
<a name='more'></a><br />
<br />
<div style="text-align: justify;">
In this case, please check the following areas in the registry <a href="http://codeplustech.blogspot.com/2013/06/cddvd-drive-not-found-problem-cddvd.html">[how to go to registry]</a> and remove the keys, after backing up the registry (optional):</div>
<div style="text-align: justify;">
</div>
<ol>
<li> Case where an aborted attempt to install the product and the reinstall attempt is blocked saying that the product is already installed. Browse to the following locations in the registry:</li>
</ol>
<br />
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
</div>
<ul>
<li><b><i>HKEY_CLASSES_ROOT\Installer\Products</i></b></li>
<li><b><i>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr?entVersion\Installer\UserData\S-1-5-18\Products</i></b></li>
<li><b><i>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr?entVersion\Uninstall</i></b></li>
</ul>
<br />
<div style="text-align: justify;">
I usually search for the product name string in these locations and remove any keys from the GUID level. Backup the registry first, of course, prior to any editing. This is the standard solution.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
2. If the install log shows that the install initialization is detecting the existence of a .mst file and cannot proceed because the .mst file is not found in the path listed, then look in the first key above for the string of the .mst file name and delete that key from the GUID level.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
3. If the log fails due to the custom action, CheckForACADExistance, then browse to the INSTALLDIR, usually C:\Program Files\<Product Name> and remove the <Product Name> directory.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Then, launch the install again.</div>
</div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com6tag:blogger.com,1999:blog-2551501238036138660.post-65572884296404602752013-06-08T06:18:00.000-07:002013-06-08T06:21:30.874-07:00CD/DVD Drive not Found Problem| CD/DVD Drive is not Detected Problem| Windows 7 Problem Solution<div dir="ltr" style="text-align: left;" trbidi="on">
In windows 7, if you are facing the optical drives not detected/ not found problem even if it is visible in BIOS and using the standard driver, then you can try out the following options. The standard solution that worked in my desktop is as follows:<br />
<br />
<br />
<ul style="text-align: left;">
<li>Press Win key and type <i>regedit.exe, </i>a new window- Registry Editor will open</li>
<li>After that, navigate to the following path from the left pane:</li>
</ul>
<span style="background-color: white;"></span><br />
<a name='more'></a><br />
<br />
<div style="text-align: justify;">
<span style="background-color: white;"><i><b>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E965-E325- 11CE-BFC1-08002BE10318}</b></i></span></div>
<span style="background-color: white;">
</span>
<br />
<div style="text-align: justify;">
<ul><span style="background-color: white;">
<li><b><i><span style="font-style: normal; font-weight: normal; text-align: left;">Then, delete both </span><span style="font-weight: normal; text-align: left;">UpperFilters</span><span style="font-style: normal; font-weight: normal; text-align: left;"> and </span><span style="font-weight: normal; text-align: left;">LowerFilters</span><span style="font-style: normal; font-weight: normal; text-align: left;"> in the right-hand pane (UpperFilters.bak and LowerFilters.bak entries can be ignored).</span></i></b></li>
<li><b><i><span style="font-style: normal; font-weight: normal; text-align: left;">Exit from the Registry Editor, and Restart your computer, you'll find problem solved!!!</span></i></b></li>
</span></ul>
<div style="text-align: left;">
<span style="background-color: white;">The following is the image shown after deleting the filters as indicated above:</span><br />
<span style="background-color: white;"><br /></span></div>
<div style="text-align: left;">
<div class="separator" style="clear: both; text-align: center;">
<span style="background-color: white;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRN7T5ROwrXDbPxR0J45_keT9YKRV_nlO9-Ht0BPLFHgikVKE1qF_jMmyaCWFev1evvqq_TJJzRJzmcrgqAkVkOtLKqidUm6oeRfNPL6MElQBu7ZiMvent-I0UaQqQJ3bMpewcVydcW3ly/s1600/Capture.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="280" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRN7T5ROwrXDbPxR0J45_keT9YKRV_nlO9-Ht0BPLFHgikVKE1qF_jMmyaCWFev1evvqq_TJJzRJzmcrgqAkVkOtLKqidUm6oeRfNPL6MElQBu7ZiMvent-I0UaQqQJ3bMpewcVydcW3ly/s640/Capture.PNG" width="640" /></a></span></div>
<span style="background-color: white;"><br /></span></div>
</div>
<span style="background-color: white;">
</span></div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com1tag:blogger.com,1999:blog-2551501238036138660.post-4881069445409262502013-06-07T11:42:00.000-07:002013-06-07T13:17:57.183-07:00Huffman Algorithm Implementation in C| Huffman Encoding| Huffman Algorithm Example<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
Huffman Algorithm is an encoding technique for symbols where most frequently occuring symbols are represented with short length bit strings and least frequently occuring symbols are represented with long bit strings.<br />
<br /></div>
<div style="text-align: justify;">
This algorithm is widely used as the fundamental encoding algorithm in compressing audio and image files.</div>
<div style="text-align: justify;">
</div>
<a name='more'></a><br />
<h4 style="text-align: left;">
Algorithm (Pseudo-code)</h4>
<div>
<i>Huffman</i> (C: symbols ai with freuencies wi; i=1,2,3,.....n)</div>
<div>
F: Forest of n rooted trees, each consisting of the single vertex ai and assigned weight wi in ascending order of wi</div>
<div>
<i>while</i> F is not a tree</div>
<div>
<i>begin</i> </div>
<div>
<ul style="text-align: left;">
<li><span style="text-align: justify;">Replace the rooted trees T and T' of least weight from F with w(T) >= w(T') with a tree having a new root that has T as its left subtree and T' as its right subtree</span></li>
<li>Label new edge to T with 0 and new edge to T' with 1</li>
<li>Assign w(T)+w(T') as weight of new tree</li>
</ul>
</div>
<div>
<i>end</i></div>
<div>
<br /></div>
<div>
<b>Example:</b></div>
<div>
Use Huffman Algorithm to encode the following symbols:</div>
<div>
<u>Symbol</u> <u>Frequency</u></div>
<div>
A 0.5</div>
<div>
B 0.2</div>
<div>
C 0.2</div>
<div>
D 0.1</div>
<div>
<i><br /></i></div>
<div>
After running the algorithm, we'll get the following encodings:</div>
<div>
<div>
<u>Symbol</u> <u>Code</u></div>
<div>
A 0</div>
<div>
B 100</div>
<div>
C 11</div>
<div>
D 101</div>
</div>
<div>
<br /></div>
<div>
<a href="http://codeplustech.blogspot.com/p/huffman-algorithm-implementation-in-c.html">Implementation of Huffman Algorithm in C</a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
</div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com0tag:blogger.com,1999:blog-2551501238036138660.post-62146789739429079642013-05-29T08:35:00.001-07:002013-06-07T07:34:50.847-07:00Solution of Ordinary Differential Equation using Runge-Kutta Method | RK4 method for ODE Solution in C<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
In numerical analysis, the Runge–Kutta methods are an important family of implicit and explicit iterative methods for the approximation of solutions of ordinary differential equations. These techniques were developed around 1900 by the German mathematicians C. Runge and M. W. Kutta.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
There are many variants of the Runge-Kutta method, but the most widely used one is the following known as RK-4 method: </div>
<div style="text-align: justify;">
Given </div>
<div style="text-align: justify;">
y' = f(x,y) </div>
<div style="text-align: justify;">
y(xn) = yn </div>
<div style="text-align: justify;">
we compute in turn </div>
<div style="text-align: justify;">
k1 = hf(xn,yn) </div>
<div style="text-align: justify;">
k 2 = hf (xn+h/2,yn+k1/2)</div>
<div style="text-align: justify;">
k3 = hf (xn+h/2,yn+k2/2)</div>
<div style="text-align: justify;">
k4 = hf(xn + h, yn + k3) </div>
<div style="text-align: justify;">
yn+1 = yn + (k1 + 2*k2 + 2*k3 + k4 )/6</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
This algorithm can be implemented using the following source code in C:</div>
<div style="text-align: justify;">
<br />
<a name='more'></a><br /></div>
<div style="text-align: justify;">
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-oLd2rs5-zQ1xhNWUoQzgaaMA16uy4OS5elvO33EcdsimT8V_nAweevOIGgSIKJrszvY_VZMsc76vWttFdR8gTmqKaEbJgs6BiaCQ2WU_sUqEjmr_nhjCsUwUAUBNsl9JCShivA7IuVYM/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">//RK4 Method to solve ODI, @author:Jivan Nepali, Kathmandu</code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-oLd2rs5-zQ1xhNWUoQzgaaMA16uy4OS5elvO33EcdsimT8V_nAweevOIGgSIKJrszvY_VZMsc76vWttFdR8gTmqKaEbJgs6BiaCQ2WU_sUqEjmr_nhjCsUwUAUBNsl9JCShivA7IuVYM/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> #include<stdio.h>
#include<math.h>
float f(float x ,float y)
{
return (y*y-x*x)/((y*y+x*x));
}
int main()
{
float x0,y0,x1,y1,h,k1,k2,k3,k4,k,xn ,x,y;
printf("Enter the values of x0 , y0 ,h ,xn :\n");
scanf("%f %f %f %f" ,&x0,&y0,&h,&xn);
x=x0;
y=y0;
while(1)
{
if(x==xn)
break;
k1=h*f(x,y);
k2=h*f(x+h/2,y+k1/2);
k3=h*f(x+h/2,k2/2+y);
k4=h*f(x+h,y+k3);
k=(k1+(k2+k3)*2+k4)/6;
x+=h;
y+=k;
printf("value of x =%7.5f Value of y =%7.5f\n",x,y);
}
return 0;
} </code></pre>
</div>
<br />
Enjoy Coding!!!!</div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com0tag:blogger.com,1999:blog-2551501238036138660.post-83543185432518396512013-05-24T09:34:00.002-07:002013-05-24T09:37:10.991-07:00Gauss Jordan Method Implementation with C Source Code<div dir="ltr" style="text-align: left;" trbidi="on">
In linear algebra, Gaussian Jordan method is an algorithm for solving systems of linear equations. It is usually understood as a sequence of operations performed on the associated matrix of coefficients. This method can also be used to find the rank of a matrix, to calculate the determinant of a matrix, and to calculate the inverse of an invertible square matrix.<br />
<br />
We can implement this method in C using the following source code:<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-oLd2rs5-zQ1xhNWUoQzgaaMA16uy4OS5elvO33EcdsimT8V_nAweevOIGgSIKJrszvY_VZMsc76vWttFdR8gTmqKaEbJgs6BiaCQ2WU_sUqEjmr_nhjCsUwUAUBNsl9JCShivA7IuVYM/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">//Implementation of Gauss Jordan Method, @author: <a class="g-profile" href="http://plus.google.com/107360838856177439041" target="_blank">+Jivan Nepali</a>, @URL: <a href="http://codeplustech.blogspot.com/2013/05/gauss-jordan-method-implementation-with.html">codeplustech</a></code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-oLd2rs5-zQ1xhNWUoQzgaaMA16uy4OS5elvO33EcdsimT8V_nAweevOIGgSIKJrszvY_VZMsc76vWttFdR8gTmqKaEbJgs6BiaCQ2WU_sUqEjmr_nhjCsUwUAUBNsl9JCShivA7IuVYM/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> #include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define Max 10
int main()
{
float a[Max][Max+1],t,det=1;
int i,j,k,N;
printf("Enter the number of unknowwns : ");
scanf("%d",&N);
<a name='more'></a> </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-oLd2rs5-zQ1xhNWUoQzgaaMA16uy4OS5elvO33EcdsimT8V_nAweevOIGgSIKJrszvY_VZMsc76vWttFdR8gTmqKaEbJgs6BiaCQ2WU_sUqEjmr_nhjCsUwUAUBNsl9JCShivA7IuVYM/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">printf("\nEnter the elements of the augmented matrix :\n");
for(i=0;i<N;i++)
for(j=0;j<N+1;j++)
scanf("%f",&a[i][j]);
for(i=0;i<N;i++)
for(j=0;j<N;j++)
if(i!=j)
{
t=a[j][i]/a[i][i];
for(k=0;k<N+1;k++)
a[j][k]-=a[i][k]*t;
}
for(i=0;i<N;i++)
det*=a[i][i];
printf("\nDeterminant = %.4f\n",det);
if(det==0){
printf("\nThe matrix is singular .\n");
exit(1);
}
printf("\nThe Gauss-Jordan Matrix is :\n\n");
for(i=0;i<N;i++)
{
for(j=0;j<N+1;j++)
printf("%.4f ",a[i][j]);
printf("\n");
}
printf("\nThe solution is :\n\n");
for(i=0;i<N;i++)
printf("x[ %d]=%.4f\n",i+1,a[i][N]/a[i][i]);
getch();
return 0;
}
</code></pre>
<br />
Enjoy coding!!!<br />
<br /></div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com2tag:blogger.com,1999:blog-2551501238036138660.post-87471764872791151552013-05-23T04:34:00.001-07:002013-05-23T04:45:59.820-07:00Modeling & Simulation of Chemical Reaction | Continuous System Simulation | C++ Implementation<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="text-align: justify;">Chemical reactions exhibit dynamic equilibrium, which means that a combination reaction is also accomplished by the reverse process of decomposition reaction. At the steady state the rates of the forward and the backward reaction is same.</span><br />
<div style="text-align: justify;">
<br /></div>
<span style="text-align: justify;">In addition to the forward reaction where Ch1 and Ch2 react to produce Ch3, there may also be backward reaction, where by, Ch3 decomposes back into Ch1 and Ch2. Let the rate of formation of Ch3 be proportional to the product of the amounts Ch1 and Ch2 present in the mixture and let the rate of decomposition of Ch3 be proportional to its amount in the mixture. </span><br />
<div style="text-align: justify;">
Let us consider C1, C2 and C3 Amount of Ch1, Ch2 and Ch3 at any instant of time t, the rate of increase of C1, C2& C3 are given by the following differential equations:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
</div>
<div style="text-align: justify;">
dC1/dt = K1C3– K1C1C2</div>
<div style="text-align: justify;">
dC2/dt = K2C3– K1C1C2</div>
<div style="text-align: justify;">
dC3/dt=2K1C1C2-2K2C3</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Where K1and K2 are constants.</div>
<div style="text-align: justify;">
<br />
<a name='more'></a><br /></div>
<div style="text-align: justify;">
</div>
<div style="text-align: justify;">
As soon as the chemicals Ch1 and Ch2are mixed, the reaction starts and the amount of C1, C2, C3 in the mixture goes on changing as time progresses.The simulation of reaction will determine the state of the system. i.e. value of quantities C1, C2 and C3at different points in time. Starting at zero time, a very small increment of time is taken in each step. It is assumed to be so small, that all changes in the mixture can be taken to occur at theend of each increment. If C1(t), C2(t) and C3(t) are the quantities to there chemicals at time t, then at time t + <span class="f" style="background-color: white; color: #666666; font-family: arial, sans-serif; font-size: x-small; line-height: 16px; text-align: left;"> </span><span style="background-color: white; color: #444444; font-family: arial, sans-serif; font-size: x-small; line-height: 16px; text-align: left;">Δ</span>t, the quantities are ;</div>
<div style="text-align: justify;">
C1(t + <span class="f" style="background-color: white; color: #666666; font-family: arial, sans-serif; font-size: x-small; line-height: 16px; text-align: left;"> </span><span style="background-color: white; color: #444444; font-family: arial, sans-serif; font-size: x-small; line-height: 16px; text-align: left;">Δ</span>t) = C1(t) + dC1(t)/dt</div>
<div style="text-align: justify;">
C2(t + <span class="f" style="background-color: white; color: #666666; font-family: arial, sans-serif; font-size: x-small; line-height: 16px; text-align: left;"> </span><span style="background-color: white; color: #444444; font-family: arial, sans-serif; font-size: x-small; line-height: 16px; text-align: left;">Δ</span>t) = C2(t) + dC2(t)/dt</div>
<div style="text-align: justify;">
C3(t +<span class="f" style="background-color: white; color: #666666; font-family: arial, sans-serif; font-size: x-small; line-height: 16px; text-align: left;"> </span><span style="background-color: white; color: #444444; font-family: arial, sans-serif; font-size: x-small; line-height: 16px; text-align: left;">Δ</span>t) = C3(t) + dC3(t)/d</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
After forming the the mathematical model, we can simulate the system using following program written in C++:</div>
<div style="text-align: justify;">
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-oLd2rs5-zQ1xhNWUoQzgaaMA16uy4OS5elvO33EcdsimT8V_nAweevOIGgSIKJrszvY_VZMsc76vWttFdR8gTmqKaEbJgs6BiaCQ2WU_sUqEjmr_nhjCsUwUAUBNsl9JCShivA7IuVYM/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">// Simulate Chemical Reaction, </code> <a class="g-profile" href="http://plus.google.com/107360838856177439041" target="_blank">+Jivan Nepali</a> </pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-oLd2rs5-zQ1xhNWUoQzgaaMA16uy4OS5elvO33EcdsimT8V_nAweevOIGgSIKJrszvY_VZMsc76vWttFdR8gTmqKaEbJgs6BiaCQ2WU_sUqEjmr_nhjCsUwUAUBNsl9JCShivA7IuVYM/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> #include<iostream>
#include<fstream>
using namespace std;
float k1 = 0.008,k2 = 0.002,del_t = 0.1;
float calc_c1(float c1, float c2, float c3)
{
return (c1+(k2*c3-k1*c1*c2)*del_t);
}
float calc_c2(float c1, float c2, float c3)
{
return (c2+(k2*c3-k1*c1*c2)*del_t);
}
float calc_c3(float c1, float c2, float c3)
{
return (c3+(2*k1*c1*c2-2*k2*c3)*del_t);
}
int main()
{
float c1 = 25,c2 = 80, c3 =0;
int i;
float temp_c1,temp_c2,temp_c3;
ofstream outfile("simulation_lab.txt");
outfile<<c1<<","<<c2<<","<<c3<<"\n";
for(i=1;i<400;i++)
{
temp_c1 = calc_c1(c1,c2,c3);
temp_c2 = calc_c2(c1,c2,c3);
temp_c3 = calc_c3(c1,c2,c3);
c1 = temp_c1;
c2 = temp_c2;
c3 = temp_c3;
outfile<<c1<<","<<c2<<","<<c3<<"\n";
}
outfile.close();
cout<<"\nAll data printed on the file \"Simulation_Lab.txt\" on your project folder.\n";
cout<<"\nHave a look!!!\n\n";
return 0;
}
</code></pre>
To simulate the result obtained through the above model, we can use following MATLAB code:<br />
<br /></div>
<div style="text-align: justify;">
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-oLd2rs5-zQ1xhNWUoQzgaaMA16uy4OS5elvO33EcdsimT8V_nAweevOIGgSIKJrszvY_VZMsc76vWttFdR8gTmqKaEbJgs6BiaCQ2WU_sUqEjmr_nhjCsUwUAUBNsl9JCShivA7IuVYM/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">%Simulate Chemical Reaction, <a class="g-profile" href="http://plus.google.com/107360838856177439041" target="_blank">+Jivan Nepali</a> </code></pre>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-oLd2rs5-zQ1xhNWUoQzgaaMA16uy4OS5elvO33EcdsimT8V_nAweevOIGgSIKJrszvY_VZMsc76vWttFdR8gTmqKaEbJgs6BiaCQ2WU_sUqEjmr_nhjCsUwUAUBNsl9JCShivA7IuVYM/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">data = load('simulation_lab.txt');
plot(data(:,1),'b-');
hold on;
plot(data(:,2),'r-');
hold on;
plot(data(:,3),'k-');
legend('reactant c1','reactant c2','product c3');
</code></pre>
</div>
<div style="text-align: justify;">
<br />
The graph obtained using the MATLAB will be as shown:</div>
<div style="text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7p5owKHCKRxJ1KpurePjMGHaYSpxWe-6X1wnBeAxBo5krbt4k4y-Ok3dtWP35POOS_1jDRsxm7ET6IFA4GG4NOPVcq3AieuZb5UJK6Az3yy2hYb6eZr9Laws_tvS-Cx52yOwOCehhjJ5v/s1600/untitled.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7p5owKHCKRxJ1KpurePjMGHaYSpxWe-6X1wnBeAxBo5krbt4k4y-Ok3dtWP35POOS_1jDRsxm7ET6IFA4GG4NOPVcq3AieuZb5UJK6Az3yy2hYb6eZr9Laws_tvS-Cx52yOwOCehhjJ5v/s640/untitled.png" width="640" /></a></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Enjoy Simulating....!!!</div>
</div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com38tag:blogger.com,1999:blog-2551501238036138660.post-23075783995153837862013-05-21T19:05:00.000-07:002013-05-28T10:15:25.211-07:00Preventing Windows 8 from Automatically Launching Browser on Network Connection | Solutions<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
With the newer version of Microsoft's Windows Operating System- Windows 8, its users are experiencing newer and more advanced features than the older versions. But, at the same time they may have been facing with some of the strange troubles.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
One such issue is that Windows 8 automatically launches its default browser upon the the internet connection. To some users it may be helpful as they need not to open the browser and especially for users in a LAN provided by some institutions such as University, it may be the sign of avialability of the internet connection. But, for most of the users such as those posting in Microsoft's Community Page, it may be really problematic. </div>
<div style="text-align: justify;">
<br /></div>
<br />
<div style="text-align: justify;">
<i>"Windows is launching the following link in Internet Explorer:</i></div>
<div style="text-align: justify;">
<i><b>http://go.microsoft.com/fwlink/?LinkID=219472&clcid=0x409</b></i></div>
<div style="text-align: justify;">
<b><i><br /></i></b></div>
<div style="text-align: justify;">
<i>which leads to Bing. When I enable my internet connection Bing will popup from time to time. When I disable Internet Explorer via the Windows Features, the link will open in Mozilla Firefox."</i></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
So, the steps that I followed for solving this issue are given:</div>
<div style="text-align: justify;">
<br />
<a name='more'></a><br /></div>
<div style="text-align: justify;">
1. Press Win Key and type <i>regedit.exe.</i></div>
<div style="text-align: justify;">
<i>2. </i>Then, Navigate to the following path in the opened registry window:</div>
<div style="text-align: justify;">
<i>Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet</i></div>
<div style="text-align: justify;">
as shown:<br />
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoDPjLo_H96XibIHk9WEOC2hlYx9Jy61skwdNcYhtgpWsS5gmyDIsnEfYTY6R9c5l3Ocz8REiy-nopGoNHh-WCYIKIxdT9QRCarf3HqYq2Tc5PNuCU5rTAfAW3b3YhYZRtetlTSrPamsxr/s1600/win.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="284" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoDPjLo_H96XibIHk9WEOC2hlYx9Jy61skwdNcYhtgpWsS5gmyDIsnEfYTY6R9c5l3Ocz8REiy-nopGoNHh-WCYIKIxdT9QRCarf3HqYq2Tc5PNuCU5rTAfAW3b3YhYZRtetlTSrPamsxr/s640/win.PNG" width="640" /> </a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoDPjLo_H96XibIHk9WEOC2hlYx9Jy61skwdNcYhtgpWsS5gmyDIsnEfYTY6R9c5l3Ocz8REiy-nopGoNHh-WCYIKIxdT9QRCarf3HqYq2Tc5PNuCU5rTAfAW3b3YhYZRtetlTSrPamsxr/s1600/win.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoDPjLo_H96XibIHk9WEOC2hlYx9Jy61skwdNcYhtgpWsS5gmyDIsnEfYTY6R9c5l3Ocz8REiy-nopGoNHh-WCYIKIxdT9QRCarf3HqYq2Tc5PNuCU5rTAfAW3b3YhYZRtetlTSrPamsxr/s1600/win.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoDPjLo_H96XibIHk9WEOC2hlYx9Jy61skwdNcYhtgpWsS5gmyDIsnEfYTY6R9c5l3Ocz8REiy-nopGoNHh-WCYIKIxdT9QRCarf3HqYq2Tc5PNuCU5rTAfAW3b3YhYZRtetlTSrPamsxr/s1600/win.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoDPjLo_H96XibIHk9WEOC2hlYx9Jy61skwdNcYhtgpWsS5gmyDIsnEfYTY6R9c5l3Ocz8REiy-nopGoNHh-WCYIKIxdT9QRCarf3HqYq2Tc5PNuCU5rTAfAW3b3YhYZRtetlTSrPamsxr/s1600/win.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
3. In the right pane, right click the EnableActiveProbing and click Modify.</div>
<div style="text-align: justify;">
4. In the new window, set value to 0 if it is 1.</div>
<div style="text-align: justify;">
5. Restart your computer and you'll find your problem solved!</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
....</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
</div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com2tag:blogger.com,1999:blog-2551501238036138660.post-38088089435622825102013-05-18T09:32:00.000-07:002013-05-18T09:32:23.007-07:00Newton-Raphson Method in C with source codes<div dir="ltr" style="text-align: left;" trbidi="on">
Newton-Raphson method is a method for finding successively better roots (zeros) of a real valued function<br />
x: f(x) = 0.<br />
<br />
The algorithm can be implemented in C as follows:<br />
<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>#include<stdio.h>
#include<math.h>
#include<conio.h>
#define h pow(10,-6)
#define error pow(10,-6)
double f(double x)
{
return(x*x-4);
}
double df(double x)
{
return 2*x;
}<a name='more'></a>
int main()
{
int iter=0,maxiter,i;
double x0,x1;
for( i=-5;i<=5;i++)
{
printf("\n\t%d \t\t %6.2lf",i,f(i));
if(f(i)*f(i-1)<=0)
break;
}
while(1){
x0=i;
printf("\nInitial approximation taken within given limits : %lf \n",x0);
if (fabs(df(x0))==0)
{
printf("Denominator :(Derivative) zero !! choose another guess .\n");
}
else
break;
}
while(1)
{
++iter;
x1=x0-f(x0)/df(x0);
printf("\nx%d = %lf \tf(x%d) = %lf \n",iter,x1,iter,f(x1));
if(fabs(x1-x0)< error||f(x1)<error)
break;
x0=x1;
}
printf("\n Root = %lf ",x1);
printf("\n No.of iterations = %d",iter);
printf("\n interval width = %lf",fabs(x1-x0));
getch();
return 0;
}
</code></pre>
<br /></div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com0tag:blogger.com,1999:blog-2551501238036138660.post-84692165129416398422013-05-18T09:10:00.001-07:002013-05-18T09:11:10.960-07:00Implementation of Warshall's Algorithm in C++ with Source Codes<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
Warshall's algorithm is used to find the transitive closure of a graph. It's one of the efficient method to compute closure path that can be produced. Transitive closure is an important application in graph theory in computer science.</div>
<div style="text-align: justify;">
The following provides the source codes for implementing the Warshall's algorithm:</div>
<div style="text-align: justify;">
<br /></div>
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>
//.............................USE OF WARSHALL'S ALGORITHM TO CREATE TRANSITIVE CLOSURE OF A GRAPH..........
#include<iostream>
#include<conio.h>
using namespace std;
const int num_nodes =10;
int main()
{
//..............................................................VARIABLE DECLARATION
int num_nodes,k,n;
char i,j,res,c;
int adj[10][10],path[10][10];
<a name='more'></a>
cout<<"\n\t\t\t\t.............................................................................\n";
cout<<"\n\t\t\t\t\"USE OF WARSHALL'S ALGORITHM TO CREATE TRANSITIVE CLOSURE OF A GRAPH\"";
cout<<"\n\t\t\t\t.............................................................................\n";
cout<<"\n\tMaximum number of nodes in the graph :";cin>>n;
num_nodes = n;
cout<<"\n\n\tNODES ARE LABELED AS A,B,C,......\n\n";
cout<<"\nEnter 'y'for 'YES' and 'n' for 'NO' !!\n";
//..................................................................CREATING ADJACENCY MATRIX
for(i=65;i<65+num_nodes;i++)
for(j=65;j<65+num_nodes;j++)
{
cout<<"\n\tIs there an EDGE from " <<i<<" to "<<j<<" ? ";cin>>res;
if(res=='y')
adj[i-65][j-65]=1;
else
adj[i-65][j-65]=0;
}
//...................................................................DISPLAYING THE ADJ. MATRIX
cout<<"\n........................................Adjacency Matrix:.................................................\n";
cout<<"\n\t\t\t ";
for(i=0;i<num_nodes;i++){
c =65+i;
cout<<c<<" ";
}
cout<<"\n\n";
for(int i=0;i<num_nodes;i++)
{
c =65+i;
cout<<"\t\t\t"<<c<<" ";
for(int j=0;j<num_nodes;j++)
cout<<adj[i][j]<<" ";
cout<<"\n";
}
//...................................................................APPLYING WARSHALL'S ALGORITHM
for(int i=0;i<num_nodes;i++)
for(int j=0;j<num_nodes;j++)
path[i][j]=adj[i][j];
for(int k=0;k<num_nodes;k++)
for(int i=0;i<num_nodes;i++)
if(path[i][k]==1)
for(int j=0;j<num_nodes;j++)
path[i][j]=path[i][j]||path[k][j];
for(int i=0;i<num_nodes;i++)
for(int j=0;j<num_nodes;j++)
adj[i][j]=path[i][j];
//....................................................................DISPLAYING THE TRANSITIVE CLOSURE
cout<<"\n........................................Transitive Closure of the Graph:...................................\n";
cout<<"\n\t\t\t ";
for(i=0;i<num_nodes;i++){
c =65+i;
cout<<c<<" ";
}
cout<<"\n\n";
for(int i=0;i<num_nodes;i++)
{
c =65+i;
cout<<"\t\t\t"<<c<<" ";
for(int j=0;j<num_nodes;j++)
cout<<adj[i][j]<<" ";
cout<<"\n";
}
//...................................................................END MAIN
getch();
return 0;
}
</code></pre>
<br /></div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com1tag:blogger.com,1999:blog-2551501238036138660.post-34632264041433058142013-05-18T09:02:00.000-07:002013-06-07T07:44:05.506-07:00C Source Code for Dijkstra's Shortest Path Algorithm <div dir="ltr" style="text-align: left;" trbidi="on">
Dijkstra's Shortest Path Algorithm is the popular algorithm for finding shortest/optimal path in compute science due to its widespread application in different branches- computer networks, distributed systems, signal processing etc.<br />
<br />
I've implemented the algorithm for finding the minimum distance between any two nodes:<br />
<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>
///......................................SHORTEST PATH ALGORITHM << Dijkstra Algorithm >>......................
#include<stdio.h>
#include<conio.h>
#define MAX_NODES 10
#define INFINITY 1000
#define MEMBER 1
#define NON_MEMBER 0
struct arc{
int adj;
int weight;
};</code></pre>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;">int main(){</pre>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code></code></pre>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>
int i,j,k,weight[MAX_NODES][MAX_NODES],num_nodes,source,dest,precede[MAX_NODES];
int distance[MAX_NODES],permanent_nodes_set[MAX_NODES];
int current,current_distance,n;
int smalldist,newdist;
char s,d,node;
printf("\n\t\t................................................................................\n");
printf("\t\t\t\tSHORTEST PATH ALGORITHM << Dijkstra Algorithm >>");
printf("\n\t\t................................................................................\n");
printf("\n\n\t\t\tAssign 1000 as INFINITY for non-adjacent nodes !!\n\n");
printf("\nEnter the number of nodes in the GRAPH :");
scanf("%d",&n);
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
printf("\nEnter weight for arc[%c][%c] :",65+i,65+j);
scanf("%d",&weight[i][j]);
weight[j][i] =weight[i][j];
weight[i][i] =INFINITY;
}
printf("\nEnter the source _node :");scanf(" %c",&s);
source =(int)(s-97);
printf("\nEnter the destination_node :");scanf(" %c",&d);
dest = (int)(d-97);
printf("\n\t\t\tThe shortest path is :>>\n\n\t\t\t");
for(i=0;i<n;i++)
{
permanent_nodes_set[i] =NON_MEMBER;
distance[i] =INFINITY;
}
permanent_nodes_set[source]=MEMBER;
distance[source]=0;
current=source;
while(current!=dest)
{
smalldist =INFINITY;
current_distance =distance[current];
for(i=0;i<n;i++)
if(permanent_nodes_set[i] ==NON_MEMBER)
{
newdist =current_distance+weight[current][i];
if(newdist<distance[i])
{
distance[i]=newdist;
precede[i]=current;
if(node!=(65+current))
printf(" %c ->",65+current);
node =65+current;
}
if(distance[i]<smalldist)
{
smalldist =distance[i];
k =i;
}
}
current =k;
permanent_nodes_set[current] =MEMBER;
}
printf(" %c ->",65+dest);
printf("\n\n\t\t\tThe shortest distance = %d\n",distance[dest]);
getch();
return 0;
}
</code></pre>
</div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com0tag:blogger.com,1999:blog-2551501238036138660.post-29065357627119759252013-05-18T08:53:00.002-07:002013-05-18T08:53:54.060-07:00Priority Queue Implementation: C source codes<div dir="ltr" style="text-align: left;" trbidi="on">
A priority queue is data structure in which intrinsic ordering of the elements does determine the results of its basic operations. These are of two types- ascending (e.g. queue) and descending (e.g. stack).<br />
The following source code implements ascending type priority queue in C:<br />
<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>// Ascending Priority Queue Implementation in C</code></pre>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>#include<iostream.h>
#include<conio.h>
const int MAX=5;
class pqueue
{
int front,rear;
public:
struct data
{
int val,p,o;
}d[MAX];
<a name='more'></a>
pqueue()
{
front=rear=-1;
}
void insert(data d1);
data deletion();
void display();
};
void pqueue :: insert(data d1)
{
if(rear==MAX-1)
cout<<"Priority Queue is Full
";
else
{
rear++;
d[rear]=d1;
if(front==-1)
front=0;
data temp;
for(int i=front;i<=rear;i++)
for(int j=i+1;j<=rear;j++)
{
if(d[i].p > d[j].p)
{
temp=d[i];
d[i]=d[j];
d[j]=temp;
}
else
{
if(d[i].p==d[j].p)
{
if(d[i].o > d[j].o)
{
temp=d[i];
d[i]=d[j];
d[j]=temp;
}
}
}
}
}
}
data pqueue :: deletion()
{
data d1;
if(front==-1)
cout<<"Priority Queue is Empty
";
else
{
d1=d[front];
if(front==rear)
front=rear=-1;
else
front++;
}
return d1;
}
void pqueue :: display()
{
if(front==-1)
cout<<"Priority Queue is Empty
";
else
{
for(int i=front;i<=rear;i++)
{
cout<<"Object :"<<i+1<<endl;
cout<<"Value ="<<d[i].val<<endl;
cout<<"Priority="<<d[i].p<<endl;
cout<<"Order = "<<d[i].o<<endl;
}
}
}
void main()
{
pqueue p1;
data d1;
char op;
do
{
int ch;
clrscr();
cout<<"----------Menu-------------
";
cout<<"1.Insertion
2.Deletion
3.Display
4.Exit
";
cout<<"Enter your Choice<1..4> ?";
cin>>ch;
switch(ch)
{
case 1 : cout<<"Enter Value ?";
cin>>d1.val;
cout<<"Enter Priority?";
cin>>d1.p;
cout<<"Enter Order ?";
cin>>d1.o;
p1.insert(d1);
break;
case 2 : d1=p1.deletion();
cout<<"Value = "<<d1.val<<endl;
cout<<"Priority = "<<d1.p<<endl;
cout<<"Order ="<<d1.o<<endl;
break;
case 3 : p1.display();
break;
}
cout<<"Do You Want to Continue <Y/N> ?";
cin>>op;
}while(op=='Y' || op=='y');
getch();
}
</code></pre>
</div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com0tag:blogger.com,1999:blog-2551501238036138660.post-49165114168019341512013-05-18T08:41:00.002-07:002013-05-18T08:42:55.299-07:00Merge Sort Algorithm with C source Codes<div dir="ltr" style="text-align: left;" trbidi="on">
Here, I've presented the merge sort algorithm as the straight merge sort. The basic idea is to break the file into n subfiles of size 1 and merge adjacent disjoint pairs of files and repeating the process until we've single file remaining of size n.<br />
The C Source codes is as follows:<br />
<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;">// Merge sort implementation in C</pre>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>#include<stdio.h>
void getdata(int arr[],int n)
{
int i;
printf("\nEnter the data:");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
}
<a name='more'></a>
void display(int arr[],int n)
{
int i;
printf(" ");
for(i=0;i<n;i++)
{
printf("%d ",arr[i]);
}
getchar();
}
void sort(int arr[],int low,int mid,int high)
{
int i,j,k,l,b[20];
l=low;
i=low;
j=mid+1;
while((l<=mid)&&(j<=high))
{
if(arr[l]<=arr[j])
{
b[i]=arr[l];
l++;
}
else
{
b[i]=arr[j];
j++;
}
i++;
}
if(l>mid)
{
for(k=j;k<=high;k++)
{
b[i]=arr[k];
i++;
}
}
else
{
for(k=l;k<=mid;k++)
{
b[i]=arr[k];
i++;
}
}
for(k=low;k<=high;k++)
{
arr[k]=b[k];
}
}
void partition(int arr[],int low,int high)
{
int mid;
if(low<high)
{
mid=(low+high)/2;
partition(arr,low,mid);
partition(arr,mid+1,high);
sort(arr,low,mid,high);
}
}
void main()
{
int arr[20];
int n;
printf("Enter number of data:");
scanf("%d",&n);
getdata(arr,n);
partition(arr,0,n-1);
printf("\nThe Sorted array is :\n");
display(arr,n);
getchar();
}
</code></pre>
</div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com0tag:blogger.com,1999:blog-2551501238036138660.post-22372419430252055042013-05-18T08:33:00.000-07:002013-05-18T08:43:46.238-07:00C Source Codes for Implementing Linked List<div dir="ltr" style="text-align: left;" trbidi="on">
The linked list can be implemented using the pointer structure in C so that we can<br />
<br />
<ul style="text-align: left;">
<li>add an element</li>
<li>delete an element</li>
<li>search for an element</li>
<li>concatenate two linked list</li>
<li>Invert a linked list</li>
<li>Display elements in the list</li>
</ul>
<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>//Program to demonstrate linked list operations
# include<stdio.h>
# include<conio.h>
# include "malloc.h"
struct node
{
int data;
struct node *link;
};
<a name='more'></a>
void main()
{
int a=111,b=2,c=3,will,wish,num;
struct node *ptr,*ptr2,*result,*temp;
void add(struct node **,int );
struct node * search(struct node *);
void display(struct node *);
void invert(struct node *);
void del(struct node *,int);
struct node * concat(struct node *,struct node *);
ptr=NULL;
ptr2=NULL;
result=NULL; //result for storing the result of concatenation
////();
will=1;
printf("Main Menu\n1. Add element\n2.Delete element\n3.Search element\n4Linked List concatenation\n5.Invert linked list\n6. Display elements\n7.To exit\n\nPlease enter the choice");
while(will==1)
{
scanf("%d",&wish);
switch(wish)
{
case 1:
printf("Enter the element you want to add : ");
scanf("%d",&num);
add(&ptr,num);
display(ptr);
break;
case 2:
printf("Enter the element to delete :");
scanf("%d",&num);
del(ptr,num);
break;
case 3:
printf("Now demonstrating search \n\t");
temp = search(ptr);
printf("Address of first occurence is %u \t",temp);
break;
case 4:
/* Inputs given internally for demo only */
printf(" Now demonstrating linked list concatenation\tPress any key to continue...");
add(&ptr2,2);
add(&ptr2,4);
add(&ptr2,6);
getch();
printf("Displaying second Linked List");
display(ptr2);
getch();
result = concat(ptr,ptr2);
//();
printf("Now Displaying the result of concatenation");
display(result);
getch();
break;
case 5:
printf("Inverting the list ...Press any key to continue...\n\t");
invert(ptr);
break;
case 6:
display(ptr);
break;
case 7:
exit(1);
break;
default:
printf("Illegal choice");
}
printf("DO you want to continue ? ");
scanf("%d",&will);
} //end of while
}
void add(struct node **q,int num)
{
struct node *temp;
temp = *q;
if(*q==NULL)
{
*q=malloc(sizeof(struct node));
temp = *q;
}
else
{
while((temp->link)!=NULL)
{
temp=temp->link;
}
temp->link = malloc(sizeof(struct node));
temp=temp->link;
}
temp->data = num;
temp->link = NULL;
}
void display(struct node *pt)
{
while(pt!=NULL)
{
printf("\tData : %d\t",pt->data);
printf("Link : %d\t",pt->link);
pt=pt->link;
}
}
void invert(struct node *ptr)
{
struct node *p,*q,*r;
p=ptr;
q=NULL;
while(p!=NULL)
{
r=q;
q=p;
p=p->link;
q->link=r;
}
ptr = q;
display(ptr);
}
// CONCATENATION OF LINKED LISTS
struct node * concat(struct node *p,struct node *q)
{
struct node *x,*r;
if (p==NULL)
r=q;
if (q==NULL)
r=p;
else
{
x=p;
r=x;
while(x->link!=NULL)
x=x->link;
x->link=q;
}
return(r);
}
// SEARCHING AN ELEMENT IN THE LINKED LIST
// THIS FUNCTION FINDS THE FIRST OCCURENCE OF
// A DATA AND RETURNS A POINTER TO ITS ADDRESS
struct node * search(struct node *p)
{
struct node *temp;
int num;
temp = p;
printf("Enter the data that you want to search ");
scanf("%d",&num);
printf("Link of temp %u", temp->link);
while(temp->link!=NULL)
{
printf("\nIn while\n ");
if(temp->data == num)
return(temp);
temp=temp->link;
}
return(NULL);
}
// DELETING DATA FROM THE LINKED LIST//
void del(struct node *p,int num)
{
struct node *temp,*x;
temp=p;
x= NULL;
while (temp->link !=NULL)
{
if(temp->data == num)
{
if (x==NULL)
{
p = temp->link;
free(temp);
return;
}
else
{
x->link = temp->link;
free(temp);
return;
}
} //end of outer if
x=temp;
temp=temp->link;
} //end of while
printf("\n No such entry to delete \n");
} //end of fn.
</code></pre>
<br /></div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com10tag:blogger.com,1999:blog-2551501238036138660.post-10909150855589936832013-05-18T08:22:00.000-07:002013-05-18T08:24:14.259-07:00Implement Infix to postfix conversion using Stack C source codes<div dir="ltr" style="text-align: left;" trbidi="on">
We can implement a valid infix expression to a valid postfix expression using stacks in c as shown:<br />
<br />
<br />
<i>
</i>
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><i><code>
//C PROGRAM TO CONVERT GIVEN VALID INFIX EXPRESSION INTO POSTFIX EXPRESSION USING STACKS.
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define MAX 20
char stack[MAX];
int istack[MAX];
int top = -1;
char pop();
void push(char item);
<a name='more'></a></code></i></pre>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><i><code>int prcd(char symbol)
{
switch(symbol)
{
case '+':
case '-':return 2;break;
case '*':
case '/':return 4;break;
case '$':return 6;break;
case '(':
case ')':
case '#':return 1;break;
}
}
int isoperator(char symbol)
{
if(symbol=='+'||symbol=='-'||symbol=='*'||symbol=='/'||symbol=='$')
return 1;
else if(symbol==')'||symbol=='(')
return -1;
else
return 0;
}
void convertip(char infix[],char postfix[])
{
int i,symbol,j=0;
stack[++top]='#';
for(i=0;i<strlen(infix);i++)
{
symbol=infix[i];
if(isoperator(symbol)==0)
{
postfix[j]=symbol;
j++;
}
else{
if(symbol=='(')
push(symbol);
else if(symbol==')')
{
while(stack[top]!='(')
{
postfix[j]=pop();
j++;
}
pop();//pop out (.
}
else{
if(prcd(symbol)>prcd(stack[top]))
push(symbol);
else{
while(prcd(symbol)<=prcd(stack[top]))
{
postfix[j]=pop();
j++;
}
push(symbol);
}//end of else.
}//end of else.
}//end of else.
}//end of for.
while(stack[top]!='#')
{
postfix[j]=pop();
j++;
}
postfix[j]='\0';//null terminate string.
}
long int oper(char c,int op1,int op2)
{
switch(c)
{
case '+':return op2+op1+48;
case '-':return op2-op1+48;
case '*':return op2*op1+48;
case '/':return op2/op1+48;
case '$':return pow(op2,op1)+48;
default: printf("Invalid operation!!");exit(1);
}
}
int eval(char postfix[])
{
int i;
char c;
float value ,op1,op2;
for(i=0;(c=postfix[i])!='\0';i++)
{
if(isoperator(postfix[i])==0)
push(postfix[i]);
else
{
op1=pop();
op2=pop();
op1-=48;
op2-=48;
value = oper(c,op1,op2) ;
push(value);
}
}
return (pop()-48);
}
int main()
{
char infix[20],postfix[20];
int i;
char res;
do
{
printf("\nEnter the valid infix string: ");
fflush(stdin);
gets(infix);
for(i=0;infix[i]!='\0';i++)
{
if(isoperator(infix[i])==1 && isoperator(infix[i+1])==1)
{
printf("\n\tINPUT ERROR : Invalid Infix Expression !!");
getch();
exit(0);
}
}
convertip(infix,postfix);
printf("The corresponding postfix string is: ");
puts(postfix);
printf("\nThe value of postfix expression : %d",eval(postfix));
printf("\n\n\tDo you want to continue -[y/n]? ");
scanf("%c",&res);
}while(res =='y'||res=='Y');
return 0;
}
void push(char item)
{
top++;
stack[top]=item;
}
char pop()
{
char a;
a=stack[top];
top--;
return a;
}
</code></i></pre>
<i>
</i>
</div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com7tag:blogger.com,1999:blog-2551501238036138660.post-11093787917385818502013-05-18T08:14:00.000-07:002013-05-18T08:23:08.759-07:00Code Generator in C<div dir="ltr" style="text-align: left;" trbidi="on">
The following code generates the code itself. The code seems to be simple but it's little bit tricky and is FAQ for programmers in an interview.<br />
<br />
<br />
<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><div style="text-align: left;">
<b><code>#include"stdio.h"</code></b><br />
<b><code>#include"conio.h"</code></b><br />
<b><code>char *s="#include%c#</code></b><b><code>include%cchar *s=%c%s%c;%cvoid main()%c{%cclrscr();-%cprintf(s,10,10,34,s,34,10,10,10,10,10,10);%cgetch();%c}";</code></b><br />
<b><code>void main()</code><code>{</code></b><br />
<b><code>//clrscr();</code></b><br />
<b><code>printf(s,10,10,34,s,34,10,10,10,10,10,10);</code></b><br />
<b><code>getch();</code></b><br />
<b><code>}</code></b></div>
<code>
</code></pre>
</div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com0tag:blogger.com,1999:blog-2551501238036138660.post-52550250585817778072013-05-18T07:59:00.000-07:002013-05-18T08:24:37.373-07:00Binary Tree Implementation in C with Tree Traversals<div dir="ltr" style="text-align: left;" trbidi="on">
We can implement the binary tree using C so that we can add a node, delete a node, and can perform different tree traversals:<br />
<div>
1. Preorder tree traversal</div>
<div>
2. Inorder tree traversal</div>
<div>
3. Post order tree traversal</div>
<div>
<br /></div>
<div>
<div>
<br /></div>
<blockquote class="tr_bq">
<br />
<i>
</i>
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><i><code>/// ..............................................BINARY TREE OPERATIONS AND TREE TRAVERSALS
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
///.................................................................DYNAMIC STRUCTURE FOR BINARY TREE
struct tree
{
int info;
struct tree *left_subtree;
struct tree *right_subtree;
};
<a name='more'></a>
///...................................................................GLOBAL FUNCTIONS DECLARATIONS
struct tree* make_tree();
struct tree* delete_node(struct tree*,int);
void insert_node(struct tree *);
void preorder(struct tree *);
void inorder(struct tree *);
void postorder(struct tree *);
///....................................................................MAIN FUNCTION
int main()
{
struct tree *p_tree,*t;
int choice,del_item;
printf("\n\t_____________________________****OPERATIONS ON BINARY TREE AND TREE TRAVERSALS****_____________________________\n\n");
printf("\n1. INSERTION");
printf("\n2. dELETION");
printf("\n3. PRE-ORdER TRAVERSAL");
printf("\n4. IN-ORdER TRAVERSAL");
printf("\n5. POST-ORdER TRAVERSAL");
printf("\n6. EXIT FROM MENU\n");
p_tree = NULL;
do
{
printf("\n\t\t\t\t\t\tEnter Choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: ///.........................................................INSERTION
if(p_tree == NULL)
p_tree = make_tree();
else
insert_node(p_tree);
break;
case 2: ///..................................................... ..DELETION
if(p_tree == NULL)
printf("Binary Tree Empty.......");
else
{
printf("Enter info to delete:");
scanf("%d",&del_item);
if(p_tree->left_subtree == NULL && p_tree->right_subtree == NULL && p_tree->info == del_item)
{
t = p_tree;
p_tree = NULL;
free(t);
}
else
p_tree = delete_node(p_tree,del_item);
}
break;
case 3:/// ......................................................PRE-ORdER TRAVERSAL
printf("\n\n\tPRE-ORdER TRAVERSAL :\n\t\t\t\t");
if(p_tree == NULL)
printf("\nBinary Tree Empty....\n");
else
preorder(p_tree);
break;
case 4:///..................................................... IN-ORdER TRAVERSAL
printf("\n\n\tIN-ORdER TRAVERSAL :\n\t\t\t\t");
if(p_tree == NULL)
printf("\nBinary Tree Empty....\n");
else
inorder(p_tree);
break;
case 5:///...................................................... POST-ORdER TRAVERSAL
printf("\n\n\tPOST-ORdER TRAVERSAL :\n\t\t\t\t");
if(p_tree == NULL)
printf("\nBinary Tree Empty....\n");
else
postorder(p_tree);
break;
case 6: ///...................................................... TO EXIT
exit(0);
default:///........................................................dEFAULT CASE
printf("\n\tPlease,Enter the choice lying among 1 to 4 .\n");
}
}while(1);
getch();
return 0;
}
struct tree* make_tree() ///..................................ALLOCATES A NOdE & SETS IT AS A ROOT OF THE TREE
{
struct tree * p_tree;
p_tree =(struct tree*)malloc(sizeof(struct tree));
printf("\n\t\tEnter info: ");
scanf("%d",&p_tree->info);
p_tree->left_subtree = NULL;
p_tree->right_subtree = NULL;
return p_tree;
}
void insert_node(struct tree *p_tree) ///.............................ALLOWS INSERTION OF A NOdE
{
struct tree *t,*n;
t = p_tree;
n =(struct tree *)malloc(sizeof(struct tree));
printf("\n\t\tEnter info: ");
scanf("%d",&n->info);
n->left_subtree = NULL;
n->right_subtree = NULL;
while(t->left_subtree != NULL || t->right_subtree != NULL)
{
if(t->left_subtree != NULL)
if(n->info < t->info)
t = t->left_subtree;
if(t->right_subtree != NULL)
if(n->info>= t->info)
t = t->right_subtree;
if((t->left_subtree == NULL) && (n->info < t->info) && (n->info <t->right_subtree->info))
break;
if((t->right_subtree == NULL) && (n->info >= t->info) && (n->info >t->left_subtree->info))
break;
}
if((n->info < t->info) && (t->left_subtree == NULL))
t->left_subtree=n;
if((n->info > t->info) && (t->right_subtree == NULL))
t->right_subtree = n;
}
void inorder(struct tree * p_tree) ///..................................................ALLOWS IN-ORDER TRAVERSAL
{
//printf("\n\t\t");
if(p_tree != NULL)
{
inorder(p_tree->left_subtree);
printf("%d ",p_tree->info);
inorder(p_tree->right_subtree);
}
}
void preorder(struct tree *p_tree) ///..................................................ALLOWS PRE-ORDER TRAVERSAL
{
//printf("\n\t\t");
if(p_tree != NULL)
{
printf("%d ",p_tree->info);
preorder(p_tree->left_subtree);
preorder(p_tree->right_subtree);
}
}
void postorder(struct tree *p_tree) ///.................................................ALLOWS POST - ORDER TRAVERSAL
{
//printf("\n\t\t");
if(p_tree != NULL)
{
postorder(p_tree->left_subtree);
postorder(p_tree->right_subtree);
printf("%d ",p_tree->info);
}
}
struct tree * delete_node(struct tree *p_tree,int d) ///................................ALLOWS DELETION OF A NODE
{
int f = 0,f1 = 0;
struct tree *p,*t,*t1,*x;
t = p_tree;
//to search found or not
while(t != NULL)
{
if(t->info == d)
{
f = 1;
x = t;
break;
}
if(t->info > d)
{
p = t;
t = t->left_subtree;
}
else if(t->info <= d)
{
p = t;
t = t->right_subtree;
}
}
if(f == 0)
{
printf("\nThe entered element not found.......\n");
return p_tree;
}
///........................................................................if the node to be deleted has no sub-tree
if(x->left_subtree == NULL && x->right_subtree == NULL)
{
if(p->right_subtree == x)
p->right_subtree = NULL;
else
p->left_subtree = NULL;
free(x);
return p_tree;
}
///......................................................................if the node to be deleted has left & right sub-trees
if(x->left_subtree != NULL && x->right_subtree != NULL)
{
p = x;
t1 = x->right_subtree;
while(t1->left_subtree != NULL)
{
p = t1; f1 = 1;
t1 = t1->left_subtree;
}
if(t1->left_subtree == NULL && t1->right_subtree == NULL)
{
x->info = t1->info;
if(f1 == 1)
p->left_subtree = t1->left_subtree;
if(f1 == 0)
x->right_subtree = t1->right_subtree;
free(t1);
return p_tree;
}
if(t1->right_subtree != NULL)
{
x->info = t1->info;
if(f1 == 1)
p->left_subtree = t1->right_subtree;
if(f1 == 0)
p->right_subtree = t1->right_subtree;
free(t1);
return p_tree;
}
}
///..........................................................................if the node to be deleted has oniy right sub-tree
if(x->left_subtree == NULL && x->right_subtree != NULL && x->info!= p_tree->info)
{
if(p->left_subtree == x)
p->left_subtree = x->right_subtree;
else
p->right_subtree = x->right_subtree;
free(x);
return p_tree;
}
///........................................................................if the node to be deleted has oniy left sub-tree
if(x->left_subtree != NULL && x->right_subtree == NULL && x->info != p_tree->info)
{
if(p->left_subtree == x)
p->left_subtree = x->left_subtree;
else
p->right_subtree = x->left_subtree;
free(x);
return p_tree;
}
if(x->left_subtree != NULL && x->right_subtree == NULL && x->info == p_tree->info)
{
p_tree = x->left_subtree;
free(p);
return p_tree;
}
if(x->left_subtree == NULL && x->right_subtree != NULL && x->info == p_tree->info)
{
p_tree = x->right_subtree;
free(p);
return p_tree;
}
}
</code></i></pre>
<i>
</i>
</blockquote>
</div>
</div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com3tag:blogger.com,1999:blog-2551501238036138660.post-20760396649344873042013-05-11T08:11:00.001-07:002013-05-18T07:46:19.882-07:00Time & Space Complexity of Basic K-means Algorithm<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal">
<div style="text-align: justify;">
The basic k-means clustering algorithm is a simple algorithm that separates the given data space into different clusters based on centroids calculation using some proximity function. Using this algorithm, we first choose the k- points as initial centroids and then each point is assigned to a cluster with the closest centroid. The algorithm is formally described as follows:<o:p></o:p></div>
</div>
<div class="MsoNormal">
<div style="text-align: justify;">
<span class="Heading2Char"><span style="font-size: 13pt;"><b>Input:</b></span></span> A data set D containing m objects (points) with n attributes in an Euclidean space</div>
</div>
<div class="MsoNormal">
<span class="Heading2Char"><span style="font-size: 13pt;"><b>Output:</b></span></span> Partitioning of m objects into k-clusters C<sub>1,</sub> C<sub>2</sub>, C<sub>3,</sub> …, C<sub>k</sub>, <i>i.e.</i> C<sub>i</sub> <span style="background-color: white; font-family: 'Cambria Math', serif;">⊂</span><span style="background-color: white; font-family: 'Cambria Math', serif; font-size: 10pt;"> </span>D and C<sub>i</sub> ∩ C<sub>j</sub> = <span style="font-size: 16pt;">ᶲ </span>(for<span style="font-size: 16pt;"> </span>1 ≤ i, j ≤ k)<br />
<br />
<a name='more'></a><br /></div>
<div class="MsoNormal">
<o:p></o:p></div>
<h4>
Procedure:</h4>
<ol>
<li><span style="text-indent: -0.25in;">Select k points as initial centroid</span></li>
<li><b style="text-indent: -0.25in;">Repeat</b></li>
<li><span style="text-indent: -0.25in;">Form k clusters by assigning each point to its closest centroid</span></li>
<li><span style="font-size: 7pt; text-indent: -0.25in;"> </span><span style="text-indent: -0.25in;">Re-compute the centroid of each cluster</span></li>
<li><b style="text-indent: -0.25in;">Until</b><span style="text-indent: -0.25in;"> the centroids don’t change</span></li>
</ol>
<o:p></o:p><br />
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<o:p></o:p></div>
<div class="MsoListParagraphCxSpLast" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<o:p></o:p></div>
<h4>
Time Complexity of the algorithm:</h4>
<h2>
<o:p></o:p></h2>
<div class="MsoNormal">
<div style="text-align: justify;">
To analyze the complexity of the algorithm in terms of time required, we need to identify the operations required in each step and in each iteration of the algorithm. Here, for k-means algorithm, the operations for each iteration are:<o:p></o:p></div>
</div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l1 level1 lfo2; text-indent: -.25in;">
</div>
<ul>
<li style="text-align: justify;"><span style="text-indent: -0.25in;">Calculation of distances: To calculate the distance from a point to the centroid, we can use the squared Euclidean proximity function. For this, we need two subtractions, one summation, two multiplications and one square - root operations, i.e., 6-operations.</span></li>
<li style="text-align: justify;"><span style="text-indent: -0.25in;">Comparisons between distances</span></li>
<li style="text-align: justify;"><span style="text-indent: -0.25in;">Calculation of centroids</span></li>
</ul>
<div style="text-align: justify;">
<o:p></o:p><br /></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l1 level1 lfo2; text-indent: -.25in;">
<o:p></o:p></div>
<div class="MsoListParagraphCxSpLast" style="mso-list: l1 level1 lfo2; text-indent: -.25in;">
<o:p></o:p></div>
<div class="MsoNormal">
So, the total number of operations for an iteration<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 1.5in;">
= distance calculation operations + comparison operations + centroids calculation operations<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 1.5in;">
= 6*[k*m*n] operations + [(k-1)*m*n] operations + [k*((m-1) + 1)*n] operations<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Assume that the algorithm converges after I iterations, then total number of operations for the algorithm<o:p></o:p></div>
<div class="MsoNormal" style="text-indent: .5in;">
= 6*[I*k*m*n] operations + [I*(k-1)*m*n] operations + [I*k*((m-1) + 1)*n] operations<o:p></o:p></div>
<div class="MsoNormal" style="text-indent: .5in;">
= [6Ikmn + I(k-1)mn + Ikmn] operations<o:p></o:p></div>
<div class="MsoNormal" style="text-indent: .5in;">
≈ O (I*k*m*n)<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<div style="text-align: justify;">
Here, we’ve applied the basic assumption of each operation requiring the same amount of time. Since, normally, k << m & n << m, the analysis shows that the k-means is linear in m, the number of points, and is scalable and efficient in processing large data sets.<o:p></o:p></div>
</div>
<div class="MsoNormal">
<div style="text-align: justify;">
<br /></div>
</div>
<div class="MsoNormal">
</div>
<h4 style="text-align: justify;">
Space Complexity of the Algorithm:</h4>
<h2>
<o:p></o:p></h2>
<div class="MsoNormal">
<div style="text-align: justify;">
The space requirement for k-means are modest because only the data points and centroids are needed to be stored. Specifically, the storage required is O((m+k)n), where m is the number of objects (points) & n is the number of attributes considering n-dimensional objects.<o:p></o:p></div>
</div>
<div class="MsoNormal">
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
From: <a href="http://nepalijivan.blogspot.com/2013/02/algorithm-analysis-basic-k-means.html">Algorithm Analysis: The Basic K-means Clustering Algorithm</a></div>
</div>
<div class="MsoNormal">
</div>
</div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com0tag:blogger.com,1999:blog-2551501238036138660.post-22064921428579529762013-05-11T08:08:00.002-07:002013-05-18T07:55:27.180-07:00DBSCAN Algorithm Implementation in MATLAB<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;">Density Based Spatial Clustering of Applications with Noise (DBSCAN) Algorithm locates regions of high density that are separated from one another by regions of low density. DBSCAN is a center based approach to clustering in which density is estimated for a particular point in the data set by counting the number of points within the specified radius, <b>ɛ, </b>of that point.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;">The center based approach to density allows us to classify a point as one of the three:<o:p></o:p></span><br />
<br />
<span style="font-family: Symbol; font-size: 12pt; line-height: 17px; text-indent: -0.25in;"><span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;"> </span></span><b style="text-indent: -0.25in;"><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;">Core points:</span></b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px; text-indent: -0.25in;"> These points are in the interior of the dense region</span><br />
<span style="font-family: Symbol; font-size: 12pt; line-height: 17px; text-indent: -0.25in;"><span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;"> </span></span><b style="text-indent: -0.25in;"><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;">Border points:</span></b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px; text-indent: -0.25in;">These points are not the core points, but fall within the neighborhood of the core points</span><br />
<span style="font-family: Symbol; font-size: 12pt; line-height: 17px; text-indent: -0.25in;"><span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;"> </span></span><b style="text-indent: -0.25in;"><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;">Noise points:</span></b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px; text-indent: -0.25in;"> A noise point is a point that is neither a core point nor a border point.</span><br />
<ul style="text-indent: -24px;"></ul>
</div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l1 level1 lfo1; text-align: justify; text-indent: -.25in;">
<span style="font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 17px; text-indent: -0.25in;"> The formal definition of DBSCAN algorithm is illustrated below:</span><br />
<ul></ul>
</div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;"></span><br />
<a name='more'></a><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l2 level1 lfo2; text-align: justify; text-indent: -.25in;">
<br />
<ol>
<li><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px; text-indent: -0.25in;"><span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;"> </span></span><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px; text-indent: -0.25in;">Eliminate noise points</span></li>
<li><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px; text-indent: -0.25in;"><span style="font-family: 'Times New Roman'; font-size: 7pt; line-height: normal;"> </span></span><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px; text-indent: -0.25in;">Perform clustering on remaining points</span></li>
<li><i style="text-indent: -0.25in;"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 107%; mso-fareast-font-family: "Times New Roman";"><span style="font-family: 'Times New Roman'; font-size: 7pt; font-style: normal;"> </span></span></i><i style="text-indent: -0.25in;"><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;">current_cluster_label := 0</span></i></li>
</ol>
</div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 74.25pt; mso-add-space: auto; mso-list: l0 level1 lfo3; text-align: justify; text-indent: -.25in;">
<span style="font-family: Symbol; font-size: 12.0pt; line-height: 107%; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;">for</span></b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;"> all core points <b>do<o:p></o:p></b></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 74.25pt; mso-add-space: auto; mso-list: l0 level1 lfo3; text-align: justify; text-indent: -.25in;">
<span style="font-family: Symbol; font-size: 12.0pt; line-height: 107%; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;">If</span></b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;"> the core point has no <i>cluster_label</i> <b>then<o:p></o:p></b></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 74.25pt; mso-add-space: auto; text-align: justify; text-indent: 33.75pt;">
<i><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;">current_cluster_label := current_cluster_label +1<o:p></o:p></span></i></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 74.25pt; mso-add-space: auto; text-align: justify; text-indent: 33.75pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;">Assign the current core point the <i>current_cluster_label<o:p></o:p></i></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 74.25pt; mso-add-space: auto; mso-list: l0 level1 lfo3; text-align: justify; text-indent: -.25in;">
<span style="font-family: Symbol; font-size: 12.0pt; line-height: 107%; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;">end if<o:p></o:p></span></b></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 74.25pt; mso-add-space: auto; mso-list: l0 level1 lfo3; text-align: justify; text-indent: -.25in;">
<span style="font-family: Symbol; font-size: 12.0pt; line-height: 107%; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;">For</span></b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;"> all points within the radius <b>do<o:p></o:p></b></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 74.25pt; mso-add-space: auto; mso-list: l0 level1 lfo3; text-align: justify; text-indent: -.25in;">
<span style="font-family: Symbol; font-size: 12.0pt; line-height: 107%; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;">If</span></b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;"> the point does not have a cluster_label <b>then<o:p></o:p></b></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 74.25pt; mso-add-space: auto; text-align: justify; text-indent: 33.75pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;">Label the point with the <i>current_cluster_label<o:p></o:p></i></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 74.25pt; mso-add-space: auto; mso-list: l0 level1 lfo3; text-align: justify; text-indent: -.25in;">
<span style="font-family: Symbol; font-size: 12.0pt; line-height: 107%; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;">end if<o:p></o:p></span></b></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 74.25pt; mso-add-space: auto; mso-list: l0 level1 lfo3; text-align: justify; text-indent: -.25in;">
<span style="font-family: Symbol; font-size: 12.0pt; line-height: 107%; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;">end for<o:p></o:p></span></b></div>
<div class="MsoListParagraphCxSpLast" style="margin-left: 74.25pt; mso-add-space: auto; mso-list: l0 level1 lfo3; text-align: justify; text-indent: -.25in;">
<span style="font-family: Symbol; font-size: 12.0pt; line-height: 107%; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol;">·<span style="font-family: 'Times New Roman'; font-size: 7pt;"> </span></span><b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 17px;">end for</span></b><br />
<b style="font-family: 'Times New Roman', serif; line-height: 17px; text-indent: -0.25in;"><br /></b><span style="font-family: 'Times New Roman', serif; line-height: 17px; text-indent: -0.25in;"><a href="http://nepalijivan.blogspot.com/p/implementation-of-dbscan-algorithm-in.html">For Implentation in MATLAB</a></span></div>
</div>
Jhttp://www.blogger.com/profile/06356043085807127323noreply@blogger.com0