<?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>TechPitcher &#187; Algorithm</title>
	<atom:link href="http://www.techpitcher.com/category/algorithm/feed" rel="self" type="application/rss+xml" />
	<link>http://www.techpitcher.com</link>
	<description></description>
	<lastBuildDate>Sat, 29 May 2010 13:50:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Implement a stack?</title>
		<link>http://www.techpitcher.com/implement-a-stack.html</link>
		<comments>http://www.techpitcher.com/implement-a-stack.html#comments</comments>
		<pubDate>Fri, 04 Jul 2008 18:38:53 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[J2ee]]></category>

		<guid isPermaLink="false">http://techpitcher.com/?p=28</guid>
		<description><![CDATA[A stack is an ordered list in which all insertions and deletions are made at one end, called the top. We can picture a stack as in the following figure.

The last element inserted is the first element deleted. Thus E is deleted before D because E was inserted after D. For this reason a stack [...]]]></description>
			<content:encoded><![CDATA[<p>A stack is an ordered list in which all insertions and deletions are made at one end, called the top. We can picture a stack as in the following figure.<br />
<img src="http://techpitcher.com/img/stack.jpg" alt="Stack" /><br />
The last element inserted is the first element deleted. Thus E is deleted before D because E was inserted after D. For this reason a stack is sometime called last-in, first-out (LIFO). Implementation of stack in Java</p>
<pre class="brush: java;">
public class MyStack extends Vector {
/**
* Constructor creates an empty stack
*/
public MyStack() {
}

/**
* Pushes an Object onto the top of the stack
*/
public Object push(Object item) {
addElement(item);
return item;
}

/**
* Pops an item from the stack and returns it.  The item popped is
* removed from the Stack.
*/
public Object pop() {
if (isEmpty()) {
throw new EmptyStackException();
}
Object item = elementData[--elementCount];
// Release memory used by this element
elementData[elementCount] = null;
return item;
}

/**
* Returns the top Object on the stack without removing it.
*/
public Object peek() {
if (isEmpty()) {
throw new EmptyStackException();
}
return elementData[elementCount - 1];
}

/**
* Check if the stack is empty.
*/
public boolean isEmpty() {
return elementCount == 0;
}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.techpitcher.com/implement-a-stack.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Create a random number between 1 to 10 excluding 3, 5, and 9.?</title>
		<link>http://www.techpitcher.com/create-a-random-number-between-1-to-10-excluding-3-5-and-9.html</link>
		<comments>http://www.techpitcher.com/create-a-random-number-between-1-to-10-excluding-3-5-and-9.html#comments</comments>
		<pubDate>Sun, 04 May 2008 18:35:15 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Algorithm]]></category>

		<guid isPermaLink="false">http://techpitcher.com/?p=27</guid>
		<description><![CDATA[This could be done by creating a random number and checking it if it doesn&#8217;t belong to 3, 5 and 9.

Random random=new Random();
int intVal=random.nextInt(11);
while(intVal==3 &#124;&#124; intVal==5 &#124;&#124; intVal==9){
intVal=random.nextInt(11);
}
System.out.println(intVal);

Secondly we can have an array initialized with [1,2,4,6,7,8,10] and now generate a number between 0 to 6 and return the element corresponding to that index.
]]></description>
			<content:encoded><![CDATA[<p>This could be done by creating a random number and checking it if it doesn&#8217;t belong to 3, 5 and 9.</p>
<pre class="brush: java;">
Random random=new Random();
int intVal=random.nextInt(11);
while(intVal==3 || intVal==5 || intVal==9){
intVal=random.nextInt(11);
}
System.out.println(intVal);
</pre>
<p>Secondly we can have an array initialized with [1,2,4,6,7,8,10] and now generate a number between 0 to 6 and return the element corresponding to that index.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techpitcher.com/create-a-random-number-between-1-to-10-excluding-3-5-and-9.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>You are given a list of n numbers from 1 to n-1, with one of the numbers repeated. Findout the repeated number?</title>
		<link>http://www.techpitcher.com/you-are-given-a-list-of-n-numbers-from-1-to-n-1-with-one-of-the-numbers-repeated-findout-the-repeated-number.html</link>
		<comments>http://www.techpitcher.com/you-are-given-a-list-of-n-numbers-from-1-to-n-1-with-one-of-the-numbers-repeated-findout-the-repeated-number.html#comments</comments>
		<pubDate>Mon, 14 Apr 2008 18:33:49 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Algorithm]]></category>

		<guid isPermaLink="false">http://techpitcher.com/?p=26</guid>
		<description><![CDATA[Sum of all the distinct numbers from 1 to n-1 in the list will be n*(n-1)/2. Findout total sum of the given list. Now subtract n*(n-1)/2 from the list sum. Result will be the repeated number.
]]></description>
			<content:encoded><![CDATA[<p>Sum of all the distinct numbers from 1 to n-1 in the list will be n*(n-1)/2. Findout total sum of the given list. Now subtract n*(n-1)/2 from the list sum. Result will be the repeated number.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techpitcher.com/you-are-given-a-list-of-n-numbers-from-1-to-n-1-with-one-of-the-numbers-repeated-findout-the-repeated-number.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Write an algorithm to find loop in a linked list?</title>
		<link>http://www.techpitcher.com/write-an-algorithm-to-find-loop-in-a-linked-list.html</link>
		<comments>http://www.techpitcher.com/write-an-algorithm-to-find-loop-in-a-linked-list.html#comments</comments>
		<pubDate>Thu, 06 Mar 2008 18:32:53 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Algorithm]]></category>

		<guid isPermaLink="false">http://techpitcher.com/?p=25</guid>
		<description><![CDATA[Start with two pointers (ptr1 and ptr2), both pointing to the first node of the given list. Now traverse the linked list with ptr1 two nodes forward and ptr2 one node forward. Stop when ptr1 reaches to end of linked list or both the pointers pointing to same node i.e. ptr1 = ptr2.
1.	Ptr1 = ptr2 [...]]]></description>
			<content:encoded><![CDATA[<p>Start with two pointers (ptr1 and ptr2), both pointing to the first node of the given list. Now traverse the linked list with ptr1 two nodes forward and ptr2 one node forward. Stop when ptr1 reaches to end of linked list or both the pointers pointing to same node i.e. ptr1 = ptr2.<br />
1.	Ptr1 = ptr2 then linked list contain loop.<br />
2.	If ptr1 reached end of the list that means list doesn&#8217;t contains loop.</p>
<p>There can be other solution for this problem if we are allowed to change structure of list node. We can add marker field to each node and start traversing the list from beginning and as soon as we visit a node, we&#8217;ll mark the field as &#8216;visited&#8217;. If we find any node with marker field as &#8216;visited&#8217; that means list contains loop.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techpitcher.com/write-an-algorithm-to-find-loop-in-a-linked-list.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Write a function to reverse the words in a string? (e.g. &#8220;Your time has come&#8221; &#8211; &gt; &#8220;come has time Your&#8221;)</title>
		<link>http://www.techpitcher.com/write-a-function-to-reverse-the-words-in-a-string-eg-your-time-has-come-come-has-time-your.html</link>
		<comments>http://www.techpitcher.com/write-a-function-to-reverse-the-words-in-a-string-eg-your-time-has-come-come-has-time-your.html#comments</comments>
		<pubDate>Fri, 08 Feb 2008 18:30:15 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Algorithm]]></category>

		<guid isPermaLink="false">http://techpitcher.com/?p=24</guid>
		<description><![CDATA[This could be achieved by first writing a function to reverse the whole string. The output from this function will be.. &#8220;emoc sah emit ruoY&#8221;. Now we need to call same function for each individual word. So the final output will be &#8220;come has time Your&#8221;
]]></description>
			<content:encoded><![CDATA[<p>This could be achieved by first writing a function to reverse the whole string. The output from this function will be.. &#8220;emoc sah emit ruoY&#8221;. Now we need to call same function for each individual word. So the final output will be &#8220;come has time Your&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techpitcher.com/write-a-function-to-reverse-the-words-in-a-string-eg-your-time-has-come-come-has-time-your.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
