<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>{Complexity} &#187; Algorithm</title>
	<atom:link href="http://technote.wsjoung.com/tag/algorithm/feed/" rel="self" type="application/rss+xml" />
	<link>http://technote.wsjoung.com</link>
	<description>simple note</description>
	<lastBuildDate>Tue, 27 Jul 2010 04:28:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Interview questions (2)</title>
		<link>http://technote.wsjoung.com/2010/01/07/interview-questions-2/</link>
		<comments>http://technote.wsjoung.com/2010/01/07/interview-questions-2/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 05:51:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Interview]]></category>

		<guid isPermaLink="false">http://technote.wsjoung.com/?p=132</guid>
		<description><![CDATA[1) There are integer arrays, A and B. what&#8217;s the best way to generate an array which contains all duplicated elements of A and B. 2) There are integer arrays, A and B. how to figure it out if those contain same elements. 3) There many of files in a folder and some of them [...]]]></description>
			<content:encoded><![CDATA[<p>1) There are integer arrays, A and B. what&#8217;s the best way to generate an array which contains all duplicated elements of A and B.<br />
2) There are integer arrays, A and B. how to figure it out if those contain same elements.<br />
3) There many of files in a folder and some of them contains phone numbers. how to find them.<br />
4) Design restaurant reservation system. class design and data structures. </p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2010/01/07/interview-questions-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculating distances with geographic data</title>
		<link>http://technote.wsjoung.com/2009/08/17/calculating-distances-with-geographic-data/</link>
		<comments>http://technote.wsjoung.com/2009/08/17/calculating-distances-with-geographic-data/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 20:28:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Distance]]></category>
		<category><![CDATA[Geographic]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://technote.wsjoung.com/?p=97</guid>
		<description><![CDATA[The great circle distance formula: d = acos(sin(x1)*sin(x2)+cos(x1)*cos(x2)*cos(y2-y1)) * r CREATE TABLE ZCTA ( zcta CHAR(6) NOT NULL , lat_degrees DECIMAL(9,6) NOT NULL , long_degrees DECIMAL(9,6) NOT NULL , PRIMARY KEY(zcta)); ALTER TABLE ZCTA ADD COLUMN lat_radians DECIMAL(9,6) NOT NULL , ADD COLUMN long_radians DECIMAL(9,6) NOT NULL; UPDATE ZCTA SET lat_radians = lat_degrees * (PI() [...]]]></description>
			<content:encoded><![CDATA[<p><strong><em>The great circle distance formula:<br />
d = acos(sin(x1)*sin(x2)+cos(x1)*cos(x2)*cos(y2-y1)) * r</em></strong></p>
<p>CREATE TABLE ZCTA (<br />
zcta CHAR(6) NOT NULL<br />
, lat_degrees DECIMAL(9,6) NOT NULL<br />
, long_degrees DECIMAL(9,6) NOT NULL<br />
, PRIMARY KEY(zcta));</p>
<p>ALTER TABLE ZCTA<br />
ADD COLUMN lat_radians DECIMAL(9,6) NOT NULL<br />
, ADD COLUMN long_radians DECIMAL(9,6) NOT NULL;</p>
<p>UPDATE ZCTA<br />
SET lat_radians = lat_degrees * (PI() / 180)<br />
, long_radians = long_degrees * (PI() / 180);</p>
<p><strong>/* calculating the distance between two points */</strong><br />
SELECT<br />
ROUND(ACOS(SIN(x1.lat_radians) * SIN(x2.lat_radians)<br />
+ COS(x1.lat_radians) * COS(x2.lat_radians)<br />
* COS(x2.long_radians &#8211; x1.long_radians)) * 3956, 2) AS &#8220;Distance&#8221;<br />
FROM ZCTA x1, ZCTA x2<br />
WHERE x1.zcta = &#8217;1001&#8242;<br />
AND x2.zcta = &#8217;21236&#8242;;</p>
<p><strong>/* zip codes within a given radius */</strong><br />
SELECT<br />
x2.zcta AS zip<br />
, ROUND(ACOS(SIN(x1.lat_radians) * SIN(x2.lat_radians)<br />
+ COS(x1.lat_radians) * COS(x2.lat_radians)<br />
* COS(x2.long_radians &#8211; x1.long_radians)) * 3956, 2) AS &#8220;Distance&#8221;<br />
FROM ZCTA x1, ZCTA x2<br />
WHERE x1.zcta = &#8217;21236&#8242;<br />
AND ACOS(SIN(x1.lat_radians) * SIN(x2.lat_radians)<br />
+ COS(x1.lat_radians) * COS(x2.lat_radians)<br />
* COS(x2.long_radians &#8211; x1.long_radians)) * 3956 &lt;= 5<br />
ORDER BY Distance;</p>
<p>/* StoreLocation table definition */<br />
CREATE TABLE StoreLocation (<br />
store_id INT NOT NULL AUTO_INCREMENT<br />
, address VARCHAR(100) NOT NULL<br />
, city VARCHAR(35) NOT NULL<br />
, state CHAR(2) NOT NULL<br />
, zip VARCHAR(6) NOT NULL<br />
, PRIMARY KEY (store_id)<br />
, KEY (zip));</p>
<p><strong>/* zip codes within a given radius  with StoreLocation table*/</strong><br />
SELECT<br />
address<br />
, city<br />
, state<br />
, zip<br />
FROM StoreLocation<br />
WHERE zip IN (<br />
SELECT x2.zcta<br />
FROM ZCTA x1, ZCTA x2<br />
WHERE x1.zcta = &#8217;21236&#8242;<br />
AND ACOS(SIN(x1.lat_radians) * SIN(x2.lat_radians)<br />
+ COS(x1.lat_radians) * COS(x2.lat_radians)<br />
* COS(x2.long_radians &#8211; x1.long_radians)) * 3956 &lt;= 5<br />
);</p>
<p>SELECT<br />
address<br />
, city<br />
, state<br />
, zip<br />
FROM StoreLocation s1<br />
INNER JOIN (<br />
SELECT x2.zcta<br />
FROM ZCTA x1, ZCTA x2<br />
WHERE x1.zcta = &#8217;21236&#8242;<br />
AND ACOS(SIN(x1.lat_radians) * SIN(x2.lat_radians)<br />
+ COS(x1.lat_radians) * COS(x2.lat_radians)<br />
* COS(x2.long_radians &#8211; x1.long_radians)) * 3956 &lt;= 5<br />
) AS zips<br />
ON s1.zip = zips.zcta;</p>
<p>SELECT<br />
address<br />
, city<br />
, state<br />
, zip<br />
FROM ZCTA x1, ZCTA x2<br />
INNER JOIN StoreLocation s1<br />
ON x2.zcta = s1.zip<br />
WHERE x1.zcta = &#8217;21236&#8242;<br />
AND ACOS(SIN(x1.lat_radians) * SIN(x2.lat_radians)<br />
+ COS(x1.lat_radians) * COS(x2.lat_radians)<br />
* COS(x2.long_radians &#8211; x1.long_radians)) * 3956 &lt;= 5;</p>
<p>SELECT<br />
address<br />
, city<br />
, state<br />
, zip<br />
, ROUND(ACOS(SIN(x1.lat_radians) * SIN(x2.lat_radians)<br />
+ COS(x1.lat_radians) * COS(x2.lat_radians)<br />
* COS(x2.long_radians &#8211; x1.long_radians)) * 3956, 2) AS &#8220;Distance&#8221;<br />
FROM ZCTA x1, ZCTA x2<br />
INNER JOIN StoreLocation s1<br />
ON x2.zcta = s1.zip<br />
WHERE x1.zcta = &#8217;21236&#8242;<br />
AND ACOS(SIN(x1.lat_radians) * SIN(x2.lat_radians)<br />
+ COS(x1.lat_radians) * COS(x2.lat_radians)<br />
* COS(x2.long_radians &#8211; x1.long_radians)) * 3956 &lt;= 5<br />
ORDER BY Distance;</p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2009/08/17/calculating-distances-with-geographic-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interview questions</title>
		<link>http://technote.wsjoung.com/2008/02/06/amazon-interview/</link>
		<comments>http://technote.wsjoung.com/2008/02/06/amazon-interview/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 17:33:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Interview]]></category>
		<category><![CDATA[Linked List]]></category>

		<guid isPermaLink="false">http://wsjoung.wordpress.com/?p=76</guid>
		<description><![CDATA[what&#8217;s difference C++ and java explain about java static is java use call by reference or call by value get the algorithm to fine nth value from the last element in single linked list, and write code all questions look pretty easy though, anyway, the last algorithm question. because it&#8217;s just one direction single linked [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li>what&#8217;s difference C++ and java</li>
<li>explain about java static</li>
<li>is java use call by reference or call by value</li>
<li>get the algorithm to fine nth value from the last element in single linked list, and write code</li>
</ul>
<p>all questions look pretty easy though,</p>
<p>anyway, the last algorithm question. because it&#8217;s just one direction single linked list, we should travel from the start node to the last node. then we figure it out how many elements in that linked list when we reached the last element. then we can simply travel again from the start node to (m-n)th element. complexity is O(n).<br />
I was trying to bring up some other data structure like stack or hash table but, all those are not good  in terms of space efficiency. we do not have to wast precious resource which doesn&#8217;t increase the performance that much.</p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2008/02/06/amazon-interview/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tomasulo&#039;s Algorithm</title>
		<link>http://technote.wsjoung.com/2006/11/17/tomasulos-algorithm/</link>
		<comments>http://technote.wsjoung.com/2006/11/17/tomasulos-algorithm/#comments</comments>
		<pubDate>Fri, 17 Nov 2006 01:02:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Archietecture]]></category>
		<category><![CDATA[System]]></category>

		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/17/tomasulos-algorithm/</guid>
		<description><![CDATA[An Efficient Algorithm for Exploiting Multiple Arithmetic Units, R. M. Tomasulo, IBM Journal, January 1967 instructions and it&#8217;s execution plan would be like this. div Rg, Rb, Rc add Rh, Rg, Rd (data hazard) mul Rg, Re, Rf add Ra, Rh, Rg (data hazard) then, we should maintain RS(Reservation Station) for 2nd and 4th instructions [...]]]></description>
			<content:encoded><![CDATA[<p>An Efficient Algorithm for Exploiting Multiple Arithmetic Units, R. M. Tomasulo, IBM Journal, January 1967</p>
<p>instructions and it&#8217;s execution plan would be like this.</p>
<p>div     Rg, Rb, Rc<br />
add    Rh, Rg, Rd    (data hazard)<br />
mul    Rg, Re, Rf<br />
add    Ra, Rh, Rg    (data hazard)</p>
<p align="center"><a title="106670243_bb27bd269b.jpg" href="http://wsjoung.files.wordpress.com/2006/11/106670243_bb27bd269b.jpg"><img src="http://wsjoung.files.wordpress.com/2006/11/106670243_bb27bd269b.jpg" alt="106670243_bb27bd269b.jpg" /></a></p>
<p>then, we should maintain RS(Reservation Station) for 2nd and 4th instructions because those instruction need to wait for previous result. and, RS may look like this. source operands of the 1st instruction are ready and the result would be tagged T1 for register Rg and then put this tag T1 and mark busy bit into register till the result comes out. but the first operand of 2nd instruction is not ready when this instruction decode. it need to wait for Rg which is tagged for T1 by previous instruction. by looking up the register, we can figure out. if busy bit is set, the register is not available. so, we should wait for this tagged result.</p>
<table border="1">
<tbody>
<tr>
<td>Ready</td>
<td>Tag</td>
<td>Contents</td>
<td>Ready</td>
<td>Tag</td>
<td>Contents</td>
<td>Register</td>
</tr>
<tr>
<td>Y</td>
<td></td>
<td>Rb</td>
<td>Y</td>
<td></td>
<td>Rc</td>
<td>T1</td>
</tr>
<tr>
<td>N</td>
<td>T1</td>
<td></td>
<td>Y</td>
<td></td>
<td>Rd</td>
<td>T2</td>
</tr>
<tr>
<td>Y</td>
<td></td>
<td>Re</td>
<td>Y</td>
<td></td>
<td>Rf</td>
<td>T3</td>
</tr>
<tr>
<td>N</td>
<td>T2</td>
<td></td>
<td>N</td>
<td>T3</td>
<td></td>
<td>T4</td>
</tr>
</tbody>
</table>
<p>RS and register will watch the result bus to get tagged result. for this example, we will get T1 first then 2nd instruction will be ready to go. when we got 2nd tagged result(T3), left operand of 4th instruction will be ready and the busy bit of the register Rg will be marked free(N).</p>
<table border="1">
<tbody>
<tr>
<td>busy</td>
<td>Tab</td>
<td>register</td>
</tr>
<tr>
<td>Y</td>
<td>T4</td>
<td>Ra</td>
</tr>
<tr>
<td>Y</td>
<td>T2</td>
<td>Rh</td>
</tr>
<tr>
<td>N</td>
<td>T3</td>
<td>Rg</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2006/11/17/tomasulos-algorithm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>3D Rotation(and Align) about an arbitrary axis</title>
		<link>http://technote.wsjoung.com/2006/11/17/34/</link>
		<comments>http://technote.wsjoung.com/2006/11/17/34/#comments</comments>
		<pubDate>Fri, 17 Nov 2006 00:46:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[Rotation]]></category>

		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/17/34/</guid>
		<description><![CDATA[we need several steps to do this job. 1. translate to origin 2. rotate Z 3. rotate Y Z-Axis Rotation x&#8217; = x*cos q &#8211; y*sin q y&#8217; = x*sin q + y*cos q z&#8217; = z X-Axis Rotation y&#8217; = y*cos q &#8211; z*sin q z&#8217; = y*sin q + z*cos q x&#8217; = [...]]]></description>
			<content:encoded><![CDATA[<p>we need several steps to do this job.<br />
1. translate to origin<br />
2. rotate Z<br />
3. rotate Y</p>
<p align="center"><a title="64819260_50a870c49c.jpg" href="http://wsjoung.files.wordpress.com/2006/11/64819260_50a870c49c.jpg"><img src="http://wsjoung.files.wordpress.com/2006/11/64819260_50a870c49c.jpg" alt="64819260_50a870c49c.jpg" /></a></p>
<p><strong>Z-Axis Rotation</strong><br />
x&#8217; = x*cos q &#8211; y*sin q<br />
y&#8217; = x*sin q + y*cos q<br />
z&#8217; = z</p>
<p><strong>X-Axis Rotation</strong><br />
y&#8217; = y*cos q &#8211; z*sin q<br />
z&#8217; = y*sin q + z*cos q<br />
x&#8217; = x</p>
<p><strong>Y-Axis Rotation</strong><br />
z&#8217; = z*cos q &#8211; x*sin q<br />
x&#8217; = z*sin q + x*cos q<br />
y&#8217; = y</p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2006/11/17/34/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Comparative Protein Modeling</title>
		<link>http://technote.wsjoung.com/2006/11/17/comparative-protein-modeling/</link>
		<comments>http://technote.wsjoung.com/2006/11/17/comparative-protein-modeling/#comments</comments>
		<pubDate>Fri, 17 Nov 2006 00:44:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Bioinformatics]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Modeling]]></category>

		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/17/comparative-protein-modeling/</guid>
		<description><![CDATA[Once we figure out the protein sequence, then how we can figure out its 3D structure? There are two kinds of methods. Physical and empirical methods. The physical prediction methods are based on interactions between atoms and include molecular dynamics and energy minimization, whereas the empirical methods depend on the protein structures that have been [...]]]></description>
			<content:encoded><![CDATA[<p>Once we figure out the protein sequence, then how we can figure out its 3D structure?<br />
There are two kinds of methods. Physical and empirical methods. The physical prediction methods are based on interactions between atoms and include molecular dynamics and energy minimization, whereas the empirical methods depend on the protein structures that have been already determined by experiments.<br />
A comparative protein modeling method designed to find the most probable structure for a sequence given its alignment with related structures. 3D model is obtained by optimally satisfying spatial restraints derived from the alignment and expressed as probability density functions for the features restrained.</p>
<p><a title="Evolution and Physics in comparative protein structure modeling.pdf" href="http://wsjoung.files.wordpress.com/2006/11/evolution-and-physics-in-comparative-protein-structure-modeling.pdf">Evolution and Physics in comparative protein structure modeling.pdf</a><br />
<a title="Comparative_Protein_Modeling.pdf" href="http://wsjoung.files.wordpress.com/2006/11/comparative_protein_modeling.pdf">Comparative_Protein_Modeling.pdf</a></p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2006/11/17/comparative-protein-modeling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error Detection and Correction:</title>
		<link>http://technote.wsjoung.com/2006/11/17/error-detection-and-correction/</link>
		<comments>http://technote.wsjoung.com/2006/11/17/error-detection-and-correction/#comments</comments>
		<pubDate>Fri, 17 Nov 2006 00:33:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Error]]></category>

		<guid isPermaLink="false">http://wsjoung.wordpress.com/2006/11/17/error-detection-and-correction/</guid>
		<description><![CDATA[Everyone knows that it is easy to make mistakes when lots of numbers are involved &#8211; and I&#8217;m not talking about all those slip-ups that occur in exams. It is so easy to get a few digits of a bank account number mixed up, or for fingers to slip on a keyboard and enter the [...]]]></description>
			<content:encoded><![CDATA[<p>Everyone knows that it is easy to make mistakes when lots of numbers are involved &#8211; and I&#8217;m not talking about all those slip-ups that occur in exams. It is so easy to get a few digits of a bank account number mixed up, or for fingers to slip on a keyboard and enter the wrong numbers. Imagine the consequences of these errors: things might go your way, you might get access to Bill Gates&#8217;s bank account, for example, but the chances of that are relatively slim. Alternatively, if a bar code gets printed wrongly, you might end up paying the price of a bottle of champagne for your carton of apple juice or if the number on your airline ticket is wrong, who knows where you or your luggage might end up? Luckily, there are schemes in place to detect, and in some cases even correct, such errors almost immediately.<a title="Error Detection and Correction" href="http://wsjoung.files.wordpress.com/2006/11/errordetectionandcorrection.pdf"></a></p>
<p><a title="Error Detection and Correction" href="http://wsjoung.files.wordpress.com/2006/11/errordetectionandcorrection.pdf">Error Detection and Correction</a></p>
]]></content:encoded>
			<wfw:commentRss>http://technote.wsjoung.com/2006/11/17/error-detection-and-correction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
