tag:blogger.com,1999:blog-20767023344257377542024-03-13T08:10:17.430-07:00learn with me : Krishna K"Learning Algorithms in Java"Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.comBlogger48125tag:blogger.com,1999:blog-2076702334425737754.post-270312363590406132017-06-16T22:28:00.000-07:002017-06-16T22:34:51.731-07:00Graph Problem based on Traversal (DFS) | Hackerrank : Roads and Libraries<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
<br />
I am here with an problem based on Graphs. This I took from Hacker rank <a href="https://www.hackerrank.com/challenges/torque-and-development">https://www.hackerrank.com/challenges/torque-and-development</a><br />
<br />
The Problem summary is as follows.<br />
<br />
<b>Input and the problem Summary </b><br />
<ol style="text-align: left;">
<li>There are n cites. </li>
<li>Each city must either have a library or be connected directly or indirectly via another city to a city having a library.</li>
<li>There are <b>only m roads </b>which can be build. These m paths are provided in the questions and represented by pair <span style="color: blue;"><b>(city1,city2)</b> : path connecting city1 and city2 directly.</span></li>
<li><span style="color: blue;"> <span style="color: black;">Cost of building the library is given as a part of input. (Big number between 1 and 10^5)</span></span></li>
<li><span style="color: blue;"><span style="color: black;">Cost of building road between any two cities is constant and is also given as a part of input. </span></span><br /><span style="color: blue;"><span style="color: black;"> (Big number between 1 and 10^5)</span></span></li>
</ol>
<span style="color: blue;"><span style="color: black;"><b>Output</b></span></span><br />
<br />
<span style="color: blue;"><span style="color: black;">Minimum cost to make each city accessible to Library.<b> </b></span></span><br />
<br />
<span style="color: blue;"><span style="color: black;"><b>Here is the code in Java for above problem:</b></span></span><br />
<br />
<br />
<span style="color: blue;"><span style="color: black;"><!-- HTML generated using hilite.me --><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.io.*</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.*</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Solution</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
Scanner in <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Scanner<span style="color: #333333;">(</span>System<span style="color: #333333;">.</span><span style="color: #0000cc;">in</span><span style="color: #333333;">);</span>
<span style="color: #333399; font-weight: bold;">int</span> q <span style="color: #333333;">=</span> in<span style="color: #333333;">.</span><span style="color: #0000cc;">nextInt</span><span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> a0 <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> a0 <span style="color: #333333;"><</span> q<span style="color: #333333;">;</span> a0<span style="color: #333333;">++){</span>
<span style="color: #333399; font-weight: bold;">int</span> n <span style="color: #333333;">=</span> in<span style="color: #333333;">.</span><span style="color: #0000cc;">nextInt</span><span style="color: #333333;">();</span>
<span style="color: #333399; font-weight: bold;">int</span> m <span style="color: #333333;">=</span> in<span style="color: #333333;">.</span><span style="color: #0000cc;">nextInt</span><span style="color: #333333;">();</span>
<span style="color: #333399; font-weight: bold;">long</span> x <span style="color: #333333;">=</span> in<span style="color: #333333;">.</span><span style="color: #0000cc;">nextLong</span><span style="color: #333333;">();</span> <span style="color: #888888;">// lib</span>
<span style="color: #333399; font-weight: bold;">long</span> y <span style="color: #333333;">=</span> in<span style="color: #333333;">.</span><span style="color: #0000cc;">nextLong</span><span style="color: #333333;">();</span> <span style="color: #888888;">// road</span>
Graph g <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Graph<span style="color: #333333;">(</span>n<span style="color: #333333;">,</span>m<span style="color: #333333;">,</span>x<span style="color: #333333;">,</span>y<span style="color: #333333;">);</span>
g<span style="color: #333333;">.</span><span style="color: #0000cc;">addSingleNodes</span><span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> a1 <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> a1 <span style="color: #333333;"><</span> m<span style="color: #333333;">;</span> a1<span style="color: #333333;">++){</span>
<span style="color: #333399; font-weight: bold;">int</span> city_1 <span style="color: #333333;">=</span> in<span style="color: #333333;">.</span><span style="color: #0000cc;">nextInt</span><span style="color: #333333;">();</span>
<span style="color: #333399; font-weight: bold;">int</span> city_2 <span style="color: #333333;">=</span> in<span style="color: #333333;">.</span><span style="color: #0000cc;">nextInt</span><span style="color: #333333;">();</span>
g<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span>city_1<span style="color: #333333;">,</span>city_2<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>g<span style="color: #333333;">.</span><span style="color: #0000cc;">computeCost</span><span style="color: #333333;">());</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Graph</span><span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">long</span> costRoad<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">long</span> costLib<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> n<span style="color: #333333;">,</span>m<span style="color: #333333;">;</span>
Graph<span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> n<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> m <span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">long</span> costLib<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">long</span> costRoad<span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">costRoad</span> <span style="color: #333333;">=</span> costRoad<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">costLib</span> <span style="color: #333333;">=</span> costLib<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">n</span> <span style="color: #333333;">=</span> n<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">m</span> <span style="color: #333333;">=</span> m<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Node</span><span style="color: #333333;">{</span>
Integer name<span style="color: #333333;">;</span>
AdjListNode listHead<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">boolean</span> isVisited<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Node</span><span style="color: #333333;">(</span>Integer name<span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">name</span> <span style="color: #333333;">=</span> name<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">AdjListNode</span><span style="color: #333333;">{</span>
AdjListNode next<span style="color: #333333;">;</span>
Node adj<span style="color: #333333;">;</span>
AdjListNode<span style="color: #333333;">(</span>Node adj<span style="color: #333333;">,</span> AdjListNode next<span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">adj</span> <span style="color: #333333;">=</span> adj<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">next</span> <span style="color: #333333;">=</span> next<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
Map<span style="color: #333333;"><</span>Integer<span style="color: #333333;">,</span>Node<span style="color: #333333;">></span> nameNodeMap <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> HashMap<span style="color: #333333;"><>();</span>
<span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addEdge</span><span style="color: #333333;">(</span>Integer c1<span style="color: #333333;">,</span> Integer c2<span style="color: #333333;">){</span>
Node n1 <span style="color: #333333;">=</span> nameNodeMap<span style="color: #333333;">.</span><span style="color: #0000cc;">get</span><span style="color: #333333;">(</span>c1<span style="color: #333333;">);</span>
Node n2 <span style="color: #333333;">=</span> nameNodeMap<span style="color: #333333;">.</span><span style="color: #0000cc;">get</span><span style="color: #333333;">(</span>c2<span style="color: #333333;">);</span>
n1<span style="color: #333333;">.</span><span style="color: #0000cc;">listHead</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> AdjListNode<span style="color: #333333;">(</span>n2<span style="color: #333333;">,</span>n1<span style="color: #333333;">.</span><span style="color: #0000cc;">listHead</span><span style="color: #333333;">);</span>
n2<span style="color: #333333;">.</span><span style="color: #0000cc;">listHead</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> AdjListNode<span style="color: #333333;">(</span>n1<span style="color: #333333;">,</span>n2<span style="color: #333333;">.</span><span style="color: #0000cc;">listHead</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addSingleNodes</span><span style="color: #333333;">(){</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span>Integer i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><=</span> n<span style="color: #333333;">;</span> i<span style="color: #333333;">++){</span>
nameNodeMap<span style="color: #333333;">.</span><span style="color: #0000cc;">put</span><span style="color: #333333;">(</span>i<span style="color: #333333;">,</span><span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">(</span>i<span style="color: #333333;">));</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333399; font-weight: bold;">long</span> <span style="color: #0066bb; font-weight: bold;">computeCost</span><span style="color: #333333;">(){</span>
<span style="color: #333399; font-weight: bold;">long</span> answer <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>costLib <span style="color: #333333;"><=</span> costRoad<span style="color: #333333;">){</span>
answer <span style="color: #333333;">=</span> n<span style="color: #333333;">*</span>costLib<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">return</span> answer<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span>Node node <span style="color: #333333;">:</span> nameNodeMap<span style="color: #333333;">.</span><span style="color: #0000cc;">values</span><span style="color: #333333;">()){</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(!</span>node<span style="color: #333333;">.</span><span style="color: #0000cc;">isVisited</span><span style="color: #333333;">){</span>
answer <span style="color: #333333;">+=</span> dfs<span style="color: #333333;">(</span>node<span style="color: #333333;">)-</span>costRoad <span style="color: #333333;">+</span> costLib<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> answer<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333399; font-weight: bold;">long</span> <span style="color: #0066bb; font-weight: bold;">dfs</span><span style="color: #333333;">(</span>Node node<span style="color: #333333;">){</span>
AdjListNode temp <span style="color: #333333;">=</span> node<span style="color: #333333;">.</span><span style="color: #0000cc;">listHead</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">long</span> cost <span style="color: #333333;">=</span> costRoad<span style="color: #333333;">;</span>
node<span style="color: #333333;">.</span><span style="color: #0000cc;">isVisited</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">while</span><span style="color: #333333;">(</span>temp <span style="color: #333333;">!=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(!</span>temp<span style="color: #333333;">.</span><span style="color: #0000cc;">adj</span><span style="color: #333333;">.</span><span style="color: #0000cc;">isVisited</span><span style="color: #333333;">){</span>
cost <span style="color: #333333;">+=</span> dfs<span style="color: #333333;">(</span>temp<span style="color: #333333;">.</span><span style="color: #0000cc;">adj</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
temp <span style="color: #333333;">=</span> temp<span style="color: #333333;">.</span><span style="color: #0000cc;">next</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> cost<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /><b> </b></span></span><br />
<span style="color: blue;"><span style="color: black;"><b> </b></span></span><br />
<span style="color: blue;"><span style="color: black;"><b> ** Make Sure we initialize all the vertices (nodes) of the graph. This should be <span style="color: blue;">independent </span>of edge adding logic as<span style="color: blue;"> the input edges may not contain all the </span></b></span></span><span style="color: blue;"><span style="color: black;"><b><span style="color: blue;"><span style="color: blue;"><span style="color: black;"><b>vertices </b></span></span></span>, there may be nodes which are not connected to any other vertices.</b> </span></span></div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-84435010714251363722017-06-11T12:52:00.001-07:002017-06-11T13:01:57.332-07:00TRIE based java solution for Hacker rank : good set, bad set problem.<div dir="ltr" style="text-align: left;" trbidi="on">
Hi Friends,<br />
<br />
I am here with a problem, which is based on the <span style="color: blue;">No Prefix Set<span style="color: black;">. It is about a set of input strings and we are supposed to find out if any string in the set is prefix of any other one in the string. </span></span><br />
<br />
<span style="color: blue;"><span style="color: black;">We are given N strings, we have to print "GOOD SET" if none of the strings in the set are prefix of any other string in the set. </span></span><br />
<span style="color: blue;"><span style="color: black;">If any string is a prefix of any other string in the set then we are supposed to print "BAD SET" followed by the FIRST string for which such condition is detected in the set.</span></span><br />
<br />
<span style="color: blue;"><span style="color: black;">Link for the problem is : <a href="https://www.hackerrank.com/challenges/no-prefix-set">https://www.hackerrank.com/challenges/no-prefix-set</a></span></span><br />
<br />
<span style="color: blue;"><span style="color: black;">Please find below the TRIE based java solution for the same.</span></span><br />
<br />
<span style="color: blue;"><span style="color: black;"><!-- HTML generated using hilite.me --><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.HashMap</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.Map</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.Scanner</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Solution</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #888888;">/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */</span>
Scanner sc <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Scanner<span style="color: #333333;">(</span>System<span style="color: #333333;">.</span><span style="color: #0000cc;">in</span><span style="color: #333333;">);</span>
<span style="color: #333399; font-weight: bold;">int</span> n <span style="color: #333333;">=</span> sc<span style="color: #333333;">.</span><span style="color: #0000cc;">nextInt</span><span style="color: #333333;">();</span>
sc<span style="color: #333333;">.</span><span style="color: #0000cc;">nextLine</span><span style="color: #333333;">();</span>
Node head <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> n <span style="color: #333333;">;</span> i<span style="color: #333333;">++){</span>
String line <span style="color: #333333;">=</span> sc<span style="color: #333333;">.</span><span style="color: #0000cc;">nextLine</span><span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(!</span>head<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span>line<span style="color: #333333;">)){</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"BAD SET"</span><span style="color: #333333;">);</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>line<span style="color: #333333;">);</span>
sc<span style="color: #333333;">.</span><span style="color: #0000cc;">close</span><span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">return</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"GOOD SET"</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">static</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Node</span><span style="color: #333333;">{</span>
Map<span style="color: #333333;"><</span>Character<span style="color: #333333;">,</span> Node<span style="color: #333333;">></span> map <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> HashMap<span style="color: #333333;"><>();</span>
<span style="color: #333399; font-weight: bold;">boolean</span> isComplete<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">add</span><span style="color: #333333;">(</span>String word<span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #0066bb; font-weight: bold;">add</span><span style="color: #333333;">(</span>word<span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">add</span><span style="color: #333333;">(</span>String word<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> index<span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>isComplete<span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>index <span style="color: #333333;">==</span> word<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">()){</span>
isComplete <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
Node child <span style="color: #333333;">=</span> map<span style="color: #333333;">.</span><span style="color: #0000cc;">get</span><span style="color: #333333;">(</span>word<span style="color: #333333;">.</span><span style="color: #0000cc;">charAt</span><span style="color: #333333;">(</span>index<span style="color: #333333;">));</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>child <span style="color: #333333;">==</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">){</span>
child <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">();</span>
map<span style="color: #333333;">.</span><span style="color: #0000cc;">put</span><span style="color: #333333;">(</span>word<span style="color: #333333;">.</span><span style="color: #0000cc;">charAt</span><span style="color: #333333;">(</span>index<span style="color: #333333;">),</span>child<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span><span style="color: #008800; font-weight: bold;">else</span> <span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>index <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">==</span> word<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">()){</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> child<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span>word<span style="color: #333333;">,</span>index<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /><br /> </span></span><span style="color: blue;"></span><br />
</div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-62081035643308298512017-06-11T12:02:00.001-07:002017-06-11T13:03:10.667-07:00Contacts problem from Hacker rank. Count the number of contacts with given prefix | TRIE data structure | Java Based Solution<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
<br />
I am today with you with yet another good programming challenge. I have taken this problem from Hackerrank. The link for the problem is : <a href="https://www.hackerrank.com/challenges/contacts">https://www.hackerrank.com/challenges/contacts</a><br />
<br />
It asks us to build an algorithm similar to the contacts application we have in our mobile phones.<br />
The operations we need to support are<br />
<br />
<ol style="text-align: left;">
<li><span style="color: blue;">add (String contact)</span> : The problem statement guarantees that always the contact will be unique</li>
<li><span style="color: blue;">count (String partial) : <span style="color: black;">Return all the number of contacts with prefix as partial. </span></span></li>
</ol>
<br />
<span style="color: blue;"><span style="color: black;">Friends for solving the problem optimally we will use TRIE data structure. Please find below my code for the same.</span></span><br />
<br />
<span style="color: blue;"><span style="color: black;"><!-- HTML generated using hilite.me --><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> hacker<span style="color: #333333;">.</span><span style="color: #0000cc;">rank</span><span style="color: #333333;">.</span><span style="color: #0000cc;">trie</span><span style="color: #333333;">.</span><span style="color: #0000cc;">contacts</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.HashMap</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.Map</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.Scanner</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Solution</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #888888;">/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */</span>
Scanner sc <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Scanner<span style="color: #333333;">(</span>System<span style="color: #333333;">.</span><span style="color: #0000cc;">in</span><span style="color: #333333;">);</span>
<span style="color: #333399; font-weight: bold;">int</span> n <span style="color: #333333;">=</span> sc<span style="color: #333333;">.</span><span style="color: #0000cc;">nextInt</span><span style="color: #333333;">();</span>
sc<span style="color: #333333;">.</span><span style="color: #0000cc;">nextLine</span><span style="color: #333333;">();</span>
Node head <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> n <span style="color: #333333;">;</span> i<span style="color: #333333;">++){</span>
String lines <span style="color: #333333;">=</span> sc<span style="color: #333333;">.</span><span style="color: #0000cc;">nextLine</span><span style="color: #333333;">();</span>
String<span style="color: #333333;">[]</span> commands <span style="color: #333333;">=</span> lines<span style="color: #333333;">.</span><span style="color: #0000cc;">split</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">" "</span><span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>commands<span style="color: #333333;">[</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">].</span><span style="color: #0000cc;">equals</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"add"</span><span style="color: #333333;">)){</span>
head<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span>commands<span style="color: #333333;">[</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]);</span>
<span style="color: #333333;">}</span><span style="color: #008800; font-weight: bold;">else</span><span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> answer <span style="color: #333333;">=</span> head<span style="color: #333333;">.</span><span style="color: #0000cc;">getCount</span><span style="color: #333333;">(</span>commands<span style="color: #333333;">[</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]);</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>answer<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">static</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Node</span><span style="color: #333333;">{</span>
Map<span style="color: #333333;"><</span>Character<span style="color: #333333;">,</span> Node<span style="color: #333333;">></span> map <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> HashMap<span style="color: #333333;"><>();</span>
<span style="color: #333399; font-weight: bold;">boolean</span> isComplete <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> count <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">add</span><span style="color: #333333;">(</span>String contact<span style="color: #333333;">){</span>
add<span style="color: #333333;">(</span>contact<span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">add</span><span style="color: #333333;">(</span>String contact<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> index<span style="color: #333333;">){</span>
count<span style="color: #333333;">++;</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>index <span style="color: #333333;">==</span> contact<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">()){</span>
isComplete <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">return</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
Node child <span style="color: #333333;">=</span> map<span style="color: #333333;">.</span><span style="color: #0000cc;">get</span><span style="color: #333333;">(</span>contact<span style="color: #333333;">.</span><span style="color: #0000cc;">charAt</span><span style="color: #333333;">(</span>index<span style="color: #333333;">));</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>child <span style="color: #333333;">==</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">){</span>
child <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">();</span>
map<span style="color: #333333;">.</span><span style="color: #0000cc;">put</span><span style="color: #333333;">(</span>contact<span style="color: #333333;">.</span><span style="color: #0000cc;">charAt</span><span style="color: #333333;">(</span>index<span style="color: #333333;">),</span>child<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
child<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span>contact<span style="color: #333333;">,</span>index<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">getCount</span><span style="color: #333333;">(</span>String partial<span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #0066bb; font-weight: bold;">getCount</span><span style="color: #333333;">(</span>partial<span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">getCount</span><span style="color: #333333;">(</span>String partial<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> index<span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>index <span style="color: #333333;">==</span> partial<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">()){</span>
<span style="color: #008800; font-weight: bold;">return</span> count<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
Node child <span style="color: #333333;">=</span> map<span style="color: #333333;">.</span><span style="color: #0000cc;">get</span><span style="color: #333333;">(</span>partial<span style="color: #333333;">.</span><span style="color: #0000cc;">charAt</span><span style="color: #333333;">(</span>index<span style="color: #333333;">));</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>child <span style="color: #333333;">==</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> child<span style="color: #333333;">.</span><span style="color: #0000cc;">getCount</span><span style="color: #333333;">(</span>partial<span style="color: #333333;">,</span> index<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /> </span></span><br />
</div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-2650280030196267252016-07-17T06:48:00.000-07:002016-07-17T12:44:07.124-07:00Vertical Level order traversal of Binary Tree. | Java solution<div dir="ltr" style="text-align: left;" trbidi="on">
Dear Friends,<br />
<br />
I am with you with a data structure and algorithmic problem based on Binary tree and Hashing.<br />
<br />
Given a binary tree we need to print the nodes according to vertical level ordering.<br />
<br />
<img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAloAAACqCAIAAAD6NHaNAAAZlElEQVR4nO3dT0gbf58H8Lk9HueYZdllbg0sSJ6DEELBgR6e0FN6y82wa4O49NGDPKQUG2iR2EJJKNj00CKFEikewtY+5vHSxP6yJogaEaulWodsaEKbbaeuyLQVmT2MjpNkEic6M9/J5P0iB0njzGfmxy9vv9/5/qFEAAA4x3yQoijKE9shXQgYhiJdAACApe3EPBQVnN+JeRCHtoY4BADQAHFod4hDAAANEId2hzgEANAAcWh3iEMAAA0Qh3aHOAQA0ABxaHeIQwAADRCHdoc4BABoSZpzeAahaE+IQwAAAMQhAAAA4hAAAEBEHAIAtFB4X0znttO57fTieunv/+DTaelFui7QH+IQAKBGbm038uSNL/jY0TfivHab9U+y/kn/X/761tW3zrLrLLvmdmcoap1l90KhajJ5xPOkSwYdIA4BAETh5+/kwmpg7Jmjb8R94344mkxlNvj9wxa/sp/LlaLRLb8/S9PrLFuKRgWOM6te0B/iEAC6mvDzd/T5gpSC8ZdvK19/XOAg31Kpj0NDWZre9PkOCgXdiwQT2C8Oy4mpgf7wwMQW6UIAwPK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+Z269uVijgEALCEg0LhQyAgfdfLL/Vm4nyQOhWcJ1Gr6X5VKtJfDMqb866nhwuHW94fT2xH6ykQhwAAFpJnmLpEbGgmzgdPU3An5umaQDxRl4gq90d5U85u1fkQhwAAFlL3XZ+hqE2fr3aLxPmg3Ohp5+veHt719NTdnw2vt+b+1NwTxb06D+IQAMAqBI6Tv+WlpU1VR1HOB6Ve0q4LwyOel+9PnmGKkYjKxM35oKKPtI1bhDgEALCK/VwuzzB7odC5g0ROno618WjMDg63t9/19HwIBOpmX9RRPFr1eDyIQwCATqNtcsVZ8+e0mdgtjni+zaVq0DoEALCr+mdj3ZSH7cJQGgAA21I+G9uJebqtw7QN7TWeEYcAAB1mJ+bptnmH7bjgrEzEIQAAAOIQAAAAcQgAACAiDgEAAETEIQAAgIg4BAAAEBGHAAAAIuIQAABARBwCAACIiEMAAAARcQgAACAiDgEAAETEIQAAgIg4BAAAEBGHAAAAIuIQAABARBwCAACIiEMAAAARcQgAACAiDgEAAETEIQAAgIg4BAAAEBGHAAAAIuIQAABARBwCAACIovj/tti2wzmMZmUAAAAASUVORK5CYII=" /><br />
<br />
For above Binary tree the vertical level ordering is as below<br />
<span style="color: red;"><b>4</b></span><br />
<span style="color: red;"><b>2</b></span><br />
<span style="color: red;"><b>1 5 6</b></span><br />
<span style="color: red;"><b>3 8</b></span><br />
<span style="color: red;"><b>7</b></span><br />
<span style="color: red;"><b>9</b></span><br />
<br />
<span style="color: red;"><span style="color: black;">Lets try to analyze the above binary tree </span></span><span style="color: red;"><span style="color: black;"> </span></span><br />
<ol style="text-align: left;">
<li><span style="color: red;"><span style="color: black;">Lets record the horizontal (left, right) distance of each node from root</span></span></li>
<li><span style="color: red;"><span style="color: black;">To record horizontal distance for a node from root , lets see as how many lefts and how many rights do we need to travel from root's horizontal position to reach the node's horizontal position.</span></span></li>
<li><span style="color: red;"><b> </b></span>Lets take 1 Left step as -1 and 1 Right step as +1. </li>
</ol>
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><br />
<!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="267">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:"Times New Roman";
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
table.MsoTableGrid
{mso-style-name:"Table Grid";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-priority:59;
mso-style-unhide:no;
border:solid black 1.0pt;
mso-border-themecolor:text1;
mso-border-alt:solid black .5pt;
mso-border-themecolor:text1;
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-border-insideh:.5pt solid black;
mso-border-insideh-themecolor:text1;
mso-border-insidev:.5pt solid black;
mso-border-insidev-themecolor:text1;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt;"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<b style="mso-bidi-font-weight: normal;">Node</b></div>
</td>
<td colspan="2" style="border-left: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 101.25pt;" width="135"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<b style="mso-bidi-font-weight: normal;">Horizontal
distance of Node from Root</b></div>
</td>
</tr>
<tr style="height: 7.15pt; mso-yfti-irow: 1;">
<td style="border-top: none; border: solid black 1.0pt; height: 7.15pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt;" valign="top"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="color: #0070c0;">Node
with value 1 (root)</span></b></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 7.15pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 29.25pt;" width="39"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="color: #002060;">0</span></b></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 7.15pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 1.0in;" width="96"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: blue;">Root => 0</span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 2;">
<td style="border-top: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt;" valign="top"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #00b0f0;">Node with value 2</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 29.25pt;" width="39"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="color: #002060;">-1</span></b></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 1.0in;" width="96"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: red;">0 + (-1) = <b>-1</b></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 3;">
<td style="border-top: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt;" valign="top"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #00b0f0;">Node with value 4</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 29.25pt;" width="39"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="color: #002060;">-2</span></b><span style="color: #002060;"></span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 1.0in;" width="96"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: red;">-1+(-1) = <b style="mso-bidi-font-weight: normal;">-2</b></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 4;">
<td style="border-top: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt;" valign="top"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #00b0f0;">Node with value 5</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 29.25pt;" width="39"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #002060;"><span style="mso-spacerun: yes;"> </span><b style="mso-bidi-font-weight: normal;">0</b></span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 1.0in;" width="96"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: red;">-1 + 1= <b style="mso-bidi-font-weight: normal;">0</b></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 5;">
<td style="border-top: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt;" valign="top"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #00b0f0;">Node with value 3</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 29.25pt;" width="39"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="color: #002060;">+1</span></b></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 1.0in;" width="96"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: red;">0 + 1 = <b>+1</b></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 6;">
<td style="border-top: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt;" valign="top"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #00b0f0;">Node with value 6</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 29.25pt;" width="39"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="color: #002060;">0</span></b><span style="color: #002060;"></span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 1.0in;" width="96"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: red;">+1 +(-1) = <b style="mso-bidi-font-weight: normal;">0</b></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 7;">
<td style="border-top: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt;" valign="top"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #00b0f0;">Node with value 8</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 29.25pt;" width="39"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="color: #002060;">+1</span></b><span style="color: #002060;"></span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 1.0in;" width="96"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: red;">0 +1 = <b style="mso-bidi-font-weight: normal;">+1</b></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 8;">
<td style="border-top: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt;" valign="top"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #00b0f0;">Node with value 7</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 29.25pt;" width="39"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="color: #002060;">+2</span></b><span style="color: #002060;"></span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 1.0in;" width="96"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: red;">+1 +1 = <b style="mso-bidi-font-weight: normal;">+2</b></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 9; mso-yfti-lastrow: yes;">
<td style="border-top: none; border: solid black 1.0pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt;" valign="top"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #00b0f0;">Node with value 9</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 29.25pt;" width="39"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="color: #002060;">+3</span></b><span style="color: #002060;"></span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 1.0in;" width="96"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: red;">2+1 = <b style="mso-bidi-font-weight: normal;">+3</b></span></div>
</td>
</tr>
</tbody></table>
<br />
With above analysis lets see the code in java for the solution of this problem.<br />
<br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> krishnalearnings<span style="color: #333333;">.</span><span style="color: #0000cc;">binarytree</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.ArrayList</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.List</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.Map</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.Set</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.TreeMap</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">VerticalLevelOrderTraversal</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Node</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">private</span> Node left<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> Node right<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> data<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Node</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> data<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">data</span> <span style="color: #333333;">=</span> data<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #888888;">// lets construct a tree</span>
Node root <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
Node node2 <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span>
Node node4 <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">);</span>
Node node5 <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">);</span>
Node node3 <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">);</span>
Node node6 <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">);</span>
Node node7 <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">7</span><span style="color: #333333;">);</span>
Node node8 <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">8</span><span style="color: #333333;">);</span>
Node node9 <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">9</span><span style="color: #333333;">);</span>
root<span style="color: #333333;">.</span><span style="color: #0000cc;">left</span> <span style="color: #333333;">=</span> node2<span style="color: #333333;">;</span>
root<span style="color: #333333;">.</span><span style="color: #0000cc;">right</span> <span style="color: #333333;">=</span> node3<span style="color: #333333;">;</span>
node2<span style="color: #333333;">.</span><span style="color: #0000cc;">left</span> <span style="color: #333333;">=</span> node4<span style="color: #333333;">;</span>
node2<span style="color: #333333;">.</span><span style="color: #0000cc;">right</span> <span style="color: #333333;">=</span> node5<span style="color: #333333;">;</span>
node3<span style="color: #333333;">.</span><span style="color: #0000cc;">left</span> <span style="color: #333333;">=</span> node6<span style="color: #333333;">;</span>
node3<span style="color: #333333;">.</span><span style="color: #0000cc;">right</span> <span style="color: #333333;">=</span> node7<span style="color: #333333;">;</span>
node6<span style="color: #333333;">.</span><span style="color: #0000cc;">right</span> <span style="color: #333333;">=</span> node8<span style="color: #333333;">;</span>
node7<span style="color: #333333;">.</span><span style="color: #0000cc;">right</span> <span style="color: #333333;">=</span> node9<span style="color: #333333;">;</span>
<span style="color: #888888;">// tree constructed</span>
printVerticalLevelOrder<span style="color: #333333;">(</span>root<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">printVerticalLevelOrder</span><span style="color: #333333;">(</span>Node root<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
TreeMap<span style="color: #333333;"><</span>Integer<span style="color: #333333;">,</span> List<span style="color: #333333;"><</span>Node<span style="color: #333333;">>></span> map <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> TreeMap<span style="color: #333333;"><>();</span>
initilizeMap<span style="color: #333333;">(</span>root<span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> map<span style="color: #333333;">);</span>
Set<span style="color: #333333;"><</span>Integer<span style="color: #333333;">></span> horizontalDistances <span style="color: #333333;">=</span> map<span style="color: #333333;">.</span><span style="color: #0000cc;">keySet</span><span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span>Integer distance <span style="color: #333333;">:</span> horizontalDistances<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span>Node node <span style="color: #333333;">:</span> map<span style="color: #333333;">.</span><span style="color: #0000cc;">get</span><span style="color: #333333;">(</span>distance<span style="color: #333333;">))</span> <span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">print</span><span style="color: #333333;">(</span>node<span style="color: #333333;">.</span><span style="color: #0000cc;">data</span> <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">" "</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">initilizeMap</span><span style="color: #333333;">(</span>Node root<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> horizontalDistance<span style="color: #333333;">,</span> Map<span style="color: #333333;"><</span>Integer<span style="color: #333333;">,</span> List<span style="color: #333333;"><</span>Node<span style="color: #333333;">>></span> map<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>root <span style="color: #333333;">!=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
List<span style="color: #333333;"><</span>Node<span style="color: #333333;">></span> list <span style="color: #333333;">=</span> map<span style="color: #333333;">.</span><span style="color: #0000cc;">get</span><span style="color: #333333;">(</span>horizontalDistance<span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>list <span style="color: #333333;">==</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
list <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> ArrayList<span style="color: #333333;"><>();</span>
map<span style="color: #333333;">.</span><span style="color: #0000cc;">put</span><span style="color: #333333;">(</span>horizontalDistance<span style="color: #333333;">,</span> list<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
list<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span>root<span style="color: #333333;">);</span>
initilizeMap<span style="color: #333333;">(</span>root<span style="color: #333333;">.</span><span style="color: #0000cc;">left</span><span style="color: #333333;">,</span> horizontalDistance <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> map<span style="color: #333333;">);</span>
initilizeMap<span style="color: #333333;">(</span>root<span style="color: #333333;">.</span><span style="color: #0000cc;">right</span><span style="color: #333333;">,</span> horizontalDistance <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> map<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-51120166431667489042016-07-16T13:07:00.000-07:002016-07-16T13:38:43.438-07:00Largest sub array with sum equal to zero | Solution in Java<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
<br />
I am here with another famous algorithmic problem.<br />
<br />
<span style="color: blue;">Given an Array of Integers, find the length of largest sub array such that the sum of the elements of the sub array is equal to zero. </span><br />
<br />
Points to ponder reading the problem statement.<br />
<ol style="text-align: left;">
<li>Array can contain negative elements, positive elements, zero.</li>
<li>Array with all elements greater than zero will have zero sized Sub-Array. </li>
<li>With two loops it can be solved with below<span data-dobid="hdw">. Its Time complexity is </span><span data-dobid="hdw">O(n<sup>2</sup>). It can be optimized to O(n) but lets first see the solution which comes simple to the mind.</span></li>
</ol>
<b><span data-dobid="hdw"> SOLUTION 1 with </span><span data-dobid="hdw">Time complexity is </span><span data-dobid="hdw">O(n<sup>2</sup>)</span></b><br />
<br />
<div>
<span data-dobid="hdw"></span><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span data-dobid="hdw"><span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">ZeroSubArrayMaxLength</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> array <span style="color: #333333;">=</span> <span style="color: #333333;">{-</span><span style="color: #0000dd; font-weight: bold;">12</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,-</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">10</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">};</span>
<span style="color: #333399; font-weight: bold;">int</span> result <span style="color: #333333;">=</span> maxLength<span style="color: #333333;">(</span>array<span style="color: #333333;">);</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>result<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">maxLength</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> array<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> N <span style="color: #333333;">=</span> array<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> sum <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> localLen <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> maxLen <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> N<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
sum <span style="color: #333333;">=</span> array<span style="color: #333333;">[</span>i<span style="color: #333333;">];</span>
localLen <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>sum <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">&&</span> maxLen <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
maxLen <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> j <span style="color: #333333;">=</span> i <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span> j <span style="color: #333333;"><</span> N<span style="color: #333333;">;</span> j<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
sum <span style="color: #333333;">=</span> sum <span style="color: #333333;">+</span> array<span style="color: #333333;">[</span>j<span style="color: #333333;">];</span>
localLen<span style="color: #333333;">++;</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>sum <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">&&</span> localLen <span style="color: #333333;">></span> maxLen<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
maxLen <span style="color: #333333;">=</span> localLen<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> maxLen<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></span></pre>
</div>
<span data-dobid="hdw">
<br /> </span></div>
<div>
<span data-dobid="hdw"></span></div>
<div>
<b><span data-dobid="hdw">Now lets try to design the optimized solution with time complexity of O(n). </span></b></div>
<div>
<span data-dobid="hdw"><br /></span></div>
<div>
<i><span data-dobid="hdw">Suppose there is a person who starts a business with zero savings and he records the total savings accumulated in his account each day. </span></i></div>
<div>
<i><span data-dobid="hdw">On <b>day 1</b> he records <span style="color: blue;"><b>S1</b></span>, on<b> day 2</b> he records <span style="color: blue;"><b>S2</b></span>. </span></i></div>
<div>
<i><span data-dobid="hdw">On <b>day 5</b> he losses the amount equal to sum of what he earned on <b>day 3</b> and <b>day 4</b>. </span></i></div>
<div>
<i><span data-dobid="hdw"><br /></span></i></div>
<div>
<i><span data-dobid="hdw"><span style="color: blue;">Quick Question!!</span> What is the total savings he records on <b>day 5</b> ?</span></i></div>
<div>
<i><span data-dobid="hdw"><span style="color: blue;">Answer :</span> <span style="color: blue;"><b>S2</b></span> (As day 3, day 4 and day 5 were actually resulted in 0 profit 0 loss.)</span></i></div>
<div>
</div>
<div>
<span data-dobid="hdw">Extending this idea, lets see below image:</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVHU_mDRTP5sxLFIXl_jNzOCTa2zt3z-G8m1-V01pY0r_QcaNilXiOCHXfnEIPPbLkra8jHD7SINHk3Gcolss3oBlH6gJsG2zBciScu6Ql_-MSKFFV5GnDbLSLzOkgyZJTHSylzvLP6VU/s1600/ZeroSubArrayMaxLength.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVHU_mDRTP5sxLFIXl_jNzOCTa2zt3z-G8m1-V01pY0r_QcaNilXiOCHXfnEIPPbLkra8jHD7SINHk3Gcolss3oBlH6gJsG2zBciScu6Ql_-MSKFFV5GnDbLSLzOkgyZJTHSylzvLP6VU/s1600/ZeroSubArrayMaxLength.png" /></a></div>
<br />
<br />
<span data-dobid="hdw">Extending the idea further lets see below Approach:</span></div>
<div>
<span data-dobid="hdw"><img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsMAAAHMCAIAAAC/UDJdAAAgAElEQVR4nO2dTarlttaGPaS0PZI7ArdrAt8E0vIM7qVGkNtxIxCodFOtBAoCu1NpFIS0ioJDIFzw15AtS7LkH23L0tJ+HorinH388y7tJeu1JFvNCAAAABBLk1sAAAAACAYnAQAAAPHgJAAAACAenAQAAADEg5MAAACAeHASAAAAEA9OAgAAAOLBSQAAAEA8OAkAAACIZ9dJDF3TNE03XHnSR982TdP2j9CfLj8jAAAAJKEwJ/Ho26Zp2xYrAQAAIIJTTmLomqbth7nbQDf27ueTR7AMg/5F9zqYm048+rZpukFtslgJdfy+m3ZwfjU6Mqa9HKeiD7fRFwIAAAAxnHYS8y9maz99brTq7o/2L6EWfegsK6CthHn81a+Pvp239FuG5WA4CQAAgIs57ySs9lz9Yn2+NNdnnYRxGHsL6/irX71HWH5yOzgAAADgOgpyEoGjuH9ZO4mpj8IeMJk3wkgAAAAkJJWTWA0m7DoJxw/4XIG55fp0zl/U8Zi9CQAAkJLrnIRncoSxrz23wTM+sfrIONBRJzF0zeov66mXzJMAAAC4jAv7JLrOfabD6GiYHu0ItfK+Nn7apht2RjeMJze6rlsZh9WWOAkAAIDLuOQdl+EpkHkpVRcAAEA11OwkUrxUCwAAAEwqdhIYCQAAgOSwghcAAADEg5MAAACAeHASAAAAEA9OAgAAAOLBSQAAAEA8OAkAAACIBycBAAAA8eAkAAAAIB6cBAAAAMSDkwAAAIB4cBIAAAAQD04CAAAA4sFJAAAAQDw4CQAAAIgHJwEAAADx4CQAAAAgHpwEAAAAxLPlJBoAAAC4l9scwFXsOInbdIiGgroKSlJDUZhQGpoXLIpXC1livDiJC6CgroKS1FAUJpSG5gWL4tVClhgvTuICKKiroCQ1FIUJpaF5waJ4tZAlxouTuAAK6iooSQ1FYUJpaF6wKF4tZInx4iQugIK6CkpSQ1GYUBqaFyyKVwtZYrw4iQug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q5EHx8nAQAAJhlGN8Z142dYBY+TcO6Rd63E2UZ1z0k4BJSYv+w4CXfmyZkZlyGudhLWEU2fhJMAAACT+2dcGu2u+QDk/IeVk1g9RRB6rGD32ZBDwg7/afVXQ9fxPgnvSEIZfRKBz3ASAABgcvdToLohdMY67PZ42zd4H6fcnIVxRtjRP3n+qm/dj8+TuMFJnJ0n4T3ecm6cBAAAmNz4ZqrAjbrTljpOYqtDJND9fualVD5hB//k/av5pOuhZzcK7JPwngcnVP7pZgAAATtJREFUAQAAfm58W/bGbAGjGfT0UHhaSXuCo7vVSS9xoZOYT716vVboFRclOgmPKOPUOAkAADC5cQWvVUPofdn0etJE+F7eeNrDN0nzaOt6pZMwBhN8z7l6W+jinMTmm75wEgAAYHJjk+BpCEM39f5HICzm9nN7/uXxx1f9Qyf+wRXf4xqrU+88qerpjlnF5jvuTW/LdpQaR8dJAACACU0CnAMnAQAAJjQJcA6cBAAAmNAkwDlwEgAAYFJ9k7D5YsjTL9YGnAQAAFjQJMA5cBIAAGBCkwDnwEkAAIAJTQIAAADEg5MAAACAeHASAAAAEA9OAgAAAOLBSQAAAEA8OAkAAACIBycBAAAA8eAkAAAAIB6cBAAAAMSDkwAAAIB4cBIAAAAQD04CAAAA4sFJAAAAQDw4CQAAAIjn/wFHISFS0P6SYwAAAABJRU5ErkJggg==" /> </span></div>
<div>
<br />
<b><span data-dobid="hdw"><span style="color: #20124d;">[
Note as how the entry in Hash Map is only put when we encounter a new
sum, for the sum already present ( as key in Hash Map ) only the length
of the sub array is computed and max length is updated if the length of
the sub array is greater ]. </span></span></b><br />
<b><span data-dobid="hdw"><span style="color: #20124d;"> </span> </span></b><br />
<b><span data-dobid="hdw">Now Lets write the code finally!!</span></b></div>
<div>
</div>
<div>
<span data-dobid="hdw"></span><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span data-dobid="hdw"><span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.HashMap</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">ZeroSubArrayMaxLength</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> array <span style="color: #333333;">=</span> <span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">7</span><span style="color: #333333;">,</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">,</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">10</span> <span style="color: #333333;">};</span>
<span style="color: #333399; font-weight: bold;">int</span> result <span style="color: #333333;">=</span> maxLength<span style="color: #333333;">(</span>array<span style="color: #333333;">);</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>result<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">maxLength</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> A<span style="color: #333333;">[])</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> n <span style="color: #333333;">=</span> A<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">;</span>
HashMap<span style="color: #333333;"><</span>Integer<span style="color: #333333;">,</span> Integer<span style="color: #333333;">></span> hashMap <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> HashMap<span style="color: #333333;"><>();</span>
<span style="color: #333399; font-weight: bold;">int</span> sum <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> maxLength <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
hashMap<span style="color: #333333;">.</span><span style="color: #0000cc;">put</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span> <span style="color: #888888;">// initialization</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> n<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
sum <span style="color: #333333;">=</span> sum <span style="color: #333333;">+</span> A<span style="color: #333333;">[</span>i<span style="color: #333333;">];</span>
Integer pSumIndex <span style="color: #333333;">=</span> hashMap<span style="color: #333333;">.</span><span style="color: #0000cc;">get</span><span style="color: #333333;">(</span>sum<span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>pSumIndex <span style="color: #333333;">!=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> localLength <span style="color: #333333;">=</span> i <span style="color: #333333;">-</span> pSumIndex<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>maxLength <span style="color: #333333;"><</span> localLength<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
maxLength <span style="color: #333333;">=</span> localLength<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span> <span style="color: #008800; font-weight: bold;">else</span> <span style="color: #333333;">{</span>
hashMap<span style="color: #333333;">.</span><span style="color: #0000cc;">put</span><span style="color: #333333;">(</span>sum<span style="color: #333333;">,</span> i<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> maxLength<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></span></pre>
</div>
<span data-dobid="hdw">
<br /> </span><br />
<div>
<ol style="text-align: left;"><ol></ol>
</ol>
</div>
</div>
</div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-72573638686486714042016-06-26T07:15:00.000-07:002016-06-26T07:18:11.388-07:00Searching in a Row-wise and Column-wise sorted 2 d matrix.<div dir="ltr" style="text-align: left;" trbidi="on">
Dear Friends,<br />
<br />
I am here with you with a tricky algorithmic question. It is based on searching an element in 2 D matrix which is sorted row wise and column wise. Please find the problem details below.<br />
<br />
A matrix with R rows and C columns such that it is sorted row wise and column wise. For any element, 'e', in the matrix, positioned at 'r' and 'c', as compared to e we have:<br />
<ol style="text-align: left;">
<li>All elements towards its LEFT are SMALLER.</li>
<li>All elements towards its RIGHT are GREATER.</li>
<li>All elements above it are SMALLER.</li>
<li>All elements below it are GREATER.</li>
</ol>
We have been given a number 'X' which we have to find if it exists in the matrix or not.<br />
<br />
The top-most left element has the position of (0,0) and bottom-most right element is positioned at (R-1,C-1).<br />
<br />
<br />
<br />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><br />
<img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMEAAABtCAIAAACX/pJeAAAH2UlEQVR4nO2dwXGzMBCFVYrroIYU4RMV5OoeuFKHZzilBVfgGV9Thv6DBAgjwYrdF6/97xsfMhnyeYMeQsDz2nmTiSf36gJMby/zkIkr85CJK/OQiSvzkIkr85CJKx0eunfeufgaRMmt8875VhbqfddACm5HpmvloEEDjKzCQ4N3zjed92EnNv4uh3UAD3WN7+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AJ9ThHemiZhSVl3anroVVHveMhjb3aJOORyjw0KjbVO/rd5DAPpVlYet9Z4r5LxnXu9zhOSHVkQm1y8UilHmJ+rgOzHloubyv6zpL33TgqiyIFQ6u59zpeMOwzUtP2VVtHtaNp4mcUheYhibDm1mcFOfNQNvaaXvoxj+zkz/lZ2AJBVRZ2+mji4ftDyW2VQgz00A2M7danrHNZPvZ67y8y37VQWlMfX2aV9oCS+0N0uo4bqa/F4shKsOYhOBZHVoI1D8GxOLISrOUYTRnVjTLIPab/R+YhE1fmIRNX5iETV+YhE1fmIRNX5iETV+YhE1fmIRNX5iETV+YhE1fmIRNX5iETV/8A6d5Hqa11Q/IAAAAASUVORK5CYII=" /><br />
Above is an example of such matrix. Here R = 4 [ as rows are 4 ] , C = 5 [ as columns are 5 ].<br />
<br />
Suppose we need to find 35, so for this case our X = 35.<br />
<br />
<ol style="text-align: left;">
<li>Basic approach is traversing all the elements in the matrix this approach has time complexity of O(R*C).</li>
<li>Another approach is to do binary search in each row. This will have time complexity of O(C*logR).</li>
<li>Another approach is to start from topmost right element. We know that as compared to the topmost right element, all the elements to its left are smaller and all the elements below it are greater. </li>
<ul>
<li>In a loop and starting with topmost right element.</li>
<ul>
<li>if X is equal to element, print "Element found" and return.</li>
<li>if X is smaller than element, move LEFT, i.e. <b>decrease column </b>by 1.</li>
<li>if X is greater than element, move DOWN, i.e. <b>increase row</b> by 1. </li>
</ul>
</ul>
</ol>
<ul style="text-align: left;"><ul>
<li>continue looping until column >= 0 and row < R.</li>
<li>If the loop completes, print "Element is not found". </li>
</ul>
</ul>
Friends refer to the Java program implementing the 3rd approach.<br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> sortedmatrix<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">FindElementInSortedMatrix</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[][]</span> sortedMatrix <span style="color: #333333;">=</span>
<span style="color: #333333;">{</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">8</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">9</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">20</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">7</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">25</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">30</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">32</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">20</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">33</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">35</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">40</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">10</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">24</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">38</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">45</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">50</span> <span style="color: #333333;">}</span>
<span style="color: #333333;">};</span>
<span style="color: #333399; font-weight: bold;">int</span> R <span style="color: #333333;">=</span> sortedMatrix<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> C <span style="color: #333333;">=</span> sortedMatrix<span style="color: #333333;">[</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">].</span><span style="color: #0000cc;">length</span><span style="color: #333333;">;</span> <span style="color: #888888;">// assuming all rows have same number of</span>
<span style="color: #888888;">// columns</span>
<span style="color: #333399; font-weight: bold;">int</span> X <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">35</span><span style="color: #333333;">;</span>
findPositionOfX<span style="color: #333333;">(</span>R<span style="color: #333333;">,</span> C<span style="color: #333333;">,</span> sortedMatrix<span style="color: #333333;">,</span> X<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">findPositionOfX</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> R<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> C<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[][]</span> sortedMatrix<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> X<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> r <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> c <span style="color: #333333;">=</span> C <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #888888;">// directions possible are left and down.</span>
<span style="color: #888888;">// left => decrement in columns, 0 will be the limit</span>
<span style="color: #888888;">// down => increment in row, R-1 will be the limit</span>
<span style="color: #008800; font-weight: bold;">while</span> <span style="color: #333333;">(</span>r <span style="color: #333333;"><=</span> R <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">&&</span> c <span style="color: #333333;">>=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>sortedMatrix<span style="color: #333333;">[</span>r<span style="color: #333333;">][</span>c<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> X<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #888888;">// success, elemt has been found.</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Sucess!!, elecment found at r ="</span> <span style="color: #333333;">+</span> r <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">" c="</span> <span style="color: #333333;">+</span> c<span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">return</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>X <span style="color: #333333;"><</span> sortedMatrix<span style="color: #333333;">[</span>r<span style="color: #333333;">][</span>c<span style="color: #333333;">])</span> <span style="color: #333333;">{</span>
<span style="color: #888888;">// move left</span>
c <span style="color: #333333;">=</span> c <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span> <span style="color: #008800; font-weight: bold;">else</span> <span style="color: #333333;">{</span>
<span style="color: #888888;">// move down</span>
r <span style="color: #333333;">=</span> r <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Element is not present in the matrix"</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br />
<br />
<br />
Maximum hops for columns can be starting from right move all steps towards left till column becomes 0 and maximum hops for rows can be starting from top to move all steps below until row becomes R-1. So time complexity of this approach is O(R + C). <br />
</div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-10904225215878734712016-06-22T11:21:00.001-07:002016-06-22T11:28:00.395-07:00Given only parent array find height of a genric tree | java implementation<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
Hello friends,<br />
<br />
I recently came across an interesting question on Tree. The problem statement is as below:<br />
<br />
<span style="color: purple;">Suppose a generic tree has N nodes and nodes are named using the numbers between inclusive range 0 to N-1. An array of Integers, named 'parent' , is given, such that 'parent[i]' represents name of the parent node for node-i. For the root value stored in 'parent' array is -1. <b>Find the height of the Tree.</b></span><br />
<br />
Friends Points to note are :<br />
<ol style="text-align: left;">
<li>Tree is generic and not necessary a Binary tree.</li>
<li>Only information we have is of Parents of each node.</li>
<li>Root is not necessarily at position 0, as it is not mentioned in the problem statement.</li>
</ol>
<br />
Lets see this with a diagram.<br />
<br />
<img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXMAAAF9CAIAAAB50h+1AAARfUlEQVR4nO3d0XkiSwyE0YmLgIiHaEiGYLgPeLnYBjzMSK2q1n+e9wN1tSQDa3aXKwBEW6oLADAhNguAeGwWAPHYLADisVkAxGOzAIjHZgEQj80CIB6bBUA8NguAeGwWTGVZobrGFkgZM/hoa7BlBiBZGNu/IFgxSQgUlsLXAf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xuoXNAqgLndLL6ZC+WaZfK1c2CyYQOKiX02HAmyE2C2Bg56Cej4N/S47NAjjwGlSvajdrcUhMz2hcjUrdo8UhMT2jcTUqdY8Wh0QHFhNrUWSILufE9CyG1qLIEF3OiQ7E51a8vFiNjorpKY+ucm0Zep0W05MdYNnCkvQ6LToQnGHBkrK1OzA6kJpkqWKG6XhmdCAyzyJljNf02OigfKrLCyjU9+TooHC2O6+VK5sF07t9h3nuZxTU/fxoYtios1NuSAFdZL+U4KXKI4JALxnzz075jTjQ0eN/A7L/QQILmwahoLv1W2b5bkx5pkgH+N/yVnV1TggLQDw2C4B4bBYA8dgsAOKxWQDEY7MAiMdmARCPzQIg3n8mn5mVOtH60gAAAABJRU5ErkJggg==" /><br />
<br />
Lets see the parent array for this tree<br />
<br />
<span style="color: blue;">int[] parent = {6,6,6,-1,3,0,3};</span><br />
<br />
Friends to solve this <i>we will first compute the depth of each node and memorize it. Using above information, depth of any node can be simply calculated by adding 1 to the depth of its parent. The node at maximum depth will be the height of the tree.</i><br />
<br />
Lets see the implementation in Java for solving this problem<br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> generictree<span style="color: #333333;">;</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * @author Krishna.k</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * Suppose a generic tree has N nodes and nodes are named using the</span>
<span style="color: #888888;"> * numbers between inclusive range 0 to N-1. An array of Integers, named</span>
<span style="color: #888888;"> * 'parent' , is given, such that 'parent[i]' represents name of the</span>
<span style="color: #888888;"> * parent node for node-i. For the root value stored in 'parent' array</span>
<span style="color: #888888;"> * is -1. Find the height of the Tree.</span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">FindHeightGivenParentArray</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> parent <span style="color: #333333;">=</span> <span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">,</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span> <span style="color: #333333;">};</span>
<span style="color: #333399; font-weight: bold;">int</span> N <span style="color: #333333;">=</span> parent<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">;</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"height of tree is "</span> <span style="color: #333333;">+</span> getHeightOfTree<span style="color: #333333;">(</span>parent<span style="color: #333333;">,</span> N<span style="color: #333333;">));</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">getHeightOfTree</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> parent<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> N<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> depths <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[</span>N<span style="color: #333333;">];</span>
<span style="color: #333399; font-weight: bold;">int</span> maxDepth <span style="color: #333333;">=</span> Integer<span style="color: #333333;">.</span><span style="color: #0000cc;">MIN_VALUE</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> N<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>depths<span style="color: #333333;">[</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> depthOfIthNode <span style="color: #333333;">=</span> findDepthOfIthNode<span style="color: #333333;">(</span>parent<span style="color: #333333;">,</span> depths<span style="color: #333333;">,</span> i<span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>maxDepth <span style="color: #333333;"><</span> depthOfIthNode<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
maxDepth <span style="color: #333333;">=</span> depthOfIthNode<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> maxDepth<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">findDepthOfIthNode</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> parent<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> depths<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> i<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>depths<span style="color: #333333;">[</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">!=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> depths<span style="color: #333333;">[</span>i<span style="color: #333333;">];</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>parent<span style="color: #333333;">[</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
depths<span style="color: #333333;">[</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">return</span> depths<span style="color: #333333;">[</span>i<span style="color: #333333;">];</span>
<span style="color: #333333;">}</span>
depths<span style="color: #333333;">[</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> findDepthOfIthNode<span style="color: #333333;">(</span>parent<span style="color: #333333;">,</span> depths<span style="color: #333333;">,</span> parent<span style="color: #333333;">[</span>i<span style="color: #333333;">])</span> <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">return</span> depths<span style="color: #333333;">[</span>i<span style="color: #333333;">];</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /><br />
<br /></div>
<span style="color: blue;">The Output for the above program on console is :</span><br />
<b>height of tree is 4</b></div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-71372174038663072642016-02-21T21:45:00.002-08:002016-02-21T21:47:35.199-08:00Insertion sort in Java<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Dear Friends I am with you with implementation of Insertion sort in Java.<br />
<br />
It is an easy sorting algorithm. Please find below the code in java for the same. The code contains necessary comments to understand the steps.<br />
<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.Arrays</span><span style="color: #333333;">;</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * @author krishna.k</span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">InsersionSort</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> arr<span style="color: #333333;">[]</span> <span style="color: #333333;">=</span> <span style="color: #333333;">{</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">8</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">7</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">9</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">43</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">43</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">41</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">40</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">35</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">38</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">57</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">7</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">66</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">454</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">745</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">556465</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">3455</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">217</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">8769</span><span style="color: #333333;">,-</span><span style="color: #0000dd; font-weight: bold;">99</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">657</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">545</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">343</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">32433</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">46</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">546</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">9</span><span style="color: #333333;">,-</span><span style="color: #0000dd; font-weight: bold;">90</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">7</span><span style="color: #333333;">,-</span><span style="color: #0000dd; font-weight: bold;">10</span><span style="color: #333333;">,-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">};</span>
insertionSort<span style="color: #333333;">(</span>arr<span style="color: #333333;">);</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>Arrays<span style="color: #333333;">.</span><span style="color: #0000cc;">toString</span><span style="color: #333333;">(</span>arr<span style="color: #333333;">));</span>
<span style="color: #333333;">}</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * Best case : all the elements are already sorted : see in this case the second loop [ inner loop ] will break so O(n)</span>
<span style="color: #888888;"> * Worst case : elements are sorted in reverse order. both the loops will work till their bounds so O(n2)</span>
<span style="color: #888888;"> * Average case : O(n2).</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * This is best sorting when array size is very small. Although for small sized arrays it seams average case running time of O(n2) </span>
<span style="color: #888888;"> * but due to less steps and less computations this is better than other sorts with n*log(n) running time.</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">insertionSort</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> arr<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>arr <span style="color: #333333;">!=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> size <span style="color: #333333;">=</span> arr<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">;</span>
<span style="color: #888888;">// first loop iterates the array from 2nd element (at index 1) till the end. </span>
<span style="color: #888888;">// element at i-th [candidate element] is the element for which position needs to be decided.</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> size<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> candidateElement <span style="color: #333333;">=</span> arr<span style="color: #333333;">[</span>i<span style="color: #333333;">];</span> <span style="color: #888888;">// storing the candidate element</span>
<span style="color: #333399; font-weight: bold;">int</span> j <span style="color: #333333;">=</span> i<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(;</span> j <span style="color: #333333;">>=</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">&&</span> arr<span style="color: #333333;">[</span>j<span style="color: #333333;">]</span> <span style="color: #333333;">></span> candidateElement<span style="color: #333333;">;</span> j<span style="color: #333333;">--)</span> <span style="color: #333333;">{</span> <span style="color: #888888;">// Second array scans and compares the candidate elements with the elements before it in the array</span>
arr<span style="color: #333333;">[</span>j<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;">=</span> arr<span style="color: #333333;">[</span>j<span style="color: #333333;">];</span><span style="color: #888888;">// in case candidate element is smaller then current element at jth position needs to shift forward, so storing it at j+1th position. </span>
<span style="color: #333333;">}</span>
<span style="color: #888888;">// in case shifting of elements were done as per the value of candidate element then due to decrementing the j after each shifting, need to do +1 in j to </span>
<span style="color: #888888;">// put the candidate element at its correct position.</span>
<span style="color: #888888;">// in case no shifting was done and as j was initialized with i-1 hence +1 needs to be done for j</span>
<span style="color: #888888;">//so as candidate element is put at its current position as it is. </span>
arr<span style="color: #333333;">[</span>j<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;">=</span> candidateElement<span style="color: #333333;">;</span><span style="color: #888888;">// Inserting the current element in its correct position.</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br />
<br />
<br />
Please go through the code above and then see below steps [sort of dry run] for better understanding.<br />
<b>Outer loop 1st iteration:</b><br />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><br />
<!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="267">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:"Times New Roman";
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
table.MsoTableGrid
{mso-style-name:"Table Grid";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-priority:59;
mso-style-unhide:no;
border:solid black 1.0pt;
mso-border-themecolor:text1;
mso-border-alt:solid black .5pt;
mso-border-themecolor:text1;
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-border-insideh:.5pt solid black;
mso-border-insideh-themecolor:text1;
mso-border-insidev:.5pt solid black;
mso-border-insidev-themecolor:text1;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="height: 14.2pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
index</div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<b><span style="color: #073763;"><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">0</span></i></span></b></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<b><span style="color: #073763;"><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">1</span></i></span></b></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">2</span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">3</span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">4</span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">5</span></div>
</td>
</tr>
<tr style="height: 14.2pt; mso-yfti-irow: 1; mso-yfti-lastrow: yes;">
<td style="border-top: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
arr</div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">1</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="background-color: orange;"><b><span style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">2</span></span></b></span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">5</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">3</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">8</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">6</span></div>
</td>
</tr>
</tbody></table>
<br />
i = 1<br />
j = i-1 = 0<br />
candidateElement = arr[i] = arr[1] = 2<br />
arr[j] > candidateElement => arr[0] > 2 == 1 > 2 => false so break second loop<br />
arr[j+1] = candidateElement => arr[0+1] = 2 => 2 remains at same position <br />
<br />
<br />
<b>Outer loop 2nd Iteration:</b><br />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><br />
<!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="267">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:"Times New Roman";
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
table.MsoTableGrid
{mso-style-name:"Table Grid";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-priority:59;
mso-style-unhide:no;
border:solid black 1.0pt;
mso-border-themecolor:text1;
mso-border-alt:solid black .5pt;
mso-border-themecolor:text1;
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-border-insideh:.5pt solid black;
mso-border-insideh-themecolor:text1;
mso-border-insidev:.5pt solid black;
mso-border-insidev-themecolor:text1;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="height: 14.2pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
index</div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">0</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">1</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">2</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">3</span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">4</span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">5</span></div>
</td>
</tr>
<tr style="height: 14.2pt; mso-yfti-irow: 1; mso-yfti-lastrow: yes;">
<td style="border-top: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
arr</div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">1</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">2</span></span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="background-color: orange;"><b><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">5</span></b></span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">3</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">8</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">6</span></div>
</td>
</tr>
</tbody></table>
<br />
i = 2<br />
j = i-1 = 1<br />
candidateElement = arr[i] =arr[2] = 5 <br />
arr[j] > candidateElement => arr[1] > 5 => 2 > 5 => false so break second loop<br />
arr[j+1] = candidateElement => arr[1+1] = 5 => 5 remains at same position <br />
<br />
<br />
<b>Outer loop 3rd Iteration: </b><br />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><br />
<!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="267">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:"Times New Roman";
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
table.MsoTableGrid
{mso-style-name:"Table Grid";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-priority:59;
mso-style-unhide:no;
border:solid black 1.0pt;
mso-border-themecolor:text1;
mso-border-alt:solid black .5pt;
mso-border-themecolor:text1;
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-border-insideh:.5pt solid black;
mso-border-insideh-themecolor:text1;
mso-border-insidev:.5pt solid black;
mso-border-insidev-themecolor:text1;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="height: 14.2pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
index</div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">0</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">1</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">2</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">3</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">4</span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">5</span></div>
</td>
</tr>
<tr style="height: 14.2pt; mso-yfti-irow: 1; mso-yfti-lastrow: yes;">
<td style="border-top: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
arr</div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">1</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="mso-bidi-font-weight: normal;"><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">2</span></span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">5</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="background-color: orange;"><b><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">3</span></b></span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">8</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">6</span></div>
</td>
</tr>
</tbody></table>
<br />
i = 3<br />
j = i-1 = 2<br />
candidateElement = arr[i] =arr[3] = 3 <br />
arr[j] > candidateElement => arr[2] > 3 => 5 > 3 => true<br />
arr[j+1] = arr[j] => arr[2+1] = arr[2] => arr[3] = arr[2]<br />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><br />
<!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="267">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:"Times New Roman";
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
table.MsoTableGrid
{mso-style-name:"Table Grid";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-priority:59;
mso-style-unhide:no;
border:solid black 1.0pt;
mso-border-themecolor:text1;
mso-border-alt:solid black .5pt;
mso-border-themecolor:text1;
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-border-insideh:.5pt solid black;
mso-border-insideh-themecolor:text1;
mso-border-insidev:.5pt solid black;
mso-border-insidev-themecolor:text1;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="height: 14.2pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
index</div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">0</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">1</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">2</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">3</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">4</span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">5</span></div>
</td>
</tr>
<tr style="height: 14.2pt; mso-yfti-irow: 1; mso-yfti-lastrow: yes;">
<td style="border-top: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
arr</div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">1</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">2</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">5</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: blue;"><b><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">5</span></b></span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">8</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">6</span></div>
</td>
</tr>
</tbody></table>
<br />
j-- = j-1 = 2-1 = 1<br />
arr[j] > candidateElement => arr[1] > 3 => 2 > 3 => false so break the second loop<br />
arr[j+1] = candidateElement => arr[1+1] = 3 => arr[2] = 3<br />
<br />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><br />
<!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="267">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:"Times New Roman";
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
table.MsoTableGrid
{mso-style-name:"Table Grid";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-priority:59;
mso-style-unhide:no;
border:solid black 1.0pt;
mso-border-themecolor:text1;
mso-border-alt:solid black .5pt;
mso-border-themecolor:text1;
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-border-insideh:.5pt solid black;
mso-border-insideh-themecolor:text1;
mso-border-insidev:.5pt solid black;
mso-border-insidev-themecolor:text1;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="height: 14.2pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
index</div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">0</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">1</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">2</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">3</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">4</span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">5</span></div>
</td>
</tr>
<tr style="height: 14.2pt; mso-yfti-irow: 1; mso-yfti-lastrow: yes;">
<td style="border-top: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
arr</div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">1</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">2</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">3</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">5</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">8</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">6</span></div>
</td>
</tr>
</tbody></table>
<br />
<br />
<br />
<b>Outer Loop 4th Iteration:</b><br />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><br />
<!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="267">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:"Times New Roman";
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
table.MsoTableGrid
{mso-style-name:"Table Grid";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-priority:59;
mso-style-unhide:no;
border:solid black 1.0pt;
mso-border-themecolor:text1;
mso-border-alt:solid black .5pt;
mso-border-themecolor:text1;
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-border-insideh:.5pt solid black;
mso-border-insideh-themecolor:text1;
mso-border-insidev:.5pt solid black;
mso-border-insidev-themecolor:text1;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="height: 14.2pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
index</div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">0</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">1</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">2</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">3</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">4</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">5</span></div>
</td>
</tr>
<tr style="height: 14.2pt; mso-yfti-irow: 1; mso-yfti-lastrow: yes;">
<td style="border-top: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
arr</div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">1</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">2</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">3</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">5</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="background-color: orange;"><b><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">8</span></b></span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">6</span></div>
</td>
</tr>
</tbody></table>
<br />
i = 4<br />
j = i-1 = 3<br />
candidateElement = arr[i] =arr[4] = 8 <br />
arr[j] > candidateElement => arr[1] > 5 => 2 > 5 => false so break second loop<br />
arr[j+1] = candidateElement => arr[3+1] = 8 => 8 remains at same position<br />
<br />
<br />
<b>Outer Loop 5th Iteration:</b><br />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><br />
<!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="267">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:"Times New Roman";
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
table.MsoTableGrid
{mso-style-name:"Table Grid";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-priority:59;
mso-style-unhide:no;
border:solid black 1.0pt;
mso-border-themecolor:text1;
mso-border-alt:solid black .5pt;
mso-border-themecolor:text1;
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-border-insideh:.5pt solid black;
mso-border-insideh-themecolor:text1;
mso-border-insidev:.5pt solid black;
mso-border-insidev-themecolor:text1;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="height: 14.2pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
index</div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">0</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">1</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">2</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">3</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">4</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">5</span></i></b></span></div>
</td>
</tr>
<tr style="height: 14.2pt; mso-yfti-irow: 1; mso-yfti-lastrow: yes;">
<td style="border-top: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
arr</div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">1</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">2</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">3</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">5</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">8</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="background-color: orange;"><b><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">6</span></b></span></div>
</td>
</tr>
</tbody></table>
<br />
i = 5<br />
j = i-1 = 4<br />
candidateElement = arr[i] =arr[5] = 6 <br />
arr[j] > candidateElement => arr[4] > 6 => 8 > 6 => true<br />
arr[j+1] = arr[j] => arr[4+1] = arr[4] => arr[5] = arr[4]<br />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><br />
<!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="267">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:"Times New Roman";
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
table.MsoTableGrid
{mso-style-name:"Table Grid";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-priority:59;
mso-style-unhide:no;
border:solid black 1.0pt;
mso-border-themecolor:text1;
mso-border-alt:solid black .5pt;
mso-border-themecolor:text1;
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-border-insideh:.5pt solid black;
mso-border-insideh-themecolor:text1;
mso-border-insidev:.5pt solid black;
mso-border-insidev-themecolor:text1;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="height: 14.2pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
index</div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">0</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">1</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">2</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">3</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">4</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">5</span></i></b></span></div>
</td>
</tr>
<tr style="height: 14.2pt; mso-yfti-irow: 1; mso-yfti-lastrow: yes;">
<td style="border-top: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
arr</div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">1</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">2</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">3</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">5</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">8</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: blue;"><b><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">8</span></b></span></div>
</td>
</tr>
</tbody></table>
<br />
j-- => j-1=> 4-1 => 3<br />
arr[j] > candidateElement => arr[3] > 6 => 5 > 6 => false so breaking the second loop<br />
arr[j+1] = candidateElement = > arr[3+1] = 6 => arr[4] = 6<br />
arr[] = 1 2 3 5 6 8<br />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><br />
<!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="267">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:"Times New Roman";
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
table.MsoTableGrid
{mso-style-name:"Table Grid";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-priority:59;
mso-style-unhide:no;
border:solid black 1.0pt;
mso-border-themecolor:text1;
mso-border-alt:solid black .5pt;
mso-border-themecolor:text1;
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-border-insideh:.5pt solid black;
mso-border-insideh-themecolor:text1;
mso-border-insidev:.5pt solid black;
mso-border-insidev-themecolor:text1;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="height: 14.2pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
index</div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">0</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">1</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">2</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">3</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">4</span></i></b></span></div>
</td>
<td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">5</span></i></b></span></div>
</td>
</tr>
<tr style="height: 14.2pt; mso-yfti-irow: 1; mso-yfti-lastrow: yes;">
<td style="border-top: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
arr</div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">1</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">2</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">3</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">5</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">6</span></div>
</td>
<td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">8</span></div>
</td>
</tr>
</tbody></table>
<br />
<br />
<br />
<br />
<b>Outer loop 6th Iteration:</b><br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"><tbody>
<tr style="height: 14.2pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;"><td style="border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
index</div>
</td><td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">0</span></i></b></span></div>
</td><td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">1</span></i></b></span></div>
</td><td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">2</span></i></b></span></div>
</td><td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">3</span></i></b></span></div>
</td><td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">4</span></i></b></span></div>
</td><td style="border-left: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-themecolor: text1; mso-border-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="color: #073763;"><b><i><span style="font-size: 8.0pt; mso-bidi-font-size: 11.0pt;">5</span></i></b></span></div>
</td></tr>
<tr style="height: 14.2pt; mso-yfti-irow: 1; mso-yfti-lastrow: yes;"><td style="border-top: none; border: solid black 1.0pt; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 26.35pt;" valign="top" width="35"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
arr</div>
</td><td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">1</span></div>
</td><td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 16.2pt;" width="22"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">2</span></div>
</td><td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 25.35pt;" width="34"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">3</span></div>
</td><td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">5</span></div>
</td><td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">6</span></div>
</td><td style="border-bottom: solid black 1.0pt; border-left: none; border-right: solid black 1.0pt; border-top: none; height: 14.2pt; mso-border-alt: solid black .5pt; mso-border-bottom-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-right-themecolor: text1; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; padding: 0in 5.4pt 0in 5.4pt; width: 20.25pt;" width="27"><div align="center" class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">8</span></div>
</td></tr>
</tbody></table>
i = 6<br />
i < size <b> => </b>i < 6 => 6 < 6 => false so breaking the first loop<br />
<b><br /></b>
<b>Method is executed completely and array has been sorted. </b><br />
<b><br /></b>
<br />
Thanks friends for reading this post, do leave comments below with your feedback. <br />
<br />
<br />
<br />
<br />
<br /></div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-43454622339369446862016-01-01T10:17:00.003-08:002016-07-23T06:05:05.333-07:00Reversing a Linked List in Java<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
<br />
I am with you with a famous problem in data structure, Reversing a Linked List.<br />
<br />
For<span style="color: blue;"> java.util.LinkedList <b>Collections.reverse(List list)</b> </span>can be used. It takes List as input and after the execution of this method, the list passed as parameter is reversed.<br />
<br />
But lets see how to reverse a LinkedList if we have made our custom LinkedList. Reversing a custom LinkedList basically involves use of three references. Previous, Current and Next.<br />
<br />
The main idea is<br />
1. <b>Starting step :</b> Initialize the current node as head node<br />
2. <b>Preserve Next</b> <b>: </b>In each iteration preserve the next node to the current node,<br />
3. <b>Break and Remake the next link : </b>Making the next node to the current node as previous node.<br />
4. <b>Move ahead :</b> Finally moving previous node to current node and current node to the preserved next node.<br />
5. <b>Loop : </b>Go to step 2 if current node != null <br />
6.<b> Update Head :</b> Make head node as previous node.<br />
<br />
Lets see the code below :<br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.ArrayList</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.Collections</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.Iterator</span><span style="color: #333333;">;</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * @author Krishna Kumar</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * This class demostrates as how to reverse a linked list.</span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">ListReversal</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
reverseJavaUtilListDemo<span style="color: #333333;">();</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">();</span>
reverseCustomLinkedList<span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">reverseJavaUtilListDemo</span><span style="color: #333333;">(){</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Reversing the java.util.List..."</span><span style="color: #333333;">);</span>
java<span style="color: #333333;">.</span><span style="color: #0000cc;">util</span><span style="color: #333333;">.</span><span style="color: #0000cc;">List</span><span style="color: #333333;"><</span>String<span style="color: #333333;">></span> javaUtilList <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> ArrayList<span style="color: #333333;"><>();</span>
javaUtilList<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Hello"</span><span style="color: #333333;">);</span>
javaUtilList<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Hi"</span><span style="color: #333333;">);</span>
javaUtilList<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Hola"</span><span style="color: #333333;">);</span>
javaUtilList<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Namaste"</span><span style="color: #333333;">);</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"printing in order of insersion"</span><span style="color: #333333;">);</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>javaUtilList<span style="color: #333333;">);</span>
Collections<span style="color: #333333;">.</span><span style="color: #0000cc;">reverse</span><span style="color: #333333;">(</span>javaUtilList<span style="color: #333333;">);</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"printing in reverse order"</span><span style="color: #333333;">);</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>javaUtilList<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">reverseCustomLinkedList</span><span style="color: #333333;">(){</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Reversing the custom list"</span><span style="color: #333333;">);</span>
CustomLinkedList<span style="color: #333333;"><</span>String<span style="color: #333333;">></span> customList <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> CustomLinkedList<span style="color: #333333;"><</span>String<span style="color: #333333;">>();</span>
customList<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Hello"</span><span style="color: #333333;">);</span>
customList<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Hi"</span><span style="color: #333333;">);</span>
customList<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Hola"</span><span style="color: #333333;">);</span>
customList<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Namaste"</span><span style="color: #333333;">);</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"printing in order of insersion"</span><span style="color: #333333;">);</span>
customList<span style="color: #333333;">.</span><span style="color: #0000cc;">print</span><span style="color: #333333;">();</span>
customList<span style="color: #333333;">.</span><span style="color: #0000cc;">reverse</span><span style="color: #333333;">();</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"printing in reverse order"</span><span style="color: #333333;">);</span>
customList<span style="color: #333333;">.</span><span style="color: #0000cc;">print</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">CustomLinkedList</span><span style="color: #333333;"><</span>V<span style="color: #333333;">></span> <span style="color: #008800; font-weight: bold;">implements</span> Iterable<span style="color: #333333;"><</span>V<span style="color: #333333;">></span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">private</span> Node head<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> Node tail<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">add</span><span style="color: #333333;">(</span>V data<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>head <span style="color: #333333;">==</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
head <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">(</span>data<span style="color: #333333;">);</span>
tail <span style="color: #333333;">=</span> head<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span> <span style="color: #008800; font-weight: bold;">else</span> <span style="color: #333333;">{</span>
Node newNode <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">(</span>data<span style="color: #333333;">);</span>
tail<span style="color: #333333;">.</span><span style="color: #0000cc;">next</span> <span style="color: #333333;">=</span> newNode<span style="color: #333333;">;</span>
tail <span style="color: #333333;">=</span> newNode<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">reverse</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
Node previous <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">;</span>
Node current <span style="color: #333333;">=</span> head<span style="color: #333333;">;</span>
Node next <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">while</span> <span style="color: #333333;">(</span>current <span style="color: #333333;">!=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
next <span style="color: #333333;">=</span> current<span style="color: #333333;">.</span><span style="color: #0000cc;">next</span><span style="color: #333333;">;</span>
current<span style="color: #333333;">.</span><span style="color: #0000cc;">next</span> <span style="color: #333333;">=</span> previous<span style="color: #333333;">;</span>
previous <span style="color: #333333;">=</span> current<span style="color: #333333;">;</span>
current <span style="color: #333333;">=</span> next<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
head <span style="color: #333333;">=</span> previous<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Node</span> <span style="color: #333333;">{</span>
V data<span style="color: #333333;">;</span>
Node next<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Node</span><span style="color: #333333;">(</span>V data<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">data</span> <span style="color: #333333;">=</span> data<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">print</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span>V data <span style="color: #333333;">:</span> <span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">print</span><span style="color: #333333;">(</span>data <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">"->"</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"null"</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">public</span> Iterator<span style="color: #333333;"><</span>V<span style="color: #333333;">></span> <span style="color: #0066bb; font-weight: bold;">iterator</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">new</span> Iterator<span style="color: #333333;"><</span>V<span style="color: #333333;">>()</span> <span style="color: #333333;">{</span>
Node temp <span style="color: #333333;">=</span> head<span style="color: #333333;">;</span>
<span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">hasNext</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> temp <span style="color: #333333;">!=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">public</span> V <span style="color: #0066bb; font-weight: bold;">next</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
V data <span style="color: #333333;">=</span> temp<span style="color: #333333;">.</span><span style="color: #0000cc;">data</span><span style="color: #333333;">;</span>
temp <span style="color: #333333;">=</span> temp<span style="color: #333333;">.</span><span style="color: #0000cc;">next</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">return</span> data<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">};</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br />
Below is the summary of the above with an example.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqqyq4sMEpmU2mifHsvVQ1zWj_h4Uvnejb3HLZKV7cNQu2cFRDx1lw3_tLkJRwgFRjPfaK72rLFqBkZZEYUDedj7vKs2LoR3PNnw47e7CuFg7UECUApHuVNI-miyHU6VFEFvD9vNL6-sA/s1600/reversing_lined_list.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqqyq4sMEpmU2mifHsvVQ1zWj_h4Uvnejb3HLZKV7cNQu2cFRDx1lw3_tLkJRwgFRjPfaK72rLFqBkZZEYUDedj7vKs2LoR3PNnw47e7CuFg7UECUApHuVNI-miyHU6VFEFvD9vNL6-sA/s640/reversing_lined_list.jpg" width="429" /></a></div>
<br /></div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-47165277916355507222015-12-13T11:27:00.000-08:002015-12-13T11:35:52.482-08:00Iterator Pattern in Java | Simple Genric implementation<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
<br />
Today I wish to share with you the Iterator pattern. It is very powerful way to iterate over any collection. It is fast and also helpful in hiding the complicated way to traverse the underlying data structure of the collection.<br />
<br />
Suppose we have a Collection of String Objects stored in a class. Today I hold the items in simple array, tomorrow I may choose to use LinkedList to hold the items, and may be later I decide to use Tree or any other efficient data structure to hold my data. I want the users of my collection class not to get troubled by my decision of changing the underlying data structure. I want to provide them a uniform way to access the items in the collection.<br />
<br />
The Iterator pattern solves this problem nicely. I can provide an Iterator to my collection and it can be used by the users of my collection class to iterate over the items in the collection. The internal traversing can be handled internally in the Iterator class but the iteration methods contract never changes. Lets see below as how we can implement this.<br />
<br />
An interface iterator can be defined with hasNext() returning boolean [ true if collection has more items to iterate, else false ], and next() to get the next item in the collection. Collection class has a private concrete class implementing the Iterator and the object of concrete class(implementing the Iterator) can be exposed using a public method. <br />
<br />
<br />
Suppose we have a collection class named Lib.java It can hold items and I want a uniform way using which outside world (LibManager.java) can iterate my collection class.<br />
<br />
Lets see the UML class diagram for this.<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvwuMqGlzeP2TWxnZrIphpto-sRfSZ5CtBfjvmOu5eZLCYb5LksI5ZcuCuhp9IUYwA7AKAN88v5zF4bxRQkbtNwdm5KHI-TVPT-9EUzwb3PRTWF9XGpuOegV1s3-BX9XhQZWTvOrS3ZMA/s1600/iterator_pattern.gif" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvwuMqGlzeP2TWxnZrIphpto-sRfSZ5CtBfjvmOu5eZLCYb5LksI5ZcuCuhp9IUYwA7AKAN88v5zF4bxRQkbtNwdm5KHI-TVPT-9EUzwb3PRTWF9XGpuOegV1s3-BX9XhQZWTvOrS3ZMA/s1600/iterator_pattern.gif" /></a><br />
<br />
To keep the implementation simple, I have just kept add method in ICollection. Also the exceptional conditions such as array index out of bounds are not handled. We can do all that once we get the understanding of the Iterator pattern.<br />
Actual java.util classes Like ArrayList, LinkedList etc uses this pattern. They implement java.util.Iterable and hence enhanced for loop ( for each loop ) can be used with them.<br />
Enhanced for loop uses iterator to iterate and hence is faster. Usually in our code we get List of object, List can be actually be implemented by LinekdList or ArrayList but using Iterator to iterate is always faster as to iterate any element using Iterator only one step ahead needs to be taken whereas in case of traditional for loop, if the concrete implementation is LinekedList then again and again items will be traversed starting from the start of the linkedList. <br />
The Underlying data structure can change anytime, (say from ArrayList to LinekdList) hence using Iterator ( or enhanced for loop ) to iterate is always preferable. <br />
<br />
<br />
<br />
<pre style="line-height: 125%; margin: 0;"><!-- HTML generated using hilite.me --><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">interface</span> <span style="color: #bb0066; font-weight: bold;">ICollection</span><span style="color: #333333;"><</span>E<span style="color: #333333;">></span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">add</span><span style="color: #333333;">(</span>E element<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span></pre>
</div>
</pre>
<pre style="line-height: 125%; margin: 0;"><!-- HTML generated using hilite.me --><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">interface</span> <span style="color: #bb0066; font-weight: bold;">SIterable</span><span style="color: #333333;"><</span>P<span style="color: #333333;">></span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> CIterator<span style="color: #333333;"><</span>P<span style="color: #333333;">></span> <span style="color: #0066bb; font-weight: bold;">iterator</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span></pre>
</div>
</pre>
<pre style="line-height: 125%; margin: 0;"><!-- HTML generated using hilite.me --><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">interface</span> <span style="color: #bb0066; font-weight: bold;">CIterator</span><span style="color: #333333;"><</span>L<span style="color: #333333;">></span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">hasNext</span><span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">public</span> L <span style="color: #0066bb; font-weight: bold;">next</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span></pre>
</div>
</pre>
<pre style="line-height: 125%; margin: 0;"><!-- HTML generated using hilite.me --><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Lib</span><span style="color: #333333;"><</span>T<span style="color: #333333;">></span> <span style="color: #008800; font-weight: bold;">implements</span> SIterable<span style="color: #333333;"><</span>T<span style="color: #333333;">>,</span>ICollection<span style="color: #333333;"><</span>T<span style="color: #333333;">>{</span>
<span style="color: #008800; font-weight: bold;">private</span> Object<span style="color: #333333;">[]</span> items<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> maxSize<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Lib</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">){</span>
maxSize <span style="color: #333333;">=</span> size<span style="color: #333333;">;</span>
items <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Object<span style="color: #333333;">[</span>maxSize<span style="color: #333333;">];</span>
<span style="color: #333333;">}</span>
<span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">add</span><span style="color: #333333;">(</span>T element<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
items<span style="color: #333333;">[</span>size<span style="color: #333333;">++]</span> <span style="color: #333333;">=</span> element<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">public</span> CIterator<span style="color: #333333;"><</span>T<span style="color: #333333;">></span> <span style="color: #0066bb; font-weight: bold;">iterator</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #0066bb; font-weight: bold;">LibIterator</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">LibIterator</span> <span style="color: #008800; font-weight: bold;">implements</span> CIterator<span style="color: #333333;"><</span>T<span style="color: #333333;">>{</span>
<span style="color: #333399; font-weight: bold;">int</span> iteratingIndex <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">hasNext</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> iteratingIndex <span style="color: #333333;"><</span> size<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">public</span> T <span style="color: #0066bb; font-weight: bold;">next</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
Object nextItem <span style="color: #333333;">=</span> items<span style="color: #333333;">[</span>iteratingIndex<span style="color: #333333;">];</span>
iteratingIndex<span style="color: #333333;">++;</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #333333;">((</span>T<span style="color: #333333;">)</span>nextItem<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<!-- HTML generated using hilite.me --><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">LibManager</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
Lib<span style="color: #333333;"><</span>String<span style="color: #333333;">></span> lib <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Lib<span style="color: #333333;"><</span>String<span style="color: #333333;">>(</span><span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">);</span>
lib<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Bread"</span><span style="color: #333333;">);</span>
lib<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Butter"</span><span style="color: #333333;">);</span>
lib<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Apple"</span><span style="color: #333333;">);</span>
lib<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Orange"</span><span style="color: #333333;">);</span>
lib<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Pineapple"</span><span style="color: #333333;">);</span>
CIterator<span style="color: #333333;"><</span>String<span style="color: #333333;">></span> itr <span style="color: #333333;">=</span> lib<span style="color: #333333;">.</span><span style="color: #0000cc;">iterator</span><span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">while</span><span style="color: #333333;">(</span>itr<span style="color: #333333;">.</span><span style="color: #0000cc;">hasNext</span><span style="color: #333333;">()){</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>itr<span style="color: #333333;">.</span><span style="color: #0000cc;">next</span><span style="color: #333333;">());</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
</pre>
</div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-40431042851527849372015-11-28T20:51:00.000-08:002015-12-08T09:56:26.347-08:00Breadth-first search in java | using Adjacency list and Adjacency Matrix.<div dir="ltr" style="text-align: left;" trbidi="on">
Dear Friends,<br />
<br />
I am here with a famous traversal method for Graph : Breadth first search [BFS]<br />
<br />
This method is based on the idea of visiting a graph by taking breadth wise approach. The method will become more clear as we see the diagram below and then go through the code for BFS. <br />
<br />
We need three basic entities for implementation of BFS<br />
<br />
1. <span style="color: blue;">Graph</span><br />
2. <span style="color: blue;">Queue</span><br />
3. <span style="color: blue;">State </span>: {<span style="color: blue;">NEW</span>, <span style="color: blue;">IN_Q</span>, <span style="color: blue;">VISITED</span>} This represents the Graph-node's state, initially all the nodes are in <b>NEW</b> state and as it is added in the queue, its state is changed to <b>IN_Q</b> and as it is removed from the queue, its state is changed to <b>VISITED</b>.<br />
<br />
<br />
<img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAokAAAEpCAIAAABwQS8FAAAYoElEQVR4nO3dzZnjuq6FYcflSU9PJI7H0TiKnYGD8Rm42+Xyr0iCxALwvc8e3NO32wJJSKskS6rdBQAAKNl5FwAAAH4hm4EV/vzvv3f/eZcGQA7ZDEy0JYAJaQAPyGZgio64JaEBXJHNgLHBiCWhAZDNgCWrWCWegcrIZsCMbaASz0BZZDNgY0aUEs9ATWQzYGBeiBLPQEFkswSedg1t9qrRFUA1ZLOz50gmp2NZs0w0A1AK2eyDV1KkQTYDMEc2r8YrKTJZuS70AFAH2bwOr6TIh2wGMAPZvAivpMhn/Vqw+kARZPMKvJIiJb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kM0AEIBUHEoVkxLZDAABSMWhVDEpkc0AEIBOHOpUkhjZDAAxiISiSBm5kc0AEINIKIqUkRvZDAAxiISiSBm5kc0AEIZ7LroXUATZDABhuEejewFFkM0AEIljOhLMy5DNABAJ2VwB2QwAwbhkJMG8EtkMAMGQzemRzQAQz+KkJJgXI5sBIKRleUkwr0c2A0BUC1KTYHZBNgNAYFOzk2D2QjYDQGyTEpRgdkQ2A0B4f/73n2GU2n4aOpDNAJDEeKaSyiLIZgBIpS9fSWUpZDMAJHTN2s+Ju+XvwAXZDADJ3WcweRwC2QwAgBayGQAALWQzAABayGYAALSQzQAAaCGbAQDQQjYDAKCFbAYAQAvZDACAFrIZAAAtZDMAAFrIZgAAtJDNAABoIZsBANBCNgMAoIVsBgBAC9kMAIAWshkAAC1kMwAAWshmAAC0kM0AAGghmwEA0EI2AwCghWwGAEAL2QwAgBayGQAALWQzAABayGYAALSQzQAAaCGbAQDQ8n/zjGDQyR161gAAAABJRU5ErkJggg==" /><br />
<br />
<b><span style="color: blue;"><span style="font-size: large;">State</span> </span></b><span style="color: blue;">:<span style="color: black;"> {NEW,IN_Q,VISITED}</span></span><br />
<span style="color: blue;"><span style="color: black;"><span style="color: blue;"><span style="font-size: large;"><b>Queue </b></span>: <b>size </b>=<span style="color: black;"> 0</span></span> </span></span><br />
<span style="font-size: large;"><span style="color: blue;"><b>Graph:</b></span></span><br />
<span style="color: blue;"><b>vertices </b>= <span style="color: black;">{1,2,3,4,5,6,7}</span></span><br />
<span style="color: blue;"><b>node1 :</b> </span><br />
<span style="color: blue;">neighbourList =<span style="color: black;"> 2->3->4->null </span></span><br />
<span style="color: blue;">state :<span style="color: black;"> State.NEW</span><br /><b>node2 : </b></span><br />
<span style="color: blue;">neighbourList = <span style="color: black;">1->5->null </span> </span><br />
<span style="color: blue;">state : <span style="color: black;">State.NEW</span><br /><b>node3 : </b></span><br />
<span style="color: blue;">neighbourList = <span style="color: black;">1->6->7->null </span> </span><br />
<span style="color: blue;">state : <span style="color: black;">State.NEW</span><br /><b>node4 : </b></span><br />
<span style="color: blue;">neighbourList = <span style="color: black;">1->null </span> </span><br />
<span style="color: blue;">state :<span style="color: black;"> State.NEW</span><br /><b>node5 :</b> </span><br />
<span style="color: blue;">neighbourList = <span style="color: black;">2->null </span> </span><br />
<span style="color: blue;">state : <span style="color: black;">State.NEW</span><br /><b>node6 :</b></span><br />
<span style="color: blue;">neighbourList = <span style="color: black;">3->null </span> </span><br />
<span style="color: blue;">state : <span style="color: black;">State.NEW</span><br /><b>node7 : </b></span><br />
<span style="color: blue;">neighbourList =<span style="color: black;"> 3->null </span> </span><br />
<span style="color: blue;">state :<span style="color: black;"> State.NEW</span></span><br />
<b><span style="color: blue;">node8 : </span></b><br />
<span style="color: blue;">neighbourList =<span style="color: black;"> null </span> </span><br />
<span style="color: blue;">state : <span style="color: black;">State.NEW</span></span><br />
<b><span style="color: blue;">node9 : </span></b><br />
<span style="color: blue;">neighbourList = <span style="color: black;">10->11->12->13->null </span> </span><br />
<span style="color: blue;">state : <span style="color: black;">State.NEW</span></span><br />
<b><span style="color: blue;">node10 : </span></b><br />
<span style="color: blue;">neighbourList = <span style="color: black;">9->11->null </span> </span><br />
<span style="color: blue;">state : <span style="color: black;">State.NEW</span></span><br />
<b><span style="color: blue;">node11 : </span></b><br />
<span style="color: blue;">neighbourList = <span style="color: black;">9->10->14->null </span> </span><br />
<span style="color: blue;">state : <span style="color: black;">State.NEW</span></span><br />
<b><span style="color: blue;">node12 : </span></b><br />
<span style="color: blue;">neighbourList =<span style="color: black;"> 9->14->null</span></span><br />
<span style="color: blue;">state :<span style="color: black;"> State.NEW</span></span><br />
<span style="color: blue;"><b>node13 :</b> </span><br />
<span style="color: blue;">neighbourList = <span style="color: black;">9->null</span></span><br />
<span style="color: blue;">state : <span style="color: black;">State.NEW</span></span><br />
<b><span style="color: blue;">node14 : </span></b><br />
<span style="color: blue;">neighbourList = <span style="color: black;">11->12->null</span></span><br />
<span style="color: blue;">state : <span style="color: black;">State.NEW</span></span><br />
<br />
<br />
<b>Basic BFS Algorithm</b><br />
1. Execute a loop for '<b>node-size</b>' number of iterations.<br />
2. for each node with <span style="color: blue;">state != State.VISITED</span> call the <span style="color: blue;">bfs(Node currentNode)</span><br />
3. <span style="color: blue;">queue.add(currentNode) <span style="color: black;">and set the state of the current node :</span> </span> <span style="color: blue;">currentNode.state = State.IN_Q</span><br />
4. run a while loop until <span style="color: blue;">queue.isEmpty() != true</span><br />
<span style="color: blue;">Node visitedNode = queue.remove()</span><br />
<span style="color: blue;"> visitedNode.state = State.VISITED</span><br />
<span style="color: blue;"><b>print(visitedNode)</b></span><br />
<span style="color: blue;">queue.add(all the nodes with state = State.NEW from visitedNode.neighbourList and mark each node's state as State.IN_Q)</span><br />
<br />
<b>Lets Apply BFS to above graph</b><br />
<br />
<span style="color: blue;">Adding in the queue,</span> the <b>node1 </b>, marked it as <span style="color: #bf9000;"><i>In_Q</i></span><br />
<span style="color: purple;">Removing from queue,</span> the <b>node1 </b>, marked it as <span style="color: #990000;"><i>VISITED</i> </span>and Printing it<br />
<span style="color: red;"><b>Printing </b></span>the Visited <b>node1</b><br />
<span style="color: blue;">Adding in the queue,</span> the <b>node2 </b>, marked it as <span style="color: #bf9000;"><i>In_Q</i></span><br />
<span style="color: blue;">Adding in the queue,</span> the <b>node3 </b>, marked it as <span style="color: #bf9000;"><i>In_Q</i></span><br />
<span style="color: blue;">Adding in the queue,</span> the <b>node4 </b>, marked it as <span style="color: #bf9000;"><i>In_Q</i></span><br />
<span style="color: purple;">Removing from queue,</span> the <b>node2 </b>, marked it as <span style="color: #990000;"><i>VISITED </i></span>and Printing it<br />
<span style="color: red;"><b>Printing </b></span>the Visited <b>node2</b><br />
<span style="color: blue;">Adding in the queue,</span> the <b>node5 </b>, marked it as <span style="color: #bf9000;"><i>In_Q</i></span><br />
<span style="color: purple;">Removing from queue,</span> the <b>node3 </b>, marked it as <span style="color: #990000;"><i>VISITED </i></span>and Printing it<br />
<span style="color: red;"><b>Printing </b></span>the Visited <b>node3</b><br />
<span style="color: blue;">Adding in the queue,</span> the <b>node6 </b>, marked it as <span style="color: #bf9000;"><i>In_Q</i></span><br />
<span style="color: blue;">Adding in the queue,</span> the <b>node7 </b>, marked it as <span style="color: #bf9000;"><i>In_Q</i></span><br />
<span style="color: purple;">Removing from queue,</span> the <b>node4 </b>, marked it as <span style="color: #990000;"><i>VISITED </i></span>and Printing it<br />
<span style="color: red;"><b>Printing </b></span>the Visited <b>node4</b><br />
<span style="color: purple;">Removing from queue,</span> the <b>node5 </b>, marked it as <span style="color: #990000;"><i>VISITED </i></span>and Printing it<br />
<span style="color: red;"><b>Printing </b></span>the Visited <b>node5</b><br />
<span style="color: purple;">Removing from queue,</span> the <b>node6 </b>, marked it as <span style="color: #990000;"><i>VISITED </i></span>and Printing it<br />
<span style="color: red;"><b>Printing </b></span>the Visited <b>node6</b><br />
<span style="color: purple;">Removing from queue,</span> the <b>node7 </b>, marked it as <span style="color: #990000;"><i>VISITED </i></span>and Printing it<br />
<span style="color: red;"><b>Printing </b></span>the Visited <b>node7</b><br />
<span style="color: blue;">Adding in the queue,</span> the <b>node8 </b>, marked it as <span style="color: #bf9000;"><i>In_Q</i></span><br />
<span style="color: purple;">Removing from queue,</span> the <b>node8 </b>, marked it as <span style="color: #990000;"><i>VISITED</i> </span>and Printing it<br />
<span style="color: red;"><b>Printing </b></span>the Visited <b>node8</b><br />
<span style="color: blue;">Adding in the queue,</span> the <b>node9 </b>, marked it as<span style="color: #bf9000;"><i> In_Q</i></span><br />
<span style="color: purple;">Removing from queue,</span> the <b>node9 </b>, marked it as <span style="color: #990000;"><i>VISITED </i></span>and Printing it<br />
<span style="color: red;"><b>Printing </b></span>the Visited <b>node9</b><br />
<span style="color: blue;">Adding in the queue,</span> the <b>node10 </b>, marked it as <span style="color: #bf9000;"><i>In_Q</i></span><br />
<span style="color: blue;">Adding in the queue,</span> the <b>node11 </b>, marked it as <span style="color: #bf9000;"><i>In_Q</i></span><br />
<span style="color: blue;">Adding in the queue,</span> the <b>node12 </b>, marked it as <span style="color: #bf9000;"><i>In_Q</i></span><br />
<span style="color: blue;">Adding in the queue,</span> the <b>node13 </b>, marked it as <span style="color: #bf9000;"><i>In_Q</i></span><br />
<span style="color: purple;">Removing from queue, </span>the <b>node10 </b>, marked it as <span style="color: #990000;"><i>VISITED </i></span>and Printing it<br />
<span style="color: red;"><b>Printing </b></span>the Visited <b>node10</b><br />
<span style="color: purple;">Removing from queue,</span> the <b>node11 </b>, marked it as <span style="color: #990000;"><i>VISITED </i></span>and Printing it<br />
<span style="color: red;"><b>Printing </b></span>the Visited <b>node11</b><br />
<span style="color: blue;">Adding in the queue,</span> the <b>node14 </b>, marked it as <span style="color: #bf9000;"><i>In_Q</i></span><br />
<span style="color: purple;">Removing from queue,</span> the <b>node12 </b>, marked it as <span style="color: #990000;"><i>VISITED </i></span>and Printing it<br />
<span style="color: red;"><b>Printing </b></span>the Visited <b>node12</b><br />
<span style="color: purple;">Removing from queue, </span>the <b>node13 </b>, marked it as <span style="color: #990000;"><i>VISITED </i></span>and Printing it<br />
<span style="color: red;"><b>Printing </b></span>the Visited <b>node13</b><br />
<span style="color: purple;">Removing from queue,</span> the <b>node14 </b>, marked it as <span style="color: #990000;"><i>VISITED </i></span>and Printing it<br />
<span style="color: red;"><b>Printing </b></span>the Visited <b>node14</b><br />
<br />
Now Lets see as how we can implement it : Lets use Adjacency List. Friends Please find the code in java below:<br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #888888;">/**</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * @author krishna kumar</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * This is a basic implementation of BFS for Graph using Adjacency list.</span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Graph</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">private</span> Node<span style="color: #333333;">[]</span> vertices<span style="color: #333333;">;</span> <span style="color: #888888;">// stores the nodes of the graph</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">;</span> <span style="color: #888888;">// number of nodes in the graph</span>
<span style="color: #008800; font-weight: bold;">private</span> Queue queue<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Graph</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">size</span> <span style="color: #333333;">=</span> size<span style="color: #333333;">;</span>
vertices <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">[</span>size<span style="color: #333333;">];</span>
addNodes<span style="color: #333333;">();</span>
queue <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Queue<span style="color: #333333;">(</span>size<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Node</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> name<span style="color: #333333;">;</span>
Neighbour neighbourList<span style="color: #333333;">;</span>
State state<span style="color: #333333;">;</span>
Node<span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> name<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">name</span> <span style="color: #333333;">=</span> name<span style="color: #333333;">;</span>
state <span style="color: #333333;">=</span> State<span style="color: #333333;">.</span><span style="color: #0000cc;">NEW</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Neighbour</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> index<span style="color: #333333;">;</span>
Neighbour next<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Neighbour</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> index<span style="color: #333333;">,</span> Neighbour next<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">index</span> <span style="color: #333333;">=</span> index<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">next</span> <span style="color: #333333;">=</span> next<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addNodes</span><span style="color: #333333;">(){</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><=</span> size <span style="color: #333333;">;</span> i<span style="color: #333333;">++){</span>
addNode<span style="color: #333333;">(</span>i<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addNode</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> name<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
vertices<span style="color: #333333;">[</span>name <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">(</span>name<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addEdge</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> sourceName<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> destiName<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> srcIndex <span style="color: #333333;">=</span> sourceName <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> destiIndex <span style="color: #333333;">=</span> destiName <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
Node srcNode <span style="color: #333333;">=</span> vertices<span style="color: #333333;">[</span>srcIndex<span style="color: #333333;">];</span>
Node destiNode <span style="color: #333333;">=</span> vertices<span style="color: #333333;">[</span>destiIndex<span style="color: #333333;">];</span>
srcNode<span style="color: #333333;">.</span><span style="color: #0000cc;">neighbourList</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Neighbour<span style="color: #333333;">(</span>destiIndex<span style="color: #333333;">,</span> srcNode<span style="color: #333333;">.</span><span style="color: #0000cc;">neighbourList</span><span style="color: #333333;">);</span>
<span style="color: #888888;">// the graph is non directional so if from S, D is reachable then vice</span>
<span style="color: #888888;">// versa is also true</span>
destiNode<span style="color: #333333;">.</span><span style="color: #0000cc;">neighbourList</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Neighbour<span style="color: #333333;">(</span>srcIndex<span style="color: #333333;">,</span> destiNode<span style="color: #333333;">.</span><span style="color: #0000cc;">neighbourList</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">traverseGraph</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Using BFS Traversing the graph"</span><span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> size<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>vertices<span style="color: #333333;">[</span>i<span style="color: #333333;">].</span><span style="color: #0000cc;">state</span> <span style="color: #333333;">!=</span> State<span style="color: #333333;">.</span><span style="color: #0000cc;">VISITED</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
bfs<span style="color: #333333;">(</span>vertices<span style="color: #333333;">[</span>i<span style="color: #333333;">]);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">bfs</span><span style="color: #333333;">(</span>Node currentNode<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
queue<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span>currentNode<span style="color: #333333;">);</span>
currentNode<span style="color: #333333;">.</span><span style="color: #0000cc;">state</span> <span style="color: #333333;">=</span> State<span style="color: #333333;">.</span><span style="color: #0000cc;">IN_Q</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">while</span><span style="color: #333333;">(!</span>queue<span style="color: #333333;">.</span><span style="color: #0000cc;">isEmpty</span><span style="color: #333333;">()){</span>
Node visitedNode <span style="color: #333333;">=</span> queue<span style="color: #333333;">.</span><span style="color: #0000cc;">remove</span><span style="color: #333333;">();</span>
visitedNode<span style="color: #333333;">.</span><span style="color: #0000cc;">state</span> <span style="color: #333333;">=</span> State<span style="color: #333333;">.</span><span style="color: #0000cc;">VISITED</span><span style="color: #333333;">;</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>visitedNode<span style="color: #333333;">.</span><span style="color: #0000cc;">name</span><span style="color: #333333;">);</span>
Neighbour temp <span style="color: #333333;">=</span> visitedNode<span style="color: #333333;">.</span><span style="color: #0000cc;">neighbourList</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">while</span><span style="color: #333333;">(</span>temp <span style="color: #333333;">!=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">){</span>
Node neighbour <span style="color: #333333;">=</span> vertices<span style="color: #333333;">[</span>temp<span style="color: #333333;">.</span><span style="color: #0000cc;">index</span><span style="color: #333333;">];</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>neighbour<span style="color: #333333;">.</span><span style="color: #0000cc;">state</span> <span style="color: #333333;">==</span> State<span style="color: #333333;">.</span><span style="color: #0000cc;">NEW</span><span style="color: #333333;">){</span>
queue<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span>neighbour<span style="color: #333333;">);</span>
neighbour<span style="color: #333333;">.</span><span style="color: #0000cc;">state</span> <span style="color: #333333;">=</span> State<span style="color: #333333;">.</span><span style="color: #0000cc;">IN_Q</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
temp <span style="color: #333333;">=</span> temp<span style="color: #333333;">.</span><span style="color: #0000cc;">next</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">enum</span> State <span style="color: #333333;">{</span>
NEW<span style="color: #333333;">,</span> IN_Q<span style="color: #333333;">,</span> VISITED
<span style="color: #333333;">};</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * This is a simple queue implemented using array. Although ideally queue</span>
<span style="color: #888888;"> * should be implemented in circular style so as to use the empty area when</span>
<span style="color: #888888;"> * items are deleted from the front but for BFS implementation we each item</span>
<span style="color: #888888;"> * is added only once so if the size of the queue is taken as the size of</span>
<span style="color: #888888;"> * the items then there is no need for circular styled implementation.</span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Queue</span> <span style="color: #333333;">{</span>
Node<span style="color: #333333;">[]</span> queue<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> maxSize<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> front <span style="color: #333333;">=</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span>rear <span style="color: #333333;">=</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
Queue<span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> maxSize<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">maxSize</span> <span style="color: #333333;">=</span> maxSize<span style="color: #333333;">;</span>
queue <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">[</span>maxSize<span style="color: #333333;">];</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">add</span><span style="color: #333333;">(</span>Node node<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
queue<span style="color: #333333;">[++</span>rear<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> node<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> Node <span style="color: #0066bb; font-weight: bold;">remove</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
Node node <span style="color: #333333;">=</span> queue<span style="color: #333333;">[++</span>front<span style="color: #333333;">];</span>
queue<span style="color: #333333;">[</span>front<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">return</span> node<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">isEmpty</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> front <span style="color: #333333;">==</span> rear<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
Graph graph <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Graph<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">14</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">7</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">9</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">13</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">9</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">12</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">9</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">11</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">9</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">10</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">10</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">11</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">11</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">14</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">12</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">14</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">traverseGraph</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br />
<br />
<br />
<br />
<br />
<br />
Below friends, please find the code for Implementation of BFS using Adjacency Matrix<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #888888;">/**</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * @author krishna kumar</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * Below code shows basic implementation of DFS in a graph. Graph has</span>
<span style="color: #888888;"> * been implemented using adjacency matrix</span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Graph</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[][]</span> adjacencyMatrix<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">;</span> <span style="color: #888888;">// number of nodes in the graph</span>
<span style="color: #008800; font-weight: bold;">private</span> State<span style="color: #333333;">[]</span> states<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> Queue queue<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Graph</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">size</span> <span style="color: #333333;">=</span> size<span style="color: #333333;">;</span>
adjacencyMatrix <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[</span>size<span style="color: #333333;">][</span>size<span style="color: #333333;">];</span><span style="color: #888888;">// Initialized with all 0s</span>
states <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> State<span style="color: #333333;">[</span>size<span style="color: #333333;">];</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> size<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
states<span style="color: #333333;">[</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> State<span style="color: #333333;">.</span><span style="color: #0000cc;">NEW</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
queue <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Queue<span style="color: #333333;">(</span>size<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addEdge</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> sourceName<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> destinationName<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> sourceIndex <span style="color: #333333;">=</span> sourceName <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> destinationIndex <span style="color: #333333;">=</span> destinationName <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
adjacencyMatrix<span style="color: #333333;">[</span>sourceIndex<span style="color: #333333;">][</span>destinationIndex<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #888888;">// the graph is non directional so if from S, D is reachable then vice</span>
<span style="color: #888888;">// versa is also true</span>
adjacencyMatrix<span style="color: #333333;">[</span>destinationIndex<span style="color: #333333;">][</span>sourceIndex<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">traverseGraph</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Using BFS Traversing the graph"</span><span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> size<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>states<span style="color: #333333;">[</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">!=</span> State<span style="color: #333333;">.</span><span style="color: #0000cc;">VISITED</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
bfs<span style="color: #333333;">(</span>i<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">bfs</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> currentNodeName<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
queue<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">(</span>currentNodeName<span style="color: #333333;">);</span>
states<span style="color: #333333;">[</span>currentNodeName<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;">=</span> State<span style="color: #333333;">.</span><span style="color: #0000cc;">IN_Q</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">while</span><span style="color: #333333;">(!</span>queue<span style="color: #333333;">.</span><span style="color: #0000cc;">isEmpty</span><span style="color: #333333;">()){</span>
<span style="color: #333399; font-weight: bold;">int</span> visitedNodeName <span style="color: #333333;">=</span> queue<span style="color: #333333;">.</span><span style="color: #0000cc;">remove</span><span style="color: #333333;">();</span>
states<span style="color: #333333;">[</span>visitedNodeName<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;">=</span> State<span style="color: #333333;">.</span><span style="color: #0000cc;">VISITED</span><span style="color: #333333;">;</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>visitedNodeName<span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> size<span style="color: #333333;">;</span> i<span style="color: #333333;">++){</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>adjacencyMatrix<span style="color: #333333;">[</span>visitedNodeName<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">][</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">!=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>states<span style="color: #333333;">[</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> State<span style="color: #333333;">.</span><span style="color: #0000cc;">NEW</span><span style="color: #333333;">){</span>
queue<span style="color: #333333;">.</span><span style="color: #0000cc;">add</span><span style="color: #333333;">((</span>i<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">));</span>
states<span style="color: #333333;">[</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> State<span style="color: #333333;">.</span><span style="color: #0000cc;">IN_Q</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">enum</span> State <span style="color: #333333;">{</span>
NEW<span style="color: #333333;">,</span> IN_Q<span style="color: #333333;">,</span> VISITED
<span style="color: #333333;">};</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * This is a simple queue implemented using array. Although ideally queue</span>
<span style="color: #888888;"> * should be implemented in circular style so as to use the empty area when</span>
<span style="color: #888888;"> * items are deleted from the front but for BFS implementation we each item</span>
<span style="color: #888888;"> * is added only once so if the size of the queue is taken as the size of</span>
<span style="color: #888888;"> * the items then there is no need for circular styled implementation.</span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Queue</span> <span style="color: #333333;">{</span>
Integer<span style="color: #333333;">[]</span> queue<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> maxSize<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> front <span style="color: #333333;">=</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span>rear <span style="color: #333333;">=</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
Queue<span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> maxSize<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">maxSize</span> <span style="color: #333333;">=</span> maxSize<span style="color: #333333;">;</span>
queue <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Integer<span style="color: #333333;">[</span>maxSize<span style="color: #333333;">];</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">add</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> node<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
queue<span style="color: #333333;">[++</span>rear<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> node<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">remove</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> node <span style="color: #333333;">=</span> queue<span style="color: #333333;">[++</span>front<span style="color: #333333;">];</span>
queue<span style="color: #333333;">[</span>front<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">return</span> node<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">isEmpty</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> front <span style="color: #333333;">==</span> rear<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
Graph graph <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Graph<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">14</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">7</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">9</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">10</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">9</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">11</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">9</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">12</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">9</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">13</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">10</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">11</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">11</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">14</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">12</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">14</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">traverseGraph</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br />
<br />
<h1 class="firstHeading" id="firstHeading" lang="en">
</h1>
</div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-90191225145430911152015-11-24T21:54:00.001-08:002015-12-08T10:00:43.055-08:00Understanding Depth first Search DFS using Java (for trees and Graphs)<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
<br />
DFS is one of the algorithm that we can use to traverse the elements of a Graph.<br />
<br />
Lets try to build the algorithm for DFS below. For simplicity lets use tree with multiple children (tree is also a special type of graph).<br />
<br />
<br />
<img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAacAAAFGCAIAAABBlcfoAAAVK0lEQVR4nO2dy5nyShIFZRebu72WYA/WYMX1AGOYBT00DUKvep2T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u98MYevxUd+GNsL6eYL7rTHMU2yjZwuj2HdonptJO6xXnfUWtd3QY5tf//dIozjyp0LcTKpj/Qkrkixi6BuWKfoDSW4mtfC1nvUWtd3QrAJlRP8sPBW+JyccfbpxaJ5iBwbrjQfr9b/4xgB4ih0SrDeYnscaxC84ZIgtMfAUOxhYbzBYb+wQ2+Epdhiw3mBMrWcaNsAd641l75L+fVnDodfS9T6WcT3veq3E8YEA9oD1RrJrSe99hXPhcKWXegn3djkdjhzrQXWw3kh2LOkScxwYrvg6f+ItCx7xQV2w3kh2rOfHm1cv///MeEghPa33sdfDeqAC1hvJTuv93xxHP+t2td7LY73T+cxeD3TAeiPZvde7zfyHJsPVvc7BeI8OB7AI1hvJnvX8Yo6jEhlkvdJfw2A9qAvWG8m+9fx7buWgQ/par8a5lR3DAWwF6w3G8bhvZw1hPagL1hsM1lMbDsKD9QbjaL3qV1MYCPKA9cbj+Gf8WA98wXrjwXoKA0EesJ4Ejl/P6ShrgDvWEwHrjRoCEoL1VHB0k+/FITNYTwi7p29YDxzBelrYnapz3KJCcrCeHHbvY7XbokJysJ4idu9jtduiQmawni5e72O126JCWrCeOkbvY7XbokJOsJ4NLu9j9dqiQkKwHjTBaIsK2cB60BaXLSrkAesBQC6wHgDkAusBQC6wHgDkAusBQC6wHgDkAusBQC6wHgDk4n+exT8cBw6jyAAAAABJRU5ErkJggg==" /> <br />
<br />
<br />
Lets try to follow below steps and see how we traverse the above tree.<br />
<br />
<br />
Lets have 3 basic entities to implement DFS algorithm:<br />
<span style="color: blue;">1. currentNode</span><br />
<span style="color: blue;">2. currentConnectedList <span style="color: black;">(<i>List to contain connected nodes</i>)</span></span><br />
<span style="color: blue;"><span style="color: blue;">3. visited[] </span><i></i><span style="color: black;"><span style="color: black;"><i><span style="color: black;">(</span></i></span></span></span><i><span style="color: blue;"><span style="color: black;">Array of type <b>boolean</b> and <b>size = number of nodes </b>in the graph and all cells initialized with false,</span> </span><span style="color: blue;"><span style="color: blue;"><span style="color: blue;"><span style="color: black;">let us have node with name 'i' be mapped with cell with index as 'i-1'</span></span></span><span style="color: black;">)</span></span></i><br />
<span style="color: blue;"></span><br />
<span style="color: blue;"><span style="color: black;"><span style="color: black;"><i> </i></span></span> </span><br />
<br />
<b>Algorithm :</b><br />
<b>1</b>. Pick a node and mark it as <span style="color: blue;">currentNode</span><br />
<b>2</b>. For the <span style="color: blue;">currentNode</span>, find the connected nodes and add them in its <span style="color: blue;">currentConnectedList</span><br />
<b>3</b>. Set the cell value in array <span style="color: blue;"><span style="color: blue;">visited </span></span>as true for the cell corresponding to the <span style="color: blue;">currentNode</span><br />
<b>4</b>. print the visited node name <span style="color: blue;">print(nodeName)</span><br />
<b>5</b>. pick the <b>first Non visited node </b>from the current node's <span style="color: blue;">currentConnectedList </span>and mark it as <span style="color: blue;">currentNode</span><br />
In case <span style="color: blue;">currentConnectedList </span>has no nodes in it or all the nodes have been visited then go to parent Node of the <span style="color: blue;">currentNode</span> and pick next non visited node. <span style="color: blue;"><b>In case the parent node is null then break the loop.</b></span><br />
<span style="color: blue;"><span style="color: black;"><i>[we have put the condition to pick the <b>non visited ones</b>, when working with Graphs with cycles then it is this condition that prevents the algorithm from running infinitely by being stuck in the cycle.]</i></span> </span><br />
<b>6</b>. Go to step 2. <br />
<br />
<br />
<br />
<span style="color: blue;">currentNode </span>= 1<br />
<span style="color: blue;">visited </span>= [<span style="color: blue;">true</span>][false][false][false][false][false][false][false][false][false][false][false][false][false]<br />
<span style="color: blue;">print(1)<span style="color: blue;"> </span></span><br />
<span style="color: blue;"><span style="color: blue;">currentConnectedList</span> = 2</span>->7->14 [1st non visited node is 2 so <br />
2 will be picked next and we will come back for 7 and 14 later] <br />
<br />
<span style="color: blue;">currentNode </span>= 2<br />
<span style="color: blue;">visited</span> = [true][<span style="color: blue;">true</span>][false][false][false][false][false][false][false][false][false][false][false][false]<br />
<span style="color: blue;">print(2)</span><br />
<span style="color: blue;">currentConnectedList</span>= <span style="color: blue;">3</span>->5<br />
<br />
<span style="color: blue;">currentNode </span>= 3<br />
<span style="color: blue;">visited </span>= [true][true][<span style="color: blue;">true</span>][false][false][false][false][false][false][false][false][false][false][false]<br />
<span style="color: blue;">print(3)</span><br />
<span style="color: blue;">currentConnectedList</span>= <span style="color: blue;">4</span> <br />
<br />
<span style="color: blue;">currentNode </span>= 4<br />
<span style="color: blue;">visited </span>= [true][true][true][<span style="color: blue;">true</span>][false][false][false][false][false][false][false][false][false][false]<br />
<span style="color: blue;">print(4)</span><br />
<span style="color: blue;">currentConnectedList</span>= <span style="color: red;">NULL</span><br />
<br />
As currentConnectedList has no nodes so we go to parent of 4, i.e. 3. Lets go to 3 and see who is left unvisited. At currentNode = 3 we find only one element in <br />
connectedList = 4, and 4 already has been visited (we see in the Visited array) so nothing left to pick from here<br />
<br />
Lets go to parent of 3, i.e. 2 and see who is left unvisited. for 2 we see connectedList = 3->5, from visited array we find 3 already have been visited so now we pick 5<br />
<br />
<span style="color: blue;">currentNode </span>= 5<br />
<span style="color: blue;">visited </span>= [true][true][true][true][<span style="color: blue;">true</span>][false][false][false][false][false][false][false][false][false]<br />
<span style="color: blue;">print(5)<br />currentConnectedList= 6<br /><br />currentNode</span> = 6<br />
<span style="color: blue;">visited </span>= [true][true][true][true][true][<span style="color: blue;">true</span>][false][false][false][false][false][false][false][false]<br />
<span style="color: blue;">print(6)</span><br />
<span style="color: blue;">currentConnectedList</span>= <span style="color: red;">NULL</span><br />
<br />
Similar to above again we have a situation when connectedList do not have any element.<br />
Lets go to parent of 6 i.e. 5 and there we see only connected element was 6 which has already <br />
been visited so we go to parent of 5 i.e. 2 and again we find connectedList = 3->5 and these<br />
both elements have been visited. So now lets see parent of 2 i.e 1, for 1 we see connectedList = 2->7->14.<br />
As per our rule, lets pick first non visited node from the connected List i.e. 7<br />
<br />
<span style="color: blue;">currentNode </span>= 7<br />
<span style="color: blue;">visited </span>= [true][true][true][true][true][true][<span style="color: blue;">true</span>][false][false][false][false][false][false][false]<br />
<span style="color: blue;">print(7)</span><br />
<span style="color: blue;">currentConnectedList</span>= <span style="color: blue;">8</span>->10->13<br />
<br />
<span style="color: blue;">currentNode </span>= 8<br />
<span style="color: blue;">visited </span>= [true][true][true][true][true][true][true][<span style="color: blue;">true</span>][false][false][false][false][false][false]<br />
<span style="color: blue;">print(8)</span><br />
<span style="color: blue;">currentConnectedList</span>= <span style="color: blue;">9</span><br />
<br />
<span style="color: blue;">currentNode</span> = 9<br />
<span style="color: blue;">visited </span>= [true][true][true][true][true][true][true][true][<span style="color: blue;">true</span>][false][false][false][false][false]<br />
<span style="color: blue;">print(9)</span><br />
<span style="color: blue;">currentConnectedList</span>= <span style="color: red;">NULL</span><br />
<br />
going to 8 we see no more node left unvisited so lefts go to 7 and there we see connectedList = 8->10 <br />
and 8 has already been visited so next unvisited node is 10 <br />
<br />
<span style="color: blue;">currentNode </span>= 10<br />
<span style="color: blue;">visited </span>= [true][true][true][true][true][true][true][true][true][<span style="color: blue;">true</span>][false][false][false][false]<br />
<span style="color: blue;">print(10)</span><br />
<span style="color: blue;">currentConnectedList</span>= <span style="color: blue;">11</span>->12<br />
<br />
<span style="color: blue;">currentNode </span>= 11<br />
<span style="color: blue;">visited </span>= [true][true][true][true][true][true][true][true][true][true][<span style="color: blue;">true</span>][false][false][false]<br />
<span style="color: blue;">print(11)</span><br />
<span style="color: blue;">currentConnectedList</span>= null<br />
<br />
Going to 10 , we find connectedList = 11->12 and as 11 has already been visited so next unvisited node is 12<br />
<br />
<span style="color: blue;">currentNode </span>= 12<br />
<span style="color: blue;">visited </span>= [true][true][true][true][true][true][true][true][true][true][true][<span style="color: blue;">true</span>][false][false]<br />
<span style="color: blue;">print(12)</span><br />
<span style="color: blue;">currentConnectedList</span>= <span style="color: red;">NULL</span><br />
<br />
Going to parent of 12 i.e. 10 we find all the nodes in its connectedList have been visited<br />
so going to parent of 10 i.e. 7 we find connectedList = 8->10->13, 8 and 10 have already been visited so next we have 13 to pick<br />
<br />
<span style="color: blue;">currentNode </span>= 13<br />
<span style="color: blue;">visited </span>= [true][true][true][true][true][true][true][true][true][true][true][true][<span style="color: blue;">true</span>][false]<br />
<span style="color: blue;">print(13)</span><br />
<span style="color: blue;">currentConnectedList</span>= <span style="color: red;">NULL</span><br />
<br />
Going back to 7 we find no more unvisited node in the connectedList, so going to parent of 7 i.e. 1 we see its connectedList = 2->7->14.<br />
As 2 and 7 have already been visited, we are left with 14. <br />
<br />
<span style="color: blue;">currentNode </span>= 14<br />
<span style="color: blue;">visited </span>= [true][true][true][true][true][true][true][true][true][true][true][true][true][<span style="color: blue;">true</span>]<br />
<span style="color: blue;">print(14)</span><br />
<span style="color: blue;">currentConnectedList</span>= <span style="color: red;">NULL</span><br />
<br />
As no element in the connectedList, we go to the parent of 14, i.e. 1 and 1 has all its nodes in the connectedList 2->7->14 as visited.<br />
<span style="color: blue;"><b>Parent of 1 is Null hence we have reached the starting Node, so we are done with visiting all the nodes.</b></span><br />
<br />
Now having understood a basic idea about the DFS, lets see a graph below and do some analysis.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfMAAAGvCAIAAADAIauQAAAYNElEQVR4nO3dW3rizA6FYY+LATEeRsNkGAx9QZqQhIPt0mFJ9b1X++9nN1apVCvGIenlCgDoZckuAABgjGQHgG5IdgDohmQHgG5IdgDYYPkku8DrlWQHgDXWB7dCypPsAPDOSEZn5TvJDgDPWeVyfL6T7ADwm0cWR+Y7yQ4AP7jmb0y4k+wA8C0geSMu4X0BACgh9GmJ87VIdgAIekgSdlGSHcDsMj947nNpkh3A7Eh2AGgl/fcBeBRAsgOYV3qs39h/dt725QCgCpFYv7EtRmhhABCJZAeAVqRi/cawJLm13ZX4JcgAihLMkM7JXuuXIAOoSDY0rAoTWl7FX4IMoCLZuGiV7HV/CfLkeGKGomSHs0mye5x/MsUbT8xQmvg02tzmjr/E/mvX/yXIs+GJGRoQn8PayR7QXPH9q4UnZmjDagIvp8PXG9LD6WLyitf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VLCjPvygHYkkpSqWLiTb14AIakwlSqmHhTLx6ALZE8FSkj0ezrB2ArPVXTC1BACwAYS8xWYv2GLgAwRrKnowsA7KUkLLF+RyMAuLj920j9rlUCvQDgKCBwyfS/6AgAX67JS6w/RVMAuPN4WsITmDfoC4AgVllMpn9EdwCEWv4L+4sTokcAcqxJ6uVBWGEN0CwAyZbXskurisYBQDckOwB0Q7IDQDckOwB0Q7IDQDckOwB0Q7IDQDckOwB0Q7IDQDckOwB0Q7IDQDckOwB0Q7IDQDckOwB08w+Vqs816znuGwAAAABJRU5ErkJggg==" /><br />
<br />
Here we see the graph contains 3 sub graphs, 1,2,3,4,5,6,7 are connected then 9,10,11 are connected and then 8 is alone. These 3 sub graph make up our complete graph. Suppose this graphs represents good baseball players from 3 different teams (say Team A, Team B and Team C) who are coming to some separate city be part of some super team. Now suppose we wish to pass some information to all these players then it is enough if we pass that information to any 1 player from each team (so at-least we need to pass information to 3 players).<br />
<br />
Here DFS can come handy. We can start a for loop set for 11 iterations and then run the DFS for the node (representing a player) if it is not visited. DFS will visit all the connected nodes (players). Then coming back to the next iterations of the loop, as another non visited node is encountered (meaning we have a node from another sub graph) we need to execute DFS again to visit the nodes of that sub graph.<br />
<br />
<b>In above case 3 times DFS will run 1st for Node-1, 2nd for Node 8 and 3rd for Node-9.</b><br />
<br />
Now lets see the implementation of DFS below:<br />
<br />
<br />
Below lets see the code for DFS in graph implemented using Adjacency matrix and then using Adjacency list <br />
<br />
Code using Adjacency Matrix :<br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #888888;">/**</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * @author krishna kumar</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * Below code shows basic implementation of DFS in a graph. Graph has</span>
<span style="color: #888888;"> * been implemented using adjacency matrix</span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Graph</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[][]</span> adjacencyMatrix<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">;</span> <span style="color: #888888;">// number of nodes in the graph</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">boolean</span><span style="color: #333333;">[]</span> visited<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Graph</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">size</span> <span style="color: #333333;">=</span> size<span style="color: #333333;">;</span>
adjacencyMatrix <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[</span>size<span style="color: #333333;">][</span>size<span style="color: #333333;">];</span><span style="color: #888888;">// Initialized with all 0s</span>
visited <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">boolean</span><span style="color: #333333;">[</span>size<span style="color: #333333;">];</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addEdge</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> sourceName<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> destinationName<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> sourceIndex <span style="color: #333333;">=</span> sourceName <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> destinationIndex <span style="color: #333333;">=</span> destinationName <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
adjacencyMatrix<span style="color: #333333;">[</span>sourceIndex<span style="color: #333333;">][</span>destinationIndex<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #888888;">// the graph is non directional so if from S, D is reachable then vice</span>
<span style="color: #888888;">// versa is also true</span>
adjacencyMatrix<span style="color: #333333;">[</span>destinationIndex<span style="color: #333333;">][</span>sourceIndex<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">traverseGraph</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Using DFS Traversing the graph"</span><span style="color: #333333;">);</span>
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * If graph contains disconnected nodes or sub graphs then below loops</span>
<span style="color: #888888;"> * makes sure that all such nodes or sub graphs are also visited</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * In a single connected graph below loop is not needed and simply</span>
<span style="color: #888888;"> * dfs(1); can be called and the graph will be visited.</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><=</span> size<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(!</span>visited<span style="color: #333333;">[</span>i <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">])</span> <span style="color: #333333;">{</span>
dfs<span style="color: #333333;">(</span>i<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">dfs</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> currentNodeName<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
visited<span style="color: #333333;">[</span>currentNodeName <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>currentNodeName<span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> size<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>adjacencyMatrix<span style="color: #333333;">[</span>currentNodeName <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">][</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">!=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(!</span>visited<span style="color: #333333;">[</span>i<span style="color: #333333;">])</span> <span style="color: #333333;">{</span>
dfs<span style="color: #333333;">(</span>i <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
Graph graph <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Graph<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">11</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">7</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">9</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">11</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">10</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">11</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">traverseGraph</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /></div>
<br />
Below lets use adjacency List and see the implementation. For Linked List implementation of Stack styled Linked list have been used [ holding the reference of the last added element in the graph]<br />
We will use class Node to represent the graph-node so instead of separate array 'visited',
we can simply declare a boolean field : 'visited' in class Node itself.<br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> com<span style="color: #333333;">.</span><span style="color: #0000cc;">graph</span><span style="color: #333333;">.</span><span style="color: #0000cc;">adjacencylist</span><span style="color: #333333;">;</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * @author krishna kumar</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * This is a basic implementation of Graph using Adjacency list.</span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Graph</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">private</span> Node<span style="color: #333333;">[]</span> vertices<span style="color: #333333;">;</span> <span style="color: #888888;">// stores the nodes of the graph</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">;</span> <span style="color: #888888;">// number of nodes in the graph</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Graph</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">size</span> <span style="color: #333333;">=</span> size<span style="color: #333333;">;</span>
vertices <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">[</span>size<span style="color: #333333;">];</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Node</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> name<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">boolean</span> visited <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
Neighbour neighbourList<span style="color: #333333;">;</span>
Node<span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> name<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">name</span> <span style="color: #333333;">=</span> name<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Neighbour</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> index<span style="color: #333333;">;</span>
Neighbour next<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Neighbour</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> index<span style="color: #333333;">,</span> Neighbour next<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">index</span> <span style="color: #333333;">=</span> index<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">next</span> <span style="color: #333333;">=</span> next<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addNode</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> name<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
vertices<span style="color: #333333;">[</span>name <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">(</span>name<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addEdge</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> sourceName<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> destiName<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> srcIndex <span style="color: #333333;">=</span> sourceName <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> destiIndex <span style="color: #333333;">=</span> destiName <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
Node srcNode <span style="color: #333333;">=</span> vertices<span style="color: #333333;">[</span>srcIndex<span style="color: #333333;">];</span>
Node destiNode <span style="color: #333333;">=</span> vertices<span style="color: #333333;">[</span>destiIndex<span style="color: #333333;">];</span>
srcNode<span style="color: #333333;">.</span><span style="color: #0000cc;">neighbourList</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Neighbour<span style="color: #333333;">(</span>destiIndex<span style="color: #333333;">,</span> srcNode<span style="color: #333333;">.</span><span style="color: #0000cc;">neighbourList</span><span style="color: #333333;">);</span>
<span style="color: #888888;">// the graph is non directional so if from S, D is reachable then vice</span>
<span style="color: #888888;">// versa is also true</span>
destiNode<span style="color: #333333;">.</span><span style="color: #0000cc;">neighbourList</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Neighbour<span style="color: #333333;">(</span>srcIndex<span style="color: #333333;">,</span> destiNode<span style="color: #333333;">.</span><span style="color: #0000cc;">neighbourList</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">traverseGraph</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * If graph contains disconnected nodes or sub graphs then below loops</span>
<span style="color: #888888;"> * makes sure that all such nodes or sub graphs are also visited</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * In a single connected graph below loop is not needed and simply</span>
<span style="color: #888888;"> * dfs(vertices[0]); can be called and the graph will be visited.</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> size<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(!</span>vertices<span style="color: #333333;">[</span>i<span style="color: #333333;">].</span><span style="color: #0000cc;">visited</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
dfs<span style="color: #333333;">(</span>vertices<span style="color: #333333;">[</span>i<span style="color: #333333;">]);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">dfs</span><span style="color: #333333;">(</span>Node currentNode<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
currentNode<span style="color: #333333;">.</span><span style="color: #0000cc;">visited</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>currentNode<span style="color: #333333;">.</span><span style="color: #0000cc;">name</span><span style="color: #333333;">);</span>
Neighbour temp <span style="color: #333333;">=</span> currentNode<span style="color: #333333;">.</span><span style="color: #0000cc;">neighbourList</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">while</span> <span style="color: #333333;">(</span>temp <span style="color: #333333;">!=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(!</span>vertices<span style="color: #333333;">[</span>temp<span style="color: #333333;">.</span><span style="color: #0000cc;">index</span><span style="color: #333333;">].</span><span style="color: #0000cc;">visited</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
dfs<span style="color: #333333;">(</span>vertices<span style="color: #333333;">[</span>temp<span style="color: #333333;">.</span><span style="color: #0000cc;">index</span><span style="color: #333333;">]);</span>
<span style="color: #333333;">}</span>
temp <span style="color: #333333;">=</span> temp<span style="color: #333333;">.</span><span style="color: #0000cc;">next</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
Graph graph <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Graph<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">11</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">7</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">8</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">9</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">10</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">11</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">7</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">9</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">11</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">10</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">11</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">traverseGraph</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /></div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-64333224669890251682015-11-22T12:28:00.001-08:002015-11-22T12:28:10.267-08:00Basics of Graph in computer science using Java<div dir="ltr" style="text-align: left;" trbidi="on">
Hello friends,<br />
<br />
Lets try to have basic understanding of Graphs in computer science context.<br />
<ul style="text-align: left;">
<li>Graph is a way to represent the data : it is a Data structure.</li>
<li>It consists of Nodes (or Vertices, we will use the term nodes) and Nodes are connected with edges.</li>
<li>To identify a Node, each node has a unique name.</li>
<li>An Edge is identified by the pair of nodes it connects.</li>
<li>Each node has a value, often called as 'cost'. Nodes may or may not have same values. Note that this 'cost' is dependent upon the scenario and not for all graphs we require to associate 'cost' with its node.</li>
<li>Each edge has a value, often called as 'weight'. These may be same or in some cases all the edges may have same value. Like 'cost' of a node, edge-weight is also dependent upon the scenario and not all graphs are required to have 'weight' associated with its edges.</li>
<li>In case edges of the graph is directional then for each edge one of the pair of nodes connected by that edge is called the source and other node of the pair is called the destination. Such graph is called Directed Graph. It may happen that a single pair of nodes have two different edges and also may have two different weights.</li>
<li>In case the direction does not matter then the edges do not have a direction and such graph is called Non directed graph. In-fact this is a special case of directed graph, where each pair of node is connected by two edges of same weight such that for source node of one edge is destination node for other edge and vice versa.</li>
<li>In case of a directed graph if there is no cycle then it is called as ;DAG, directed a-cyclic graph. </li>
</ul>
<br /><div>
Above are the basic definitions of the graphs. Below lets see few examples of Graph.<br /><br /><img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAq4AAAKSCAIAAACcJc6HAAAgAElEQVR4nO3dPa7cONSn8VqIo4FXoaTThjFBZ7MDLcCBg1mFQgNexSQCXhjeQe9AsHfQgXEDw4ABTVBVKlI6pKgv6lDn+eEC3b5XHxSlEv+iVOKtBwAAht3OLgAAADgTUQAAANOIAgAAmEYUAADANKIAAACmEQUAADCNKAAAgGlEAQAATCMKAABgGlEAAADTiAIAAJhGFAAAwDSiAAAAphEFAAAwjSgAAIBpRAEAAEwjCgAAYBpRAAAA04gCAACYRhQAAMA0ogAAAKYRBQAAME1pFPjr73/jP2cXEABM4Gxsga4okH5scSACwEEWnWA5G1+Aliiw5TDiEASA7ba36GSCQp0fBfY6bjj+AOXoalZr9/pnh5blzChwxLHC8QeoQlezcofWNruyFKdFgUOPDw4+4Fx0NRchT/WyE/U7IQrk+XhzEgFOQVdzKXLWKntQudxRIPMBwfEHZENXcylOqUz2oGZZo8ApxwEH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SRHgL34cTEjgQgC6IAANu+fnIv0LmFD4OIAgBs86JAcm8/cCFEAQDGeXcN6BKAQUQBAABMIwoAAGAaUQAAANOIAgAAmEYUAADANKIAAACmEQUAADCNKAAAgGlEAQAATCMKAABgGlEAAADTiAIAAJhGFAAAwLT/D9XIQN7z+zlHAAAAAElFTkSuQmCC" /><br /><br /><img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAh8AAAIcCAIAAADZq1soAAAgAElEQVR4nO3dPa7jNheHcS9kylmFm2mDVFmFF5Ai63AZYPbhJsgOsgMj2cEUgymCAC+gt9C1TEmUREn8+B/y+WEQZOba1iF5xEPJku6lAwAgtkvpAAAAFaK6AADio7oAAOKjugAA4qO6AADio7oAAOKjugAA4qO6AADio7oAAOKjugAA4qO6AADio7oAAOKjugAA4itZXb789Nf6n4KxAQDOKFBdwosHlQYogpUfzstXXU7mJWkNpMbKDxHlqC5xU5CEPo+VKVys/JBC2uqSLufI5gNYmWKClZ+amlZ+CatLho6w1delsDLFHCs/KVWu/JJUl5wtN9HLpbAyhRcrPxF1r/ziV5ciTZXt31JYmcKLlZ+IFlZ+katLwRYKdm4prEzhxcpPQTsrv5jVpXjDigdQHCtTLGHlp6CplV+06iLSJJEwimBliiXFh6l4AMU1uPKLU10UWjKQCiYbVqZYIjJAImEU0ebKj+pSg+JNLh4AlkgNjVQw2TS78otQXQQzRjCkdEQaKxIGJqTGRSqYPIo3uWAAZ6tL8b5bIhtYXFLNlAoGneSICIaUjkhjS4VBdbFNqplSwUB2OGQDi0uqmUWCOVVdpLpvTjy88wQbKBhSs2THQjawuKSaSXWJTDy8k2RbJxtYU8RHQTy88wQbmD+k49VFsPvmTAR5jGzTZANrivgoiId3kmzrMgdGdTFJvF3i4VXPRP+bCPIY2abZqC6y3TdhJc69xNslHl71TPS/iSAPEG9XzvAqry6dqVADmWiRiSCrZKXnrcS5l3i7qC4xGQo1kIkWmQiySoZ63lCogUy0KFuQVBdjrDTHSpz1MdTzhkINZK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+3++/vL7k//pjrbqMT46tHMdQXVRRXbKw+QBt4Lg/fnPvhvnv1/6aMTSE6pKHyQdoA8eNqkvwaS5UhOoCIIXR6TIOXBpEdQEAxEd1AQDER3UBAMRHdQEAxFdvdeG3TQBAOeari9xvm+i6ydUyVDgADaqhuohN3//8+/Pnb7/+WToMACipzupS+LdNuIdQANCkGqqL1G+b+N/vv/QHLsPzlMQOrQAghxqqi9Rvmxiqiy8GAGhFO9WF3zYBAPk0U12y/baJ7s8f76cqUV0ANKrK6lL0t010XV9gtn9jKwDUy3x1CcVvmwCAjNqsLvy2CQBIq5nqwm+bAICM2qkuAIB8qC4AgPioLgCA+P4P+Ov7TBLAn44AAAAASUVORK5CYII=" /><br /><br /><br /><br /> Graphs can used to represent data of any social networking sites, where each user can be represented by the node. If the two users are connected with each other on the site then the nodes representing the two users can be connected by an edge. For the non connected users, their nodes are not connected by any edge.<br /><br />Similarly cites connected via roads can also be represented by Graphs. Each city may be represented by the node and if two cities are connected then their corresponding nodes can be connected using an edge. We can have distance or the amount of time required to travel between two cities as the weight of the edge. Suppose each city has a market and there is a businessman who travels to different cities and to for each visit to a particular city he books a hotel. The cost of the hotel may be represented by the cost of the Node corresponding to that particular city.There are many such other scenarios where graph may be useful. <br /><br />For representation of Graph we have two methods. <br /><ol style="text-align: left;">
<li><b>Adjacency List</b></li>
<li><b>Adjacency Matrix</b></li>
</ol>
</div>
<div style="text-align: left;">
<b><br /><img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYUAAAFPCAIAAAAtMkXNAAAW0klEQVR4nO3dPc7cthaHcS3E5V2FGrdGqqxCC3CRdagMkC6LUGNkB97BIKndpDBSBAYC8BaakSiJoiiNSJ5DPj8Y9zqTeeflx+E/lEYzagwAyNDkbgAAPJFHAKQgjwBIQR4BkII8AiAFeQRACvIIgBTkEQApyCMAUpBHAKQgjwBIQR4BkII8AiAFeQRACvIIgBTkEQApyCMAUpBHAKSQlUcfP331/8ndQAARicij8Lghm4CC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rMvCCJhGB1nUMeBYo0ULenEtsiUVhdpxFJfvdui9y/4vdv7+TI9OMkkTQsrSuIJKcESbT+jcHJQgapwLq6iEhayT4gduJs/+RtGwKxqK7LvgKFSL8tQqkoo7dUvg5JItyLYnpXnQuSJEIMlNQNqlqZJBHiobDuUckSraSbyIXyuk3Za5VtERKgwu5U5IoliZAMdXazkpYuSYTEqLb7FbCGSSJkQc1FoXcxk0TIiMqLRd3CVtdglIf6i0vFCieJIARVGJ3Ypd685G4I8EQtpiBt2UtrDzCiKNOREAEkESSjNJPKFQccmkEFCjSDZNFADEEXKjWbeElBDEEpSjazu7KjsdzSMCA9aleKZunUk8kglIE6FmqbOKQPikdlA5CCPAIgBXkkzKNvx0Oytn/kbguQGHkkyqNvu8EYY8zQkUioDnkk1KNvm2c0AbUgj4QaOuII1SGPJHr0LUdrqBB5JA5hhGqRR7IQRqgZeSTK0C0uw+YMEupCHgGQgjwCIAV5BEAK8giAFOQRACnIIwBSkEcApCCPAEhBHgGQgjwK9udv3z/8758vuZsBlIs8Wvvx+X9/f3j9+fzH/C+y5dFf//600ySgLOTR2o/PMjdBf/zz4ZcfuRsBREUerbnyaNqhLBPhz9++f5h3Lt9//WuZGvPff3z++d8vryf/9Nt/8xOePxuQgOQRykcerdnHa99//cv6N6tE+OOfDz//+6cxxpgvv7wOo/byaI6hV9799e9PjmfuI49QPvJobf947a08Wr/mcm/19/RSu8gjlI88WgvOI3sn5dzpHOXRfOAWgjxC+cijtdA8cgfKvGn68XnOKddr/vHPuXfryCOUjzxa28uO+djKOhO0PeD679efX+eefvPtj8zykM23V+L9ftSCPLrqyy92iPz4vDr5DeA08uiy5aaJbQvwNvIIgBTkEQApyCMAUpBHAKQgjwBIQR4BkII8AiAFeQRACvIIgBTkEQApyCMAUpBHAKQgjwBIQR4BkII8AiAFeQRACvIIgBTkEQApyCMAUpBHAKQgjwBI8X91eJZak6maNQAAAABJRU5ErkJggg==" /><br /><br />Lets try to construct the above graph in figure I in below code using Adjacency List.<br /><br /></b><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #888888;">/**</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * @author krishna kumar</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * This is a basic implementation of Graph using Adjacency list. </span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Graph</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">private</span> Node<span style="color: #333333;">[]</span> vertices<span style="color: #333333;">;</span> <span style="color: #888888;">// stores the nodes of the graph</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">;</span> <span style="color: #888888;">// number of nodes in the graph</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Graph</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">size</span> <span style="color: #333333;">=</span> size<span style="color: #333333;">;</span>
vertices <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">[</span>size<span style="color: #333333;">];</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Node</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> name<span style="color: #333333;">;</span>
Neighbour neighbourList<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> cost<span style="color: #333333;">;</span>
Node <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> name<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> cost<span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">name</span> <span style="color: #333333;">=</span> name<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">cost</span> <span style="color: #333333;">=</span> cost<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Neighbour</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> index<span style="color: #333333;">;</span>
Neighbour next<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> weight<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Neighbour</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> index<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> weight<span style="color: #333333;">,</span> Neighbour next<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">index</span> <span style="color: #333333;">=</span> index<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">weight</span> <span style="color: #333333;">=</span> weight<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">next</span> <span style="color: #333333;">=</span> next<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addNode</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> name<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> cost<span style="color: #333333;">){</span>
vertices<span style="color: #333333;">[</span>name<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Node<span style="color: #333333;">(</span>name<span style="color: #333333;">,</span> cost<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addEdge</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> sourceName<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> destinationName<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> weight<span style="color: #333333;">){</span>
<span style="color: #333399; font-weight: bold;">int</span> sourceIndex <span style="color: #333333;">=</span> sourceName<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> destinationIndex <span style="color: #333333;">=</span> destinationName<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
Node source <span style="color: #333333;">=</span> vertices<span style="color: #333333;">[</span>sourceIndex<span style="color: #333333;">];</span>
source<span style="color: #333333;">.</span><span style="color: #0000cc;">neighbourList</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Neighbour<span style="color: #333333;">(</span>destinationIndex<span style="color: #333333;">,</span> weight<span style="color: #333333;">,</span> source<span style="color: #333333;">.</span><span style="color: #0000cc;">neighbourList</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">printState</span><span style="color: #333333;">(){</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> size<span style="color: #333333;">;</span> i<span style="color: #333333;">++){</span>
Node u <span style="color: #333333;">=</span> vertices<span style="color: #333333;">[</span>i<span style="color: #333333;">];</span>
Neighbour temp <span style="color: #333333;">=</span> u<span style="color: #333333;">.</span><span style="color: #0000cc;">neighbourList</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">while</span><span style="color: #333333;">(</span>temp <span style="color: #333333;">!=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">){</span>
Node v <span style="color: #333333;">=</span> vertices<span style="color: #333333;">[</span>temp<span style="color: #333333;">.</span><span style="color: #0000cc;">index</span><span style="color: #333333;">];</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"name:"</span><span style="color: #333333;">+</span>u<span style="color: #333333;">.</span><span style="color: #0000cc;">name</span><span style="color: #333333;">+</span><span style="background-color: #fff0f0;">",cost:"</span><span style="color: #333333;">+</span>u<span style="color: #333333;">.</span><span style="color: #0000cc;">cost</span><span style="color: #333333;">+</span><span style="background-color: #fff0f0;">" is connected with "</span><span style="color: #333333;">+</span><span style="background-color: #fff0f0;">"name:"</span><span style="color: #333333;">+</span>v<span style="color: #333333;">.</span><span style="color: #0000cc;">name</span><span style="color: #333333;">+</span><span style="background-color: #fff0f0;">",cost:"</span><span style="color: #333333;">+</span>v<span style="color: #333333;">.</span><span style="color: #0000cc;">cost</span> <span style="color: #333333;">+</span><span style="background-color: #fff0f0;">" with edge-weight as "</span><span style="color: #333333;">+</span>temp<span style="color: #333333;">.</span><span style="color: #0000cc;">weight</span><span style="color: #333333;">);</span>
temp <span style="color: #333333;">=</span> temp<span style="color: #333333;">.</span><span style="color: #0000cc;">next</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
Graph graph <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Graph<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">10</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">19</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">100</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">90</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">printState</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /></div>
<div>
<br />Output : <br />name:1,cost:2 is connected with name:3,cost:19 with edge-weight as 5<br />name:1,cost:2 is connected with name:2,cost:10 with edge-weight as 4<br />name:3,cost:19 is connected with name:4,cost:3 with edge-weight as 100<br />name:4,cost:3 is connected with name:2,cost:10 with edge-weight as 2<br />name:4,cost:3 is connected with name:3,cost:19 with edge-weight as 2<br />name:4,cost:3 is connected with name:2,cost:10 with edge-weight as 90<br /><br />In case we would have had non directional graph [ or bidirectional graph with both the edges between two nodes, n1 and n2 having same weight and this statement being true for all the pair of connected nodes]<br />Then only 'addEdge' method needs to be modified as below<br /><br /><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addEdge</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> n1Name<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> n2Name<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> weight<span style="color: #333333;">){</span>
<span style="color: #333399; font-weight: bold;">int</span> n1Index <span style="color: #333333;">=</span> n1Name<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> n2Index <span style="color: #333333;">=</span> n2Name<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
Node n1 <span style="color: #333333;">=</span> vertices<span style="color: #333333;">[</span>n1Index<span style="color: #333333;">];</span>
Node n2 <span style="color: #333333;">=</span> vertices<span style="color: #333333;">[</span>n2Index<span style="color: #333333;">];</span>
n1<span style="color: #333333;">.</span><span style="color: #0000cc;">neighbourList</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Neighbour<span style="color: #333333;">(</span>n2Index<span style="color: #333333;">,</span> weight<span style="color: #333333;">,</span> n1<span style="color: #333333;">.</span><span style="color: #0000cc;">neighbourList</span><span style="color: #333333;">);</span>
n2<span style="color: #333333;">.</span><span style="color: #0000cc;">neighbourList</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Neighbour<span style="color: #333333;">(</span>n1Index<span style="color: #333333;">,</span> weight<span style="color: #333333;">,</span> n2<span style="color: #333333;">.</span><span style="color: #0000cc;">neighbourList</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /><br /><b>Now lets try to construct below graph shown in figure J using Adjacency Matrix<br /><br /><img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAATEAAAFNCAIAAADn58+FAAAS2klEQVR4nO2dMa6kxhpGWYjDtwqSSUeOvAoWMIHXQWhpslkEieUdzA5adjyJA8vBaCRLvIBuKKCAgqaqvqo6R1cz93Jp+Cm+c6saaKh6AFCiil0AAMzASQAtcBJAC5wE0AInAbTASQAt4jj54ePX/a8oVQEoENRJd+XwE4olhJNv2oWcEJLogzjvTt64DWgJ/tAZxHl00kfRdJhwL4KDOC9O+jYHM+F97k3RjUu738lgtqAlXMPf3/Rblnyzk4E9QUs4S4DMvGnmnU5GMQQtwZHAb3kur+s2JyO6gZZwSEIdxj1ORrciegGgTFodxg1ORtrgR1tXVVU1XdwyQJ3owThbwLtOxhOybh+Ptp6cjFcM6CISiVNl3Otk11RNO/RfVVW3j3HqyFOhrqmbpq6qqm7bxuzupnlN2TYoyslhXODQKvBCKg/uxbzl5Go1XTPGZujJFi8YJeqaqmq6vmuqaujv6vbR94+2HjPXNcf5WzppKykTHm1dNY1Dm8ATwSQ4lnS7kzapzI5ydLLpxv+eTj5ePWy16Gi3KMbJ54a6/J2CJ4JJ8O6kbQVWJ7tmNozddfJQwxkWJzcKSxpzdIGTTshmwKWwi05uLPrAyWloa3XyNaJ1pggnjY0s18mqOhFU8QAclhfAyWnoWrftXj/Z97Ph616fuRjmLpMqvldOsRjQF3ucx11L8b0f2EkVxMu7Srn95ICLlnF2/WN1smGX/SKvOJlE4pMo8iSlO9k7aBljv0/nC8xjJzvgJGTFjpZRz5b3/dYRjuNSZ+AkpMeWlisnQ54tPzPfvU6mkvVU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+Jk0VRrpOu/P6rKdKPT4sDQv744/tzRcYbWigAnDxk3nmaVxd4xuiKw/wVAAlwEkALnATQAicBtMBJAC1wEkALnATQAicBtMBJAC1wEkALnATQAicBtMBJAC1wEkALnATQAicBtMBJAC1wEkALnATQAicBtMBJAC1wEkALnATQAicBtMBJAC1wEkALnATQAicBtMBJAC1wEkALnATQAicBtPg/zoHPJ4ON8k8AAAAASUVORK5CYII=" /></b>* note that as compared to figure I here we have a edge, with edge weight as 90 and connecting node named 4 to node name 2, missing in Figure J. This is because it is difficult to represent more than 1 edges with same direction between two nodes. Below is the code.<br /><br /><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #888888;">/**</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * @author krishna kumar</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * This is a basic Implementation of Graph using Adjacency matrix.</span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Graph</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> costs<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[][]</span> adjacencyMatrix<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">;</span> <span style="color: #888888;">// number of nodes in the graph</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Graph</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">size</span> <span style="color: #333333;">=</span> size<span style="color: #333333;">;</span>
costs <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[</span>size<span style="color: #333333;">];</span> <span style="color: #888888;">//Initialized with all 0s</span>
adjacencyMatrix <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[</span>size<span style="color: #333333;">][</span>size<span style="color: #333333;">];</span><span style="color: #888888;">//Initialized with all 0s</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addNode</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> name<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> cost<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
costs<span style="color: #333333;">[</span>name <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;">=</span> cost<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addEdge</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> sourceName<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> destinationName<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> weight<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> sourceIndex <span style="color: #333333;">=</span> sourceName <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> destinationIndex <span style="color: #333333;">=</span> destinationName <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
adjacencyMatrix<span style="color: #333333;">[</span>sourceIndex<span style="color: #333333;">][</span>destinationIndex<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> weight<span style="color: #333333;">;</span>
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * In case we would have had non directional graph [ or bidirectional</span>
<span style="color: #888888;"> * graph with both the edges between two nodes, n1 and n2 having same</span>
<span style="color: #888888;"> * weight and this statement being true for all the pair of connected</span>
<span style="color: #888888;"> * nodes], we just need to add(uncomment) below statement</span>
<span style="color: #888888;"> */</span>
<span style="color: #888888;">//adjacencyMatrix[destinationIndex][sourceIndex] = weight;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">printState</span><span style="color: #333333;">(){</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> size<span style="color: #333333;">;</span> i<span style="color: #333333;">++){</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> j <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">;</span> j <span style="color: #333333;"><</span> size <span style="color: #333333;">;</span> j<span style="color: #333333;">++){</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>adjacencyMatrix<span style="color: #333333;">[</span>i<span style="color: #333333;">][</span>j<span style="color: #333333;">]</span> <span style="color: #333333;">!=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">){</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"name:"</span><span style="color: #333333;">+(</span>i<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">)+</span><span style="background-color: #fff0f0;">",cost:"</span><span style="color: #333333;">+</span>costs<span style="color: #333333;">[</span>i<span style="color: #333333;">]+</span><span style="background-color: #fff0f0;">" is connected with "</span><span style="color: #333333;">+</span><span style="background-color: #fff0f0;">"name:"</span><span style="color: #333333;">+(</span>j<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">)+</span><span style="background-color: #fff0f0;">",cost:"</span><span style="color: #333333;">+</span>costs<span style="color: #333333;">[</span>j<span style="color: #333333;">]</span> <span style="color: #333333;">+</span><span style="background-color: #fff0f0;">" with edge-weight as "</span><span style="color: #333333;">+</span>adjacencyMatrix<span style="color: #333333;">[</span>i<span style="color: #333333;">][</span>j<span style="color: #333333;">]);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
Graph graph <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Graph<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">10</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">19</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addNode</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">100</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">90</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">printState</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /><br />Output : <br />name:1,cost:2 is connected with name:2,cost:10 with edge-weight as 4<br />name:1,cost:2 is connected with name:3,cost:19 with edge-weight as 5<br />name:3,cost:19 is connected with name:4,cost:3 with edge-weight as 100<br />name:4,cost:3 is connected with name:2,cost:10 with edge-weight as 2<br />name:4,cost:3 is connected with name:3,cost:19 with edge-weight as 2</div>
</div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-77879780671749322562015-11-13T05:59:00.002-08:002015-11-13T05:59:48.584-08:00Hamiltonian Cycle in a graph. | Solution in java<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
<br />
<br />
I am here with another algorithm based on Graph. Its Hamiltonian cycle in a graph.<br />
<br />
<span class="_Tgc">In the mathematical field of graph theory, a <b>Hamiltonian path</b> (or traceable <b>path</b>) is a <b>path</b> in a graph that visits each vertex exactly once. A <b>Hamiltonian cycle</b> (or <b>Hamiltonian circuit</b>) is a <b>Hamiltonian path</b> that is a <b>cycle</b>.</span><br />
<br />
<span class="_Tgc">This solution if based on the post in geeksforgeeks :</span><br />
<span class="_Tgc"><a href="http://www.geeksforgeeks.org/backtracking-set-7-hamiltonian-cycle/">http://www.geeksforgeeks.org/backtracking-set-7-hamiltonian-cycle/ </a></span><br />
<br />
<br />
<span class="_Tgc"></span><br />
<span class="_Tgc"><img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANwAAACCCAIAAACivDFRAAAEkElEQVR4nO3bP3LiMBiGcZ8rB8p5cgYfgYIDcIS0qejcMEPBDAUFW9j88xpjyZ+kV9LzG5qd3TGSvicGkk1zBcQ0qRcAjBEl5BAl5BAl5BAl5BAl5BAl5BAl5BAl5BAl5BAl5BAl5BAl5BAl5BAl5BAl5BAl5BAl5BAl5BAl5BAl5BDleufvtmva4zb1OopBlOsRpTH3KPfHpu1uj8PPMcCiMlNhlJefTcAGHKM8nr4eRfaPqoYx6Rbl48u17DN5LjLIfte8fPfD4GbZn0M1X6vDjWnY4HbXNW339XsxfAa/KJ/HQJTDadwGM/zxe594WYH8/R6atmt253BPEfbluynLm12O31PO3zxSb8LZaP1yUfYLGo779TY+ffWyvNllXVGO5h6iUZ8oXx9zL9+pz9PYm126vXyn3oSP1x38/0HH+C2c83vK/jbQz6BvtNQ3T7ODeTb1QWdz+ltw2SDrjkHqW0LVWFzk1fVbQi5XrhSHMiF0N3Q5jxMZi1MMXc7gOF7EbIUu3+EsHuJXQpeTOIhBqj4K6NJ85Vmegrm0ZeTepfnKV10o33N8ptCEwhq8EaUxnRp0VuKKKC2pdaC2noWI0oxmAZqrmkeUNpRnr7y2SURpQH/q+it8RpRr5TLvXNZ5JcqVMpr0NZ/VEqW/XGb8LIs1E6WnLKY7SX/lROlDf67zxNdPlM7EJ7qQ8i6I0o3yLF3J7oUoHchO0ZvmjohyKc35rSe4L6JcRHByhtR2R5Sfqc0sBKk9EuUHUtMKSmenRDlHZ05xiOyXKN8SmVBkCrsmyg8rEVlPTMn3TpRzy1BYTBJpT4Ao364h+UrSSngORDm9gMqL7KU6DaKceHaKvEtyJkQ5fmqKHIl/MkT58rwUOSny+RAlRS4S85Rqj5Iil4t2VlVHSZGu4pxYvVFSpJ8I51ZplBS5RujTqzFKilwv6BlWFyVFWgl3knVFSZG2Ap1nRVFSZAghTrWWKCkyHPOzrSJKigzN9oTLj5Ii4zA858KjpMiYrE675CgpMj6TMy82SopMZf3JlxklRaa18vwLjJIiFayZQmlRUqQO71kUFSVFqvGbSDlRUqQmj7kUEiVFKnOdTglRUqQ+pxllHyVF5mL5pPKOkiLzsnBeGUdJkTlaMrVco6TIfH2cXZZRUmTu5idoPlabH1t//AcUmbuYc7T5Dz4zf0WRxYg2zYBRUmR5srlTTl+XIgsVYZr8dizk8NuxkBM2SvOLowYBX75DXBk1IB04+/s9NG3XP7739tcnSrjZ7rp7kf3j6/di+xQmUZ6/265pj9t3z4HMPWZ5PH21XbM5/S0bvZ8YUQ7PhDy9THF/HN0mm7Zr2sPP0aKjeyoWF1n65ZL6eOFsPMLpKI3fWXpHefnZ3BcU5B4ORf3Ld+BZ+0X5KPLpQZRV+P+DztNbTBteUQ5fLrd3EsMtnShr8dKldZFXzyj7Cnfn2595+YYlooQcg5fv2/f3iRI2+KADOXxLCHL42TfkECXkECXkECXkECXkECXkECXkECXkECXkECXkECXkECXkECXkECXkECXkECXk/AN5Omp1u/YRowAAAABJRU5ErkJggg==" /></span><br />
<span class="_Tgc">For the above graph , we have a Hamiltonian cycle as a->b->c->e->d and another Hamiltonian cyle is a->d->e->c->b->a.</span><br />
<br />
<span class="_Tgc">We have to visit <b>each </b>vertex <b>only once </b>and reach the starting vertex in order to have a Hamiltonian cycle in a graph. </span><br />
<br />
<span class="_Tgc"><span class="_Tgc"></span></span><br />
<span class="_Tgc">Friends, please find my solution in Java below</span><br />
<br />
<br />
<span class="_Tgc"><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.HashMap</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.Map</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">HamiltonianCycle</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> verticesNum<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">char</span><span style="color: #333333;">[]</span> vertices<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">char</span><span style="color: #333333;">[]</span> path<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">;</span>
Map<span style="color: #333333;"><</span>Character<span style="color: #333333;">,</span>Integer<span style="color: #333333;">></span> vertexIndexMap <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> HashMap<span style="color: #333333;"><>();</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">HamiltonianCycle</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> verticesNum<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">verticesNum</span> <span style="color: #333333;">=</span> verticesNum<span style="color: #333333;">;</span>
vertices <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">char</span><span style="color: #333333;">[</span>verticesNum<span style="color: #333333;">];</span>
path <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">char</span><span style="color: #333333;">[</span>verticesNum<span style="color: #333333;">];</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addVertex</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">char</span> v<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
vertexIndexMap<span style="color: #333333;">.</span><span style="color: #0000cc;">put</span><span style="color: #333333;">(</span>v<span style="color: #333333;">,</span> size<span style="color: #333333;">);</span>
vertices<span style="color: #333333;">[</span>size<span style="color: #333333;">++]</span> <span style="color: #333333;">=</span> v<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">isValidNodeInPath</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> <span style="color: #333333;">[][]</span> graph<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> indexOfNewVerex <span style="color: #333333;">,</span><span style="color: #333399; font-weight: bold;">int</span> pos<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">char</span> lastVertexInPath <span style="color: #333333;">=</span> path<span style="color: #333333;">[</span>pos<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">];</span>
<span style="color: #333399; font-weight: bold;">int</span> indexOfLastVertexInPath <span style="color: #333333;">=</span> vertexIndexMap<span style="color: #333333;">.</span><span style="color: #0000cc;">get</span><span style="color: #333333;">(</span>lastVertexInPath<span style="color: #333333;">);</span>
<span style="color: #888888;">// check if the new vertex is adjacent to the previously added vertex in the path]</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>graph<span style="color: #333333;">[</span>indexOfNewVerex<span style="color: #333333;">][</span>indexOfLastVertexInPath<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #888888;">// check if the new vertex has not already been added in the path</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> pos<span style="color: #333333;">;</span> i<span style="color: #333333;">++){</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>vertices<span style="color: #333333;">[</span>indexOfNewVerex<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> path<span style="color: #333333;">[</span>i<span style="color: #333333;">]){</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">validateHamiltonianCycleUtil</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> <span style="color: #333333;">[][]</span> graph<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> pos<span style="color: #333333;">){</span>
<span style="color: #888888;">// base condition</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>pos <span style="color: #333333;">==</span> verticesNum<span style="color: #333333;">){</span>
<span style="color: #333399; font-weight: bold;">char</span> lastVertexInPath <span style="color: #333333;">=</span> path<span style="color: #333333;">[</span>pos<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">];</span>
<span style="color: #333399; font-weight: bold;">int</span> indexOfVertexlastInPath <span style="color: #333333;">=</span> vertexIndexMap<span style="color: #333333;">.</span><span style="color: #0000cc;">get</span><span style="color: #333333;">(</span>lastVertexInPath<span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>graph<span style="color: #333333;">[</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">][</span>indexOfVertexlastInPath<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">else</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #888888;">// here we try to add v in the path at position pos</span>
<span style="color: #888888;">// we start from 1 as 0th vertex from the array vertices is already in the path as source node</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> verticesNum<span style="color: #333333;">;</span> i<span style="color: #333333;">++){</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>isValidNodeInPath<span style="color: #333333;">(</span>graph<span style="color: #333333;">,</span>i<span style="color: #333333;">,</span>pos<span style="color: #333333;">)){</span>
path<span style="color: #333333;">[</span>pos<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> vertices<span style="color: #333333;">[</span>i<span style="color: #333333;">];</span><span style="color: #888888;">// include new node in the path</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>validateHamiltonianCycleUtil<span style="color: #333333;">(</span>graph<span style="color: #333333;">,</span> pos<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">)){</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
path<span style="color: #333333;">[</span>pos<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #0044dd;">'$'</span><span style="color: #333333;">;</span><span style="color: #888888;">// reset the position and try to put another node at this position.</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #888888;">// no valid vertex found to be added in the path, and all nodes still not covered ,return false</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">isHamiltonianCycle</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[][]</span> graph<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> verticesNum<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
path<span style="color: #333333;">[</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #0044dd;">'$'</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
path<span style="color: #333333;">[</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">]</span> <span style="color: #333333;">=</span> vertices<span style="color: #333333;">[</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">];</span> <span style="color: #888888;">// vertices[0] is included as a source node of</span>
<span style="color: #888888;">// the cycle</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>validateHamiltonianCycleUtil<span style="color: #333333;">(</span>graph<span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">))</span> <span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Path exists::"</span><span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> verticesNum<span style="color: #333333;">;</span> i<span style="color: #333333;">++){</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">print</span><span style="color: #333333;">(</span>path<span style="color: #333333;">[</span>i<span style="color: #333333;">]+</span><span style="background-color: #fff0f0;">" "</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">print</span><span style="color: #333333;">(</span>path<span style="color: #333333;">[</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">]);</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"No path exists!!"</span><span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
HamiltonianCycle hamiltonianCycle <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> HamiltonianCycle<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">);</span>
hamiltonianCycle<span style="color: #333333;">.</span><span style="color: #0000cc;">addVertex</span><span style="color: #333333;">(</span><span style="color: #0044dd;">'a'</span><span style="color: #333333;">);</span>
hamiltonianCycle<span style="color: #333333;">.</span><span style="color: #0000cc;">addVertex</span><span style="color: #333333;">(</span><span style="color: #0044dd;">'b'</span><span style="color: #333333;">);</span>
hamiltonianCycle<span style="color: #333333;">.</span><span style="color: #0000cc;">addVertex</span><span style="color: #333333;">(</span><span style="color: #0044dd;">'c'</span><span style="color: #333333;">);</span>
hamiltonianCycle<span style="color: #333333;">.</span><span style="color: #0000cc;">addVertex</span><span style="color: #333333;">(</span><span style="color: #0044dd;">'d'</span><span style="color: #333333;">);</span>
hamiltonianCycle<span style="color: #333333;">.</span><span style="color: #0000cc;">addVertex</span><span style="color: #333333;">(</span><span style="color: #0044dd;">'e'</span><span style="color: #333333;">);</span>
<span style="color: #888888;">/* Let us create the following graph</span>
<span style="color: #888888;"> (a)--(b)--(c)</span>
<span style="color: #888888;"> | / \ |</span>
<span style="color: #888888;"> | / \ |</span>
<span style="color: #888888;"> | / \ |</span>
<span style="color: #888888;"> (d)-------(e) */</span>
<span style="color: #333399; font-weight: bold;">int</span> graph<span style="color: #333333;">[][]</span> <span style="color: #333333;">=</span> <span style="color: #333333;">{</span>
<span style="color: #333333;">{</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">},</span>
<span style="color: #333333;">{</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">},</span>
<span style="color: #333333;">{</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">},</span>
<span style="color: #333333;">{</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">},</span>
<span style="color: #333333;">{</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">},</span>
<span style="color: #333333;">};</span>
hamiltonianCycle<span style="color: #333333;">.</span><span style="color: #0000cc;">isHamiltonianCycle</span><span style="color: #333333;">(</span>graph<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /></span></div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-61480316150893526432015-11-12T11:12:00.000-08:002015-11-13T04:31:12.547-08:00Longest Path in a Directed Acyclic Graph (DAG). | Solution in Java<div dir="ltr" style="text-align: left;" trbidi="on">
Dear friends,<br />
<br />
I am here with you with yet another problem. Given a Directed Acyclic Graph how can we compute the longest path from any source.<br />
<br />
This post is based upon the post from geeksfrogeeks.org :<br />
<a href="http://www.geeksforgeeks.org/find-longest-path-directed-acyclic-graph/">http://www.geeksforgeeks.org/find-longest-path-directed-acyclic-graph/</a><br />
<br />
I have also solved same problem using adjacency matrix :<br />
<a href="http://krishnalearnings.blogspot.in/2015/08/code-in-java-for-finding-longest-path.html"> http://krishnalearnings.blogspot.in/2015/08/code-in-java-for-finding-longest-path.html</a><br />
<br />
In the below solution, I have used adjacency list.<br />
<br />
I have implemented my own Stack (exceptions like stack full, stack empty have not been taken care, considering careful usage of stack in the solution )<br />
<br />
Below is a DAG, lets find the longest path from Node with value '2'.<br />
<br />
<br />
<br />
<img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASYAAAD9CAIAAACeKE3VAAAgAElEQVR4nO2dbWwU173wz5f2S7at3cRgpw1g2ahEJUkNWlRb6RURSkTEy5REFsVtbXi0JURJlXCrgd7bx+2VYKNQR+FlhYjgru6zfDG96iiV0UOzbdwWOoK8+NE4ARRNuaKCKb5PqCaAjCcUmz33w98exvsye2bmnDNnd8/vAwK8Ozvemd+ct///fxCWSCQcQXGfgETSWEjlahLHcQzD0Oaj67pt23GfmqQKUrkaQ9f1VCqFEFJVNZfLeZVTVTWZTCqKommadE9YpHI1g67riqKkUild1x3HqfQywzAymQxCSNM0n5dJ4kIqVwM4jpNOpxVFMQyD8C22bauqqiiKZVlMz00SFKmc6Ni2nUql0ul0iCYrn88nk0ld11mcmCQcUjmhcRxHUZRMJhP6CLquI4RM06R4VpIoSOWEJpVKRfEN0HU9mUzKCRVBkMqJi6ZpqVSKyqFyuZyqqlQOJYmIVE5QbNtGCFGc/FAURQ7qREAqJyiZTCZ6l9ILrDFQPKAkHFI5EXEcp/Lo69KBHjTL9lOBDhtomUHCCKmciBiGUWEU5/EtuHW5XI5uyykJgVRORCCSq8wPZo3bfqro72RYliX7lrEjlR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i3obJzt9zLShykckID0/pR5jyiH0FCF6mc6IAz4do6GBDKHDmhkMrVAJZlBd1jxHEcqBgt2zfRkMrVBlAdDCGUyWT8xXMcByZLVFWVeToCIpWrJWzbhlKwqVQql8sZhmF60DQtnU4jhGTssshI5WoPx3EMw4CKXV5yuZyu63KbOMGRykkkXJHKSSRckcpJJFyRykkkXJHKSSRckcpJJFyRykkkXJHKSSRckcpJJFyRykkkXJHKSSRckcpJJFyRykkkXJHKSSRckcpJJFyRykkkXJHKSSRc+R/ipVvB13jffAAAAABJRU5ErkJggg==" /><br />
<br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">LongestPath</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
Graph graph <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Graph<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">7</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">,</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">,</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span>
graph<span style="color: #333333;">.</span><span style="color: #0000cc;">findLongestPath</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Graph</span> <span style="color: #333333;">{</span>
Vertex<span style="color: #333333;">[]</span> vertices<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> maxSize<span style="color: #333333;">;</span>
Stack stack<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Graph</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> maxSize<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
vertices <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Vertex<span style="color: #333333;">[</span>maxSize<span style="color: #333333;">];</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">maxSize</span> <span style="color: #333333;">=</span> maxSize<span style="color: #333333;">;</span>
stack <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Stack<span style="color: #333333;">(</span>maxSize<span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> maxSize<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
addVertex<span style="color: #333333;">(</span>i <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addVertex</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> data<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
vertices<span style="color: #333333;">[</span>size<span style="color: #333333;">++]</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Vertex<span style="color: #333333;">(</span>data<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addEdge</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> source<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> destination<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> weight<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
vertices<span style="color: #333333;">[</span>source <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">].</span><span style="color: #0000cc;">adj</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Neighbour<span style="color: #333333;">(</span>destination <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> weight<span style="color: #333333;">,</span> vertices<span style="color: #333333;">[</span>source <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">].</span><span style="color: #0000cc;">adj</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Vertex</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> data<span style="color: #333333;">;</span>
Neighbour adj<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> cost <span style="color: #333333;">=</span> Integer<span style="color: #333333;">.</span><span style="color: #0000cc;">MIN_VALUE</span><span style="color: #333333;">;</span>
State state <span style="color: #333333;">=</span> State<span style="color: #333333;">.</span><span style="color: #0000cc;">NEW</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Vertex</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> data<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">data</span> <span style="color: #333333;">=</span> data<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Stack</span> <span style="color: #333333;">{</span>
Vertex<span style="color: #333333;">[]</span> stack<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> maxSize<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Stack</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> maxSize<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">maxSize</span> <span style="color: #333333;">=</span> maxSize<span style="color: #333333;">;</span>
stack <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Vertex<span style="color: #333333;">[</span>maxSize<span style="color: #333333;">];</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">push</span><span style="color: #333333;">(</span>Vertex data<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
stack<span style="color: #333333;">[</span>size<span style="color: #333333;">++]</span> <span style="color: #333333;">=</span> data<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> Vertex <span style="color: #0066bb; font-weight: bold;">pop</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> stack<span style="color: #333333;">[--</span>size<span style="color: #333333;">];</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">isEmpty</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> size <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">enum</span> State <span style="color: #333333;">{</span>
NEW<span style="color: #333333;">,</span> VISITED
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Neighbour</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> index<span style="color: #333333;">;</span>
Neighbour next<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> weight<span style="color: #333333;">;</span>
Neighbour<span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> index<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> weight<span style="color: #333333;">,</span> Neighbour next<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">index</span> <span style="color: #333333;">=</span> index<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">next</span> <span style="color: #333333;">=</span> next<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">weight</span> <span style="color: #333333;">=</span> weight<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">findLongestPath</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> source<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
applyTopologicalSort<span style="color: #333333;">();</span>
vertices<span style="color: #333333;">[</span>source<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">].</span><span style="color: #0000cc;">cost</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">while</span> <span style="color: #333333;">(!</span>stack<span style="color: #333333;">.</span><span style="color: #0000cc;">isEmpty</span><span style="color: #333333;">())</span> <span style="color: #333333;">{</span>
Vertex u <span style="color: #333333;">=</span> stack<span style="color: #333333;">.</span><span style="color: #0000cc;">pop</span><span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>u<span style="color: #333333;">.</span><span style="color: #0000cc;">cost</span> <span style="color: #333333;">!=</span> Integer<span style="color: #333333;">.</span><span style="color: #0000cc;">MIN_VALUE</span><span style="color: #333333;">){</span>
Neighbour temp <span style="color: #333333;">=</span> u<span style="color: #333333;">.</span><span style="color: #0000cc;">adj</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">while</span><span style="color: #333333;">(</span>temp <span style="color: #333333;">!=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">){</span>
Vertex v <span style="color: #333333;">=</span> vertices<span style="color: #333333;">[</span>temp<span style="color: #333333;">.</span><span style="color: #0000cc;">index</span><span style="color: #333333;">];</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>v<span style="color: #333333;">.</span><span style="color: #0000cc;">cost</span> <span style="color: #333333;"><</span> <span style="color: #333333;">(</span>temp<span style="color: #333333;">.</span><span style="color: #0000cc;">weight</span><span style="color: #333333;">+</span>u<span style="color: #333333;">.</span><span style="color: #0000cc;">cost</span><span style="color: #333333;">)){</span>
v<span style="color: #333333;">.</span><span style="color: #0000cc;">cost</span> <span style="color: #333333;">=</span> temp<span style="color: #333333;">.</span><span style="color: #0000cc;">weight</span><span style="color: #333333;">+</span>u<span style="color: #333333;">.</span><span style="color: #0000cc;">cost</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
temp <span style="color: #333333;">=</span> temp<span style="color: #333333;">.</span><span style="color: #0000cc;">next</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Longest distances..."</span><span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> maxSize<span style="color: #333333;">;</span> i<span style="color: #333333;">++){</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Longest path from 2 to "</span> <span style="color: #333333;">+</span> <span style="color: #333333;">(</span>i<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">)+</span> <span style="background-color: #fff0f0;">" "</span><span style="color: #333333;">+</span>vertices<span style="color: #333333;">[</span>i<span style="color: #333333;">].</span><span style="color: #0000cc;">cost</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">applyTopologicalSort</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> maxSize<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>vertices<span style="color: #333333;">[</span>i<span style="color: #333333;">].</span><span style="color: #0000cc;">state</span> <span style="color: #333333;">!=</span> State<span style="color: #333333;">.</span><span style="color: #0000cc;">VISITED</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
dfs<span style="color: #333333;">(</span>vertices<span style="color: #333333;">[</span>i<span style="color: #333333;">]);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">dfs</span><span style="color: #333333;">(</span>Vertex u<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
Neighbour temp <span style="color: #333333;">=</span> u<span style="color: #333333;">.</span><span style="color: #0000cc;">adj</span><span style="color: #333333;">;</span>
u<span style="color: #333333;">.</span><span style="color: #0000cc;">state</span> <span style="color: #333333;">=</span> State<span style="color: #333333;">.</span><span style="color: #0000cc;">VISITED</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">while</span> <span style="color: #333333;">(</span>temp <span style="color: #333333;">!=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
Vertex v <span style="color: #333333;">=</span> vertices<span style="color: #333333;">[</span>temp<span style="color: #333333;">.</span><span style="color: #0000cc;">index</span><span style="color: #333333;">];</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>v<span style="color: #333333;">.</span><span style="color: #0000cc;">state</span> <span style="color: #333333;">==</span> State<span style="color: #333333;">.</span><span style="color: #0000cc;">NEW</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
dfs<span style="color: #333333;">(</span>v<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
temp <span style="color: #333333;">=</span> temp<span style="color: #333333;">.</span><span style="color: #0000cc;">next</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
stack<span style="color: #333333;">.</span><span style="color: #0000cc;">push</span><span style="color: #333333;">(</span>u<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /></div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-69241533367500617582015-11-11T01:58:00.000-08:002015-11-11T01:58:04.332-08:00Is number Special 180 degree Palindrome<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Hello friends,<br />
<br />
I am here with you with a problem. I took the idea of this problem from a problem posted in geeksforgeeks : http://www.geeksforgeeks.org/check-if-a-given-number-is-fancy<br />
<br />
<br />
A number is a special 180 degree palindrome if upon rotating it 180 degrees we get the same number back.<br />
<br />
For example : 0, 1, 8, 96, 69, 906, 901106, 68089 are such numbers and 2,929,926,99,66,6,9 are not such special 180 degree palindrome numbers.<br />
<br />
<br />
Please find below my solution in Java for this problem.<br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">SpecialPalindrome</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>isSpecialPalindrome<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">68111011189</span>l<span style="color: #333333;">));</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">isSpecialPalindrome</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">long</span> N<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">char</span> arr<span style="color: #333333;">[]</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Long<span style="color: #333333;">(</span>N<span style="color: #333333;">).</span><span style="color: #0000cc;">toString</span><span style="color: #333333;">().</span><span style="color: #0000cc;">toCharArray</span><span style="color: #333333;">();</span>
<span style="color: #333399; font-weight: bold;">boolean</span> isOddDigits <span style="color: #333333;">=</span> arr<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span> <span style="color: #333333;">%</span> <span style="color: #0000dd; font-weight: bold;">2</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">?</span> <span style="color: #008800; font-weight: bold;">true</span> <span style="color: #333333;">:</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> loopRun <span style="color: #333333;">=</span> arr<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span> <span style="color: #333333;">/</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> n <span style="color: #333333;">=</span> arr<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">;</span>
HashMap map <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> HashMap<span style="color: #333333;">();</span>
map<span style="color: #333333;">.</span><span style="color: #0000cc;">put</span><span style="color: #333333;">(</span><span style="color: #0044dd;">'0'</span><span style="color: #333333;">,</span> <span style="color: #0044dd;">'0'</span><span style="color: #333333;">);</span>
map<span style="color: #333333;">.</span><span style="color: #0000cc;">put</span><span style="color: #333333;">(</span><span style="color: #0044dd;">'1'</span><span style="color: #333333;">,</span> <span style="color: #0044dd;">'1'</span><span style="color: #333333;">);</span>
map<span style="color: #333333;">.</span><span style="color: #0000cc;">put</span><span style="color: #333333;">(</span><span style="color: #0044dd;">'8'</span><span style="color: #333333;">,</span> <span style="color: #0044dd;">'8'</span><span style="color: #333333;">);</span>
map<span style="color: #333333;">.</span><span style="color: #0000cc;">put</span><span style="color: #333333;">(</span><span style="color: #0044dd;">'6'</span><span style="color: #333333;">,</span> <span style="color: #0044dd;">'9'</span><span style="color: #333333;">);</span>
map<span style="color: #333333;">.</span><span style="color: #0000cc;">put</span><span style="color: #333333;">(</span><span style="color: #0044dd;">'9'</span><span style="color: #333333;">,</span> <span style="color: #0044dd;">'6'</span><span style="color: #333333;">);</span>
<span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(;</span> i <span style="color: #333333;"><</span> loopRun<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">char</span> left <span style="color: #333333;">=</span> map<span style="color: #333333;">.</span><span style="color: #0000cc;">get</span><span style="color: #333333;">(</span>arr<span style="color: #333333;">[</span>i<span style="color: #333333;">]);</span>
<span style="color: #333399; font-weight: bold;">char</span> right <span style="color: #333333;">=</span> map<span style="color: #333333;">.</span><span style="color: #0000cc;">get</span><span style="color: #333333;">(</span>arr<span style="color: #333333;">[</span>n<span style="color: #333333;">-</span>i<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]);</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>left <span style="color: #333333;">!=</span> <span style="color: #0044dd;">' '</span> <span style="color: #333333;">&&</span> right <span style="color: #333333;">!=</span> <span style="color: #0044dd;">' '</span> <span style="color: #333333;">&&</span> left <span style="color: #333333;">==</span> arr<span style="color: #333333;">[</span>n<span style="color: #333333;">-</span>i<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]){</span>
<span style="color: #008800; font-weight: bold;">continue</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span><span style="color: #008800; font-weight: bold;">else</span><span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>isOddDigits <span style="color: #333333;">&&</span> map<span style="color: #333333;">.</span><span style="color: #0000cc;">get</span><span style="color: #333333;">(</span>arr<span style="color: #333333;">[</span>i<span style="color: #333333;">])</span> <span style="color: #333333;">==</span> <span style="color: #0044dd;">' '</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">HashMap</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> prime <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">499</span><span style="color: #333333;">;</span>
MapNode<span style="color: #333333;">[]</span> map <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> MapNode<span style="color: #333333;">[</span>prime<span style="color: #333333;">];</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">MapNode</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">private</span> MapNode next<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">char</span> value<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">char</span> key<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">MapNode</span><span style="color: #333333;">(</span>MapNode next<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">next</span> <span style="color: #333333;">=</span> next<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">MapNode</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">char</span> key<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">char</span> value<span style="color: #333333;">,</span> MapNode next<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">key</span> <span style="color: #333333;">=</span> key<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">value</span> <span style="color: #333333;">=</span> value<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">next</span> <span style="color: #333333;">=</span> next<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">put</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">char</span> key<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">char</span> value<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> index <span style="color: #333333;">=</span> index<span style="color: #333333;">(</span>key<span style="color: #333333;">);</span>
MapNode node <span style="color: #333333;">=</span> map<span style="color: #333333;">[</span>index<span style="color: #333333;">];</span>
<span style="color: #008800; font-weight: bold;">while</span> <span style="color: #333333;">(</span>node <span style="color: #333333;">!=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>node<span style="color: #333333;">.</span><span style="color: #0000cc;">key</span> <span style="color: #333333;">==</span> key<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
node<span style="color: #333333;">.</span><span style="color: #0000cc;">value</span> <span style="color: #333333;">=</span> value<span style="color: #333333;">;</span> <span style="color: #888888;">// update the value</span>
<span style="color: #008800; font-weight: bold;">return</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
node <span style="color: #333333;">=</span> node<span style="color: #333333;">.</span><span style="color: #0000cc;">next</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
map<span style="color: #333333;">[</span>index<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> MapNode<span style="color: #333333;">(</span>key<span style="color: #333333;">,</span> value<span style="color: #333333;">,</span> map<span style="color: #333333;">[</span>index<span style="color: #333333;">]);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">hashcode</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">char</span> key<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> key <span style="color: #333333;">*</span> <span style="color: #0000dd; font-weight: bold;">31</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">index</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">char</span> key<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #0066bb; font-weight: bold;">hashcode</span><span style="color: #333333;">(</span>key<span style="color: #333333;">)</span> <span style="color: #333333;">%</span> prime<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">char</span> <span style="color: #0066bb; font-weight: bold;">get</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">char</span> key<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> index <span style="color: #333333;">=</span> index<span style="color: #333333;">(</span>key<span style="color: #333333;">);</span>
MapNode node <span style="color: #333333;">=</span> map<span style="color: #333333;">[</span>index<span style="color: #333333;">];</span>
<span style="color: #008800; font-weight: bold;">while</span> <span style="color: #333333;">(</span>node <span style="color: #333333;">!=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>node<span style="color: #333333;">.</span><span style="color: #0000cc;">key</span> <span style="color: #333333;">==</span> key<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> node<span style="color: #333333;">.</span><span style="color: #0000cc;">value</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
node <span style="color: #333333;">=</span> node<span style="color: #333333;">.</span><span style="color: #0000cc;">next</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #0044dd;">' '</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">contains</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">char</span> key<span style="color: #333333;">){</span>
<span style="color: #333399; font-weight: bold;">int</span> index <span style="color: #333333;">=</span> index<span style="color: #333333;">(</span>key<span style="color: #333333;">);</span>
MapNode node <span style="color: #333333;">=</span> map<span style="color: #333333;">[</span>index<span style="color: #333333;">];</span>
<span style="color: #008800; font-weight: bold;">while</span> <span style="color: #333333;">(</span>node <span style="color: #333333;">!=</span> <span style="color: #008800; font-weight: bold;">null</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>node<span style="color: #333333;">.</span><span style="color: #0000cc;">key</span> <span style="color: #333333;">==</span> key<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
node <span style="color: #333333;">=</span> node<span style="color: #333333;">.</span><span style="color: #0000cc;">next</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /></div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-1310015160425674142015-09-15T12:29:00.002-07:002015-09-15T12:29:43.425-07:00Minimum number of turns required in a maze. | Back tracking , Java<div dir="ltr" style="text-align: left;" trbidi="on">
Dear Friends,<br />
<br />
<br />
I am here with you with another problem based upon back tracking.<br />
<br />
The problem is as below.<br />
<br />
We are given a matrix of NXM size. Each Cell either contains 0 or 1. 1 represents a blockage or a Wall and 0 represents valid path. We need to reach from top left cell to the bottom right cell.<br />
We need to out out the minimum number of turns required to reach the bottom right cell.<br />
<br />
<br />
Friends Please find the code below.<br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> com<span style="color: #333333;">.</span><span style="color: #0000cc;">learn</span><span style="color: #333333;">.</span><span style="color: #0000cc;">dfs</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.Arrays</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">MinimumTurns</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[][]</span> A <span style="color: #333333;">=</span>
<span style="color: #333333;">{</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">};</span>
<span style="color: #333399; font-weight: bold;">int</span> initialDir <span style="color: #333333;">=</span> findInitialDirUtil<span style="color: #333333;">(</span>A<span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>initialDir <span style="color: #333333;">!=</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
findMinTurns<span style="color: #333333;">(</span>A<span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> A<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">,</span> A<span style="color: #333333;">[</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">].</span><span style="color: #0000cc;">length</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> initialDir<span style="color: #333333;">);</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>minTurns<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span> <span style="color: #008800; font-weight: bold;">else</span> <span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"No path exists"</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">int</span> minTurns <span style="color: #333333;">=</span> Integer<span style="color: #333333;">.</span><span style="color: #0000cc;">MAX_VALUE</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">findInitialDirUtil</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[][]</span> A<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>A<span style="color: #333333;">[</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">][</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>A<span style="color: #333333;">[</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">][</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * A is the input matrix, with 0s and 1s. 1s represent the wall and 0s</span>
<span style="color: #888888;"> * represent the moving cells. The problem is to find the minimum number of</span>
<span style="color: #888888;"> * turns to be taken in order to reach from top left cell to bottom right</span>
<span style="color: #888888;"> * cell.</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * The below solution is based upon back tracking.</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * @param A</span>
<span style="color: #888888;"> * @param row</span>
<span style="color: #888888;"> * @param col</span>
<span style="color: #888888;"> * @param R</span>
<span style="color: #888888;"> * @param C</span>
<span style="color: #888888;"> * @param turns</span>
<span style="color: #888888;"> * @param currDir</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">findMinTurns</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[][]</span> A<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> row<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> col<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> R<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> C<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> turns<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> currDir<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>turns <span style="color: #333333;">>=</span> minTurns<span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">return</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>row <span style="color: #333333;">==</span> R <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">&&</span> col <span style="color: #333333;">==</span> C <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>turns <span style="color: #333333;"><</span> minTurns<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
minTurns <span style="color: #333333;">=</span> turns<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
A<span style="color: #333333;">[</span>row<span style="color: #333333;">][</span>col<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> turns<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>col <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;"><</span> C <span style="color: #333333;">&&</span> A<span style="color: #333333;">[</span>row<span style="color: #333333;">][</span>col <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">boolean</span> isDirChanged <span style="color: #333333;">=</span> currDir <span style="color: #333333;">!=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> updatedDir <span style="color: #333333;">=</span> currDir<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> updatedTurns <span style="color: #333333;">=</span> turns<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>isDirChanged<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
updatedDir <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
updatedTurns<span style="color: #333333;">++;</span>
<span style="color: #333333;">}</span>
findMinTurns<span style="color: #333333;">(</span>A<span style="color: #333333;">,</span> row<span style="color: #333333;">,</span> col <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> R<span style="color: #333333;">,</span> C<span style="color: #333333;">,</span> updatedTurns<span style="color: #333333;">,</span> updatedDir<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>row <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;"><</span> R <span style="color: #333333;">&&</span> A<span style="color: #333333;">[</span>row <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">][</span>col<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">boolean</span> isDirChanged <span style="color: #333333;">=</span> currDir <span style="color: #333333;">!=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> updatedDir <span style="color: #333333;">=</span> currDir<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> updatedTurns <span style="color: #333333;">=</span> turns<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>isDirChanged<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
updatedDir <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
updatedTurns<span style="color: #333333;">++;</span>
<span style="color: #333333;">}</span>
findMinTurns<span style="color: #333333;">(</span>A<span style="color: #333333;">,</span> row <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> col<span style="color: #333333;">,</span> R<span style="color: #333333;">,</span> C<span style="color: #333333;">,</span> updatedTurns<span style="color: #333333;">,</span> updatedDir<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>col <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">>=</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">&&</span> A<span style="color: #333333;">[</span>row<span style="color: #333333;">][</span>col <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">boolean</span> isDirChanged <span style="color: #333333;">=</span> currDir <span style="color: #333333;">!=</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> updatedDir <span style="color: #333333;">=</span> currDir<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> updatedTurns <span style="color: #333333;">=</span> turns<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>isDirChanged<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
updatedDir <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">;</span>
updatedTurns<span style="color: #333333;">++;</span>
<span style="color: #333333;">}</span>
findMinTurns<span style="color: #333333;">(</span>A<span style="color: #333333;">,</span> row<span style="color: #333333;">,</span> col <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> R<span style="color: #333333;">,</span> C<span style="color: #333333;">,</span> updatedTurns<span style="color: #333333;">,</span> updatedDir<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>row <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">>=</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">&&</span> A<span style="color: #333333;">[</span>row <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">][</span>col<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">boolean</span> isDirChanged <span style="color: #333333;">=</span> currDir <span style="color: #333333;">!=</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> updatedDir <span style="color: #333333;">=</span> currDir<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> updatedTurns <span style="color: #333333;">=</span> turns<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>isDirChanged<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
updatedDir <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">;</span>
updatedTurns<span style="color: #333333;">++;</span>
<span style="color: #333333;">}</span>
findMinTurns<span style="color: #333333;">(</span>A<span style="color: #333333;">,</span> row <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> col<span style="color: #333333;">,</span> R<span style="color: #333333;">,</span> C<span style="color: #333333;">,</span> updatedTurns<span style="color: #333333;">,</span> updatedDir<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
A<span style="color: #333333;">[</span>row<span style="color: #333333;">][</span>col<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /></div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-37030652969094782732015-09-03T10:27:00.000-07:002015-09-03T10:27:08.834-07:00N Queen Problem : Placing N (natural number) Queens in a NXN chess board such that each queen is safe from the rest of the queens. | Java , Back tracking<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Dear Friends,<br />
<br />
I am here with you with another problem based upon back tracking. Its the Famous N Queen Problem.<br />
<br />
Suppose we have a NXN matrix and we have N Queens. A Queen has a nature of attacking. If She is positioned at any cell then she can attack in all the four directions [Up,Bottom,Left,Right] and also can attack diagonally [Up-Left,Up-Right,Bottom-Left,Bottom-Right]<br />
<br />
Friends if we have N Queens then we have solution for all the Natural numbers as values of N except 2 and 3.<br />
<br />
Below is my solution to this problem. Code is in Java and its based upon Recursion and Back Tracking.<br />
<br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> com<span style="color: #333333;">.</span><span style="color: #0000cc;">study</span><span style="color: #333333;">.</span><span style="color: #0000cc;">backtracking</span><span style="color: #333333;">;</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * @author Krishna.k</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * Problem :N queen problem : Placing N queens on NXN chess board.</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * Solution exists for each natural number except for N = 2 and N = 3.</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * Solution is based on Back Tracking.</span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">NQueenSolution</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> N <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">;</span> <span style="color: #888888;">// number of queens and the size of the board</span>
<span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[][]</span> board <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[</span>N<span style="color: #333333;">][</span>N<span style="color: #333333;">];</span>
NQueenSolution solution <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> NQueenSolution<span style="color: #333333;">();</span>
<span style="color: #333399; font-weight: bold;">boolean</span> isSolved <span style="color: #333333;">=</span> solution<span style="color: #333333;">.</span><span style="color: #0000cc;">solveNQueen</span><span style="color: #333333;">(</span>board<span style="color: #333333;">,</span> N<span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>isSolved<span style="color: #333333;">){</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Solution exists"</span><span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> N <span style="color: #333333;">;</span> i<span style="color: #333333;">++){</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> j <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> j <span style="color: #333333;"><</span> N <span style="color: #333333;">;</span> j<span style="color: #333333;">++){</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">print</span><span style="color: #333333;">(</span>board<span style="color: #333333;">[</span>i<span style="color: #333333;">][</span>j<span style="color: #333333;">]+</span><span style="background-color: #fff0f0;">" "</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">else</span><span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Solution does not exists"</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">solveNQueen</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[][]</span> board<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> N<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> col<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>col <span style="color: #333333;">==</span> N<span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span> <span style="color: #888888;">// all the queens have been placed successfully</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> row <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> row <span style="color: #333333;"><</span> N<span style="color: #333333;">;</span> row<span style="color: #333333;">++){</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>isSafeFromLeft<span style="color: #333333;">(</span>board<span style="color: #333333;">,</span> row<span style="color: #333333;">,</span> col<span style="color: #333333;">)</span> <span style="color: #333333;">&&</span> isSafeFromBottomLeft<span style="color: #333333;">(</span>board<span style="color: #333333;">,</span> N<span style="color: #333333;">,</span> row<span style="color: #333333;">,</span> col<span style="color: #333333;">)</span> <span style="color: #333333;">&&</span> isSafeFromTopLeft<span style="color: #333333;">(</span>board<span style="color: #333333;">,</span> row<span style="color: #333333;">,</span> col<span style="color: #333333;">)){</span>
board<span style="color: #333333;">[</span>row<span style="color: #333333;">][</span>col<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span><span style="color: #888888;">// this is a safe row and we proceed with next columns</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>solveNQueen<span style="color: #333333;">(</span>board<span style="color: #333333;">,</span> N<span style="color: #333333;">,</span> col<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">)){</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span> <span style="color: #888888;">// returning true during back track with true as return type.</span>
<span style="color: #333333;">}</span><span style="color: #008800; font-weight: bold;">else</span><span style="color: #333333;">{</span>
board<span style="color: #333333;">[</span>row<span style="color: #333333;">][</span>col<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> <span style="color: #888888;">// reseting the cell during back track with false as return type.</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">isSafeFromTopLeft</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[][]</span> board<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> row<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> col<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> traverseRow <span style="color: #333333;">=</span> row <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> traverseCol <span style="color: #333333;">=</span> col <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">while</span> <span style="color: #333333;">(</span>traverseRow <span style="color: #333333;">>=</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">&&</span> traverseCol <span style="color: #333333;">>=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>board<span style="color: #333333;">[</span>traverseRow<span style="color: #333333;">][</span>traverseCol<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
traverseRow <span style="color: #333333;">=</span> traverseRow <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
traverseCol <span style="color: #333333;">=</span> traverseCol <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">isSafeFromLeft</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[][]</span> board<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> row<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> col<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> traverseCol <span style="color: #333333;">=</span> col <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">while</span> <span style="color: #333333;">(</span>traverseCol <span style="color: #333333;">>=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>board<span style="color: #333333;">[</span>row<span style="color: #333333;">][</span>traverseCol<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
traverseCol <span style="color: #333333;">=</span> traverseCol <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">isSafeFromBottomLeft</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[][]</span> board<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> N<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> row<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> col<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> traverseRow <span style="color: #333333;">=</span> row <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> traverseCol <span style="color: #333333;">=</span> col <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">while</span> <span style="color: #333333;">(</span>traverseRow <span style="color: #333333;"><</span> N <span style="color: #333333;">&&</span> traverseCol <span style="color: #333333;">>=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>board<span style="color: #333333;">[</span>traverseRow<span style="color: #333333;">][</span>traverseCol<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
traverseRow <span style="color: #333333;">=</span> traverseRow <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
traverseCol <span style="color: #333333;">=</span> traverseCol <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /><br />
<br />
<br /></div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-43729328030026171812015-08-31T12:17:00.001-07:002015-08-31T12:18:58.416-07:00Finding permutations of r elements from total of n elements. | Code in Java<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
Dear Friends,<br />
<br />
I am here with you with another problem based on permutations and combinations.<br />
<br />
We need to find all the permutations of R elements out of total N objects. For this we will first find the combinations of R elements out of N elements and will permute them.<br />
<br />
Please find below the code in java for this.<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> com<span style="color: #333333;">.</span><span style="color: #0000cc;">learn</span><span style="color: #333333;">.</span><span style="color: #0000cc;">permutation</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.Arrays</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">PermutationOfRelementsFromNElements</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">char</span><span style="color: #333333;">[]</span> A <span style="color: #333333;">=</span> <span style="color: #333333;">{</span> <span style="color: #0044dd;">'P'</span><span style="color: #333333;">,</span> <span style="color: #0044dd;">'Q'</span><span style="color: #333333;">,</span> <span style="color: #0044dd;">'R'</span><span style="color: #333333;">,</span> <span style="color: #0044dd;">'S'</span> <span style="color: #333333;">};</span>
<span style="color: #333399; font-weight: bold;">int</span> n <span style="color: #333333;">=</span> A<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> r <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">char</span><span style="color: #333333;">[]</span> T <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">char</span><span style="color: #333333;">[</span>r<span style="color: #333333;">];</span>
combine<span style="color: #333333;">(</span>A<span style="color: #333333;">,</span> T<span style="color: #333333;">,</span> n<span style="color: #333333;">,</span> r<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * To get permutations of r elements from total N eleemnts first we take r</span>
<span style="color: #888888;"> * combinations from n elements and for each combination we permute the r</span>
<span style="color: #888888;"> * elements</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * @param A</span>
<span style="color: #888888;"> * @param T</span>
<span style="color: #888888;"> * @param n</span>
<span style="color: #888888;"> * @param r</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">combine</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">char</span><span style="color: #333333;">[]</span> A<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">char</span><span style="color: #333333;">[]</span> T<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> n<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> r<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>r <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
permute<span style="color: #333333;">(</span>T<span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span> <span style="color: #008800; font-weight: bold;">else</span> <span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>n <span style="color: #333333;">>=</span> r<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
T<span style="color: #333333;">[</span>r <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;">=</span> A<span style="color: #333333;">[</span>n <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">];</span>
combine<span style="color: #333333;">(</span>A<span style="color: #333333;">,</span> T<span style="color: #333333;">,</span> n <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> r <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
combine<span style="color: #333333;">(</span>A<span style="color: #333333;">,</span> T<span style="color: #333333;">,</span> n <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> r<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * This method permutes the r elements in array T, T is prepared from the</span>
<span style="color: #888888;"> * combine method. T[] contains the combinations of r elements from N</span>
<span style="color: #888888;"> * elements</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * @param T</span>
<span style="color: #888888;"> * @param swapingPosition</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">permute</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">char</span><span style="color: #333333;">[]</span> T<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> swapingPosition<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>swapingPosition <span style="color: #333333;">==</span> T<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>Arrays<span style="color: #333333;">.</span><span style="color: #0000cc;">toString</span><span style="color: #333333;">(</span>T<span style="color: #333333;">));</span>
<span style="color: #333333;">}</span> <span style="color: #008800; font-weight: bold;">else</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> swapingPosition<span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> T<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
swap<span style="color: #333333;">(</span>T<span style="color: #333333;">,</span> swapingPosition<span style="color: #333333;">,</span> i<span style="color: #333333;">);</span>
permute<span style="color: #333333;">(</span>T<span style="color: #333333;">,</span> swapingPosition <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
swap<span style="color: #333333;">(</span>T<span style="color: #333333;">,</span> swapingPosition<span style="color: #333333;">,</span> i<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * This is simple utility method to swap two elements of the array A at</span>
<span style="color: #888888;"> * given two indices, index1 and index2</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * @param A</span>
<span style="color: #888888;"> * @param index1</span>
<span style="color: #888888;"> * @param index2</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">swap</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">char</span><span style="color: #333333;">[]</span> A<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> index1<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> index2<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">char</span> temp <span style="color: #333333;">=</span> A<span style="color: #333333;">[</span>index1<span style="color: #333333;">];</span>
A<span style="color: #333333;">[</span>index1<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> A<span style="color: #333333;">[</span>index2<span style="color: #333333;">];</span>
A<span style="color: #333333;">[</span>index2<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> temp<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /> </div>
</div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-41664552059483619122015-08-31T12:11:00.001-07:002015-08-31T12:11:26.660-07:00Code in Java for finding Longest Path in Directed Acyclic Graph | Using Topological sorting<div dir="ltr" style="text-align: left;" trbidi="on">
Dear Friends,<br />
<br />
I am here with you with a problem based on Directed A-cyclic Graph [DAG].<br />
<br />
Given a DAG, we are supposed to find the longest path in it.<br />
<br />
Friends Please find below the code in java for this problem.<br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> com<span style="color: #333333;">.</span><span style="color: #0000cc;">learn</span><span style="color: #333333;">.</span><span style="color: #0000cc;">dag</span><span style="color: #333333;">.</span><span style="color: #0000cc;">longest</span><span style="color: #333333;">.</span><span style="color: #0000cc;">path</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">LongestPathInDAG</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
Graph g <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Graph<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">);</span>
g<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">);</span>
g<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">);</span>
g<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">);</span>
g<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span>
g<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">);</span>
g<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span>
g<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">7</span><span style="color: #333333;">);</span>
g<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
g<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
g<span style="color: #333333;">.</span><span style="color: #0000cc;">addEdge</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">,</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span>
<span style="color: #333399; font-weight: bold;">int</span> s <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
g<span style="color: #333333;">.</span><span style="color: #0000cc;">findLongestPath</span><span style="color: #333333;">(</span>s<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Graph</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> V<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[][]</span> matrix<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> vertices<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">boolean</span><span style="color: #333333;">[]</span> visited<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> distances<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> predecessor<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> Stack stack<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Graph</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> V<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">V</span> <span style="color: #333333;">=</span> V<span style="color: #333333;">;</span>
vertices <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[</span>V<span style="color: #333333;">];</span>
visited <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">boolean</span><span style="color: #333333;">[</span>V<span style="color: #333333;">];</span>
predecessor <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[</span>V<span style="color: #333333;">];</span>
distances <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[</span>V<span style="color: #333333;">];</span>
matrix <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[</span>V<span style="color: #333333;">][</span>V<span style="color: #333333;">];</span>
stack <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Stack<span style="color: #333333;">(</span>V<span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> V<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
addVertex<span style="color: #333333;">(</span>i<span style="color: #333333;">);</span>
distances<span style="color: #333333;">[</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> Integer<span style="color: #333333;">.</span><span style="color: #0000cc;">MIN_VALUE</span><span style="color: #333333;">;</span>
predecessor<span style="color: #333333;">[</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addVertex</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> name<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
vertices<span style="color: #333333;">[</span>name<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> name<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">addEdge</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> source<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> destination<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> weight<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
matrix<span style="color: #333333;">[</span>source<span style="color: #333333;">][</span>destination<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> weight<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">findLongestPath</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> source<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
invokeTopologicalSort<span style="color: #333333;">();</span>
distances<span style="color: #333333;">[</span>source<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> <span style="color: #888888;">// Initialize source with 0</span>
updateMaxDistanceForAllAdjVertices<span style="color: #333333;">();</span> <span style="color: #888888;">// for all nodes connected,</span>
<span style="color: #888888;">// directly or indirectly,</span>
<span style="color: #888888;">// with source will have</span>
<span style="color: #888888;">// their distances</span>
<span style="color: #888888;">// calculated</span>
printDistances<span style="color: #333333;">(</span>source<span style="color: #333333;">);</span>
printPath<span style="color: #333333;">(</span>source<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">printDistances</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> source<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Distances from source "</span> <span style="color: #333333;">+</span> source <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">" are as follows: "</span><span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> to <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> to <span style="color: #333333;"><</span> V<span style="color: #333333;">;</span> to<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> distance <span style="color: #333333;">=</span> distances<span style="color: #333333;">[</span>to<span style="color: #333333;">];</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">print</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"from "</span> <span style="color: #333333;">+</span> source <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">" to "</span> <span style="color: #333333;">+</span> to <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">": "</span><span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>distance <span style="color: #333333;">==</span> Integer<span style="color: #333333;">.</span><span style="color: #0000cc;">MIN_VALUE</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">" -Infinity "</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span> <span style="color: #008800; font-weight: bold;">else</span> <span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>distance <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">" "</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">printPath</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> source<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Path from source "</span> <span style="color: #333333;">+</span> source <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">" to other nodes are as follows: "</span><span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> V<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>distances<span style="color: #333333;">[</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> Integer<span style="color: #333333;">.</span><span style="color: #0000cc;">MIN_VALUE</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"No Path from "</span> <span style="color: #333333;">+</span> source <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">" to "</span> <span style="color: #333333;">+</span> i<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span> <span style="color: #008800; font-weight: bold;">else</span> <span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>i <span style="color: #333333;">!=</span> source<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> from <span style="color: #333333;">=</span> predecessor<span style="color: #333333;">[</span>i<span style="color: #333333;">];</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">print</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Path from "</span> <span style="color: #333333;">+</span> source <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">" to "</span> <span style="color: #333333;">+</span> i <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">": "</span><span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>from <span style="color: #333333;">==</span> source<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">print</span><span style="color: #333333;">(</span>from <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">" "</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">while</span> <span style="color: #333333;">(</span>from <span style="color: #333333;">!=</span> source<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">print</span><span style="color: #333333;">(</span>from <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">" "</span><span style="color: #333333;">);</span>
from <span style="color: #333333;">=</span> predecessor<span style="color: #333333;">[</span>from<span style="color: #333333;">];</span>
<span style="color: #333333;">}</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">print</span><span style="color: #333333;">(</span>i <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">" "</span><span style="color: #333333;">);</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">updateMaxDistanceForAllAdjVertices</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">while</span> <span style="color: #333333;">(!</span>stack<span style="color: #333333;">.</span><span style="color: #0000cc;">isEmpty</span><span style="color: #333333;">())</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> from <span style="color: #333333;">=</span> stack<span style="color: #333333;">.</span><span style="color: #0000cc;">pop</span><span style="color: #333333;">();</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>distances<span style="color: #333333;">[</span>from<span style="color: #333333;">]</span> <span style="color: #333333;">!=</span> Integer<span style="color: #333333;">.</span><span style="color: #0000cc;">MIN_VALUE</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> adjacent <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> adjacent <span style="color: #333333;"><</span> V<span style="color: #333333;">;</span> adjacent<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>matrix<span style="color: #333333;">[</span>from<span style="color: #333333;">][</span>adjacent<span style="color: #333333;">]</span> <span style="color: #333333;">!=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>distances<span style="color: #333333;">[</span>adjacent<span style="color: #333333;">]</span> <span style="color: #333333;"><</span> distances<span style="color: #333333;">[</span>from<span style="color: #333333;">]</span> <span style="color: #333333;">+</span> matrix<span style="color: #333333;">[</span>from<span style="color: #333333;">][</span>adjacent<span style="color: #333333;">])</span> <span style="color: #333333;">{</span>
predecessor<span style="color: #333333;">[</span>adjacent<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> from<span style="color: #333333;">;</span>
distances<span style="color: #333333;">[</span>adjacent<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> distances<span style="color: #333333;">[</span>from<span style="color: #333333;">]</span> <span style="color: #333333;">+</span> matrix<span style="color: #333333;">[</span>from<span style="color: #333333;">][</span>adjacent<span style="color: #333333;">];</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">invokeTopologicalSort</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> V<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(!</span>visited<span style="color: #333333;">[</span>i<span style="color: #333333;">])</span> <span style="color: #333333;">{</span>
dfs<span style="color: #333333;">(</span>i<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">dfs</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> source<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
visited<span style="color: #333333;">[</span>source<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> adjacent <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> adjacent <span style="color: #333333;"><</span> V<span style="color: #333333;">;</span> adjacent<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>matrix<span style="color: #333333;">[</span>source<span style="color: #333333;">][</span>adjacent<span style="color: #333333;">]</span> <span style="color: #333333;">!=</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">&&</span> <span style="color: #333333;">!</span>visited<span style="color: #333333;">[</span>adjacent<span style="color: #333333;">])</span> <span style="color: #333333;">{</span>
dfs<span style="color: #333333;">(</span>adjacent<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
stack<span style="color: #333333;">.</span><span style="color: #0000cc;">push</span><span style="color: #333333;">(</span>source<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Stack</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> maxSize<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> stack<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> top <span style="color: #333333;">=</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> size <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Stack</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> maxSize<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">maxSize</span> <span style="color: #333333;">=</span> maxSize<span style="color: #333333;">;</span>
stack <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[</span>maxSize<span style="color: #333333;">];</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">push</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> item<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
stack<span style="color: #333333;">[++</span>top<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> item<span style="color: #333333;">;</span>
size<span style="color: #333333;">++;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">pop</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> item <span style="color: #333333;">=</span> stack<span style="color: #333333;">[</span>top<span style="color: #333333;">--];</span>
size<span style="color: #333333;">--;</span>
<span style="color: #008800; font-weight: bold;">return</span> item<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">isEmpty</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> size <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /></div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com1tag:blogger.com,1999:blog-2076702334425737754.post-27001755547558159622015-08-31T08:04:00.000-07:002015-08-31T08:08:58.945-07:00Subset Sum problem | Java and Backtracking<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Hello Friends,<br />
<br />
Today I am here with you with another problem based upon recursion and back tracking.<br />
<br />
Suppose we have an array of positive integer elements: 'arr' and a positive number: 'targetSum'.<br />
We need to all the possible subsets of the array elements such that adding the elements of any of the found subsets results in 'targetSum'.<br />
<br />
Suppose we have arr= { 2, 3, 4, 5 } and targetSum = 7 then our subsets are {2,5},{3,4}.<br />
<br />
<br />
Friends I have tried to solve this using Back-tracking, please find the code in java below.<br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> com<span style="color: #333333;">.</span><span style="color: #0000cc;">recursion</span><span style="color: #333333;">.</span><span style="color: #0000cc;">backtracking</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">SubSetSum</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> input <span style="color: #333333;">=</span> <span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">5</span> <span style="color: #333333;">};</span>
<span style="color: #333399; font-weight: bold;">int</span> targetSum <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">7</span><span style="color: #333333;">;</span>
SubSetSum subSetSum <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> SubSetSum<span style="color: #333333;">();</span>
subSetSum<span style="color: #333333;">.</span><span style="color: #0000cc;">findSubSets</span><span style="color: #333333;">(</span>input<span style="color: #333333;">,</span> targetSum<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> set<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> selectedElements<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> targetSum<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> numOfElements<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">findSubSets</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> set<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> targetSum<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">set</span> <span style="color: #333333;">=</span> set<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">numOfElements</span> <span style="color: #333333;">=</span> set<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">targetSum</span> <span style="color: #333333;">=</span> targetSum<span style="color: #333333;">;</span>
selectedElements <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[</span>numOfElements<span style="color: #333333;">];</span>
quicksort<span style="color: #333333;">(</span>set<span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> numOfElements<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
<span style="color: #333399; font-weight: bold;">int</span> sumOfAllElements <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">for</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> element <span style="color: #333333;">:</span> set<span style="color: #333333;">){</span>
sumOfAllElements <span style="color: #333333;">+=</span> element<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
findSubSets<span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> sumOfAllElements<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">findSubSets</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> sumTillNow<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> index<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> sumOfRemaining<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
selectedElements<span style="color: #333333;">[</span>index<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span> <span style="color: #888888;">// selecting element at index : 'index'</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>targetSum <span style="color: #333333;">==</span> set<span style="color: #333333;">[</span>index<span style="color: #333333;">]</span> <span style="color: #333333;">+</span> sumTillNow<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
print<span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #888888;">// (sum + set[index] + set[index+1] <= targetSum) : this condition</span>
<span style="color: #888888;">// ensures selecting</span>
<span style="color: #888888;">// the next element is useful and the total sum by including next</span>
<span style="color: #888888;">// element will not exceed the target sum.</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">((</span>index <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;"><</span> numOfElements<span style="color: #333333;">)</span> <span style="color: #333333;">&&</span> <span style="color: #333333;">(</span>sumTillNow <span style="color: #333333;">+</span> set<span style="color: #333333;">[</span>index<span style="color: #333333;">]</span> <span style="color: #333333;">+</span> set<span style="color: #333333;">[</span>index <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;"><=</span> targetSum<span style="color: #333333;">))</span> <span style="color: #333333;">{</span>
findSubSets<span style="color: #333333;">(</span>sumTillNow <span style="color: #333333;">+</span> set<span style="color: #333333;">[</span>index<span style="color: #333333;">],</span> index <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> sumOfRemaining <span style="color: #333333;">-</span> set<span style="color: #333333;">[</span>index<span style="color: #333333;">]);</span>
<span style="color: #333333;">}</span>
<span style="color: #888888;">// now exploring the other path: not Selecting the element at index:</span>
<span style="color: #888888;">// 'index'</span>
selectedElements<span style="color: #333333;">[</span>index<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #888888;">// (sum + set[index+1] <= targetSum) : this condition ensures selecting</span>
<span style="color: #888888;">// the next element is useful and the total sum by including next</span>
<span style="color: #888888;">// element will not exceed the target sum.</span>
<span style="color: #888888;">// (sum + sumOfRemaining - set[index] >= targetSum) ensures the total</span>
<span style="color: #888888;">// sum of all the elements by excluding the current element may achieve</span>
<span style="color: #888888;">// the target sum, if in case the resultant sum is less than the target</span>
<span style="color: #888888;">// sum then exploring this path is of no use</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">((</span>index <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;"><</span> numOfElements<span style="color: #333333;">)</span> <span style="color: #333333;">&&</span> <span style="color: #333333;">(</span>sumTillNow <span style="color: #333333;">+</span> set<span style="color: #333333;">[</span>index <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;"><=</span> targetSum<span style="color: #333333;">)</span>
<span style="color: #333333;">&&</span> <span style="color: #333333;">(</span>sumTillNow <span style="color: #333333;">+</span> sumOfRemaining <span style="color: #333333;">-</span> set<span style="color: #333333;">[</span>index<span style="color: #333333;">]</span> <span style="color: #333333;">>=</span> targetSum<span style="color: #333333;">))</span> <span style="color: #333333;">{</span>
findSubSets<span style="color: #333333;">(</span>sumTillNow<span style="color: #333333;">,</span> index <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> sumOfRemaining <span style="color: #333333;">-</span> set<span style="color: #333333;">[</span>index<span style="color: #333333;">]);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">print</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> numOfElements<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>selectedElements<span style="color: #333333;">[</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">print</span><span style="color: #333333;">(</span>set<span style="color: #333333;">[</span>i<span style="color: #333333;">]+</span><span style="background-color: #fff0f0;">" "</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">quicksort</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> arr<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> start<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> end<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>start <span style="color: #333333;"><</span> end<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
swap<span style="color: #333333;">(</span>arr<span style="color: #333333;">,</span> <span style="color: #333333;">(</span>start <span style="color: #333333;">+</span> <span style="color: #333333;">(</span>end <span style="color: #333333;">-</span> start<span style="color: #333333;">)</span> <span style="color: #333333;">/</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">),</span> end<span style="color: #333333;">);</span>
<span style="color: #333399; font-weight: bold;">int</span> pIndex <span style="color: #333333;">=</span> partition<span style="color: #333333;">(</span>arr<span style="color: #333333;">,</span> start<span style="color: #333333;">,</span> end<span style="color: #333333;">);</span>
quicksort<span style="color: #333333;">(</span>arr<span style="color: #333333;">,</span> start<span style="color: #333333;">,</span> pIndex <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
quicksort<span style="color: #333333;">(</span>arr<span style="color: #333333;">,</span> pIndex <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> end<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">partition</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> arr<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> start<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> end<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> pIndex <span style="color: #333333;">=</span> start<span style="color: #333333;">,</span> pivot <span style="color: #333333;">=</span> arr<span style="color: #333333;">[</span>end<span style="color: #333333;">];</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> start<span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> end<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>arr<span style="color: #333333;">[</span>i<span style="color: #333333;">]</span> <span style="color: #333333;"><</span> pivot<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
swap<span style="color: #333333;">(</span>arr<span style="color: #333333;">,</span>pIndex<span style="color: #333333;">,</span>i<span style="color: #333333;">);</span>
pIndex<span style="color: #333333;">++;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
swap<span style="color: #333333;">(</span>arr<span style="color: #333333;">,</span>pIndex<span style="color: #333333;">,</span>end<span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">return</span> pIndex<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">swap</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> arr<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> index1<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> index2<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> temp <span style="color: #333333;">=</span> arr<span style="color: #333333;">[</span>index1<span style="color: #333333;">];</span>
arr<span style="color: #333333;">[</span>index1<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> arr<span style="color: #333333;">[</span>index2<span style="color: #333333;">];</span>
arr<span style="color: #333333;">[</span>index2<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> temp<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br />
<br />
<br /></div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com1tag:blogger.com,1999:blog-2076702334425737754.post-9413940377187101962015-08-30T10:46:00.004-07:002015-08-30T10:46:50.129-07:00Make correct equation to achieve a given RHS. | Java and Backtracking<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
<br />
I am with you with another problem based upon back tracking.<br />
<br />
If we have an integer array A[] and another integer value K, we need to find is there a sequence of '+', '-' exists such that if applied on the elements of A produce K. The operations need to be applied without changing the relative position of the array elements.<br />
<br />
Friends I have used recursion with back tracking to solve this problem, please find the code below for the same.<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> com<span style="color: #333333;">.</span><span style="color: #0000cc;">recursion</span><span style="color: #333333;">.</span><span style="color: #0000cc;">backtracking</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.Arrays</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">MakeValidEquation</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> numbers<span style="color: #333333;">[]</span> <span style="color: #333333;">=</span> <span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">5</span> <span style="color: #333333;">};</span>
<span style="color: #333399; font-weight: bold;">int</span> RHS <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">;</span>
MakeValidEquation equation <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> MakeValidEquation<span style="color: #333333;">(</span>numbers<span style="color: #333333;">,</span> RHS<span style="color: #333333;">);</span>
<span style="color: #333399; font-weight: bold;">boolean</span> isRHSAchievable <span style="color: #333333;">=</span> equation<span style="color: #333333;">.</span><span style="color: #0000cc;">makeValidEquation</span><span style="color: #333333;">(</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> numbers<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>isRHSAchievable<span style="color: #333333;">){</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Operations : "</span><span style="color: #333333;">+</span>Arrays<span style="color: #333333;">.</span><span style="color: #0000cc;">toString</span><span style="color: #333333;">(</span>equation<span style="color: #333333;">.</span><span style="color: #0000cc;">operators</span><span style="color: #333333;">));</span>
<span style="color: #333333;">}</span><span style="color: #008800; font-weight: bold;">else</span><span style="color: #333333;">{</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"RHS can not be achieved by +, - on the numbers"</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">MakeValidEquation</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> numbers<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> RHS<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">numbers</span> <span style="color: #333333;">=</span> numbers<span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> n <span style="color: #333333;">=</span> numbers<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">RHS</span> <span style="color: #333333;">=</span> RHS<span style="color: #333333;">;</span>
operators <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">char</span><span style="color: #333333;">[</span>n<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">];</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">char</span><span style="color: #333333;">[]</span> operators<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> numbers<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">int</span> RHS<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">makeValidEquation</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> n<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>i <span style="color: #333333;">==</span> n <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> result <span style="color: #333333;">=</span> numbers<span style="color: #333333;">[</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">];</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> j <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span> j <span style="color: #333333;"><=</span> n <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">;</span> j<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>operators<span style="color: #333333;">[</span>j<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0044dd;">'+'</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
result <span style="color: #333333;">=</span> result <span style="color: #333333;">+</span> numbers<span style="color: #333333;">[</span>j <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">];</span>
<span style="color: #333333;">}</span> <span style="color: #008800; font-weight: bold;">else</span> <span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>operators<span style="color: #333333;">[</span>j<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0044dd;">'-'</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
result <span style="color: #333333;">=</span> result <span style="color: #333333;">-</span> numbers<span style="color: #333333;">[</span>j <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">];</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> result <span style="color: #333333;">==</span> RHS<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
operators<span style="color: #333333;">[</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #0044dd;">'+'</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>makeValidEquation<span style="color: #333333;">(</span>i<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> n<span style="color: #333333;">)){</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span><span style="color: #008800; font-weight: bold;">else</span> <span style="color: #333333;">{</span>
<span style="color: #888888;">// try next option</span>
operators<span style="color: #333333;">[</span>i<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #0044dd;">'-'</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>makeValidEquation<span style="color: #333333;">(</span>i<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> n<span style="color: #333333;">)){</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">else</span> <span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /><br />
<br /></div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-4963078049734654692015-08-30T08:52:00.002-07:002015-08-30T09:45:15.139-07:00Solution in java for : Finding if a path exists from start to end cell in a maze | Back Tracking and Dynamic Programming<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
Hello Friends,<br />
<br />
Today I am here with you with a recursion problem. Today we have a little tough problem.<br />
<br />
Suppose we have a maze and we need to determine if a path exits from starting point to the last point in the maze. Maze is represented by a 2-d-matrix. Lets call this matrix 'maze'. maze[0][0] represents the starting point and maze[rows-1][columns-1] be the end point. Any cell 'maze[i][j]' can be used as a part of the path if it contains 1 and can be reached from immediate top, left, right or bottom cells. Cells containing 0 are the ones which can not be used in the path.<br />
<br />
Friends I have tried solving this using two Approaches.<br />
1. Recursion [Back Tracking] : Depth search First approach : DFS<br />
2. Dynamic Programming.<br />
<br />
**Note that <b>Dynamic programming approach will fail</b> <b>for few examples</b> where path exists by traversing <b>upwards </b>or <b>left side</b> like below example<br />
<br />
<span style="background-color: yellow;">1 1 1 1</span> 0 0 0 0<br />
0 0 0 <span style="background-color: yellow;">1</span> 0 <span style="background-color: yellow;">1 1 1</span><br />
0 <span style="background-color: yellow;">1 1 1</span> 0 <span style="background-color: yellow;">1</span> 0 <span style="background-color: yellow;">1</span><br />
0 <span style="background-color: yellow;">1</span> 0 0 0 <span style="background-color: yellow;">1</span> 0 <span style="background-color: yellow;">1</span> <br />
0 <span style="background-color: yellow;">1 1 1 1 1</span> 0 <span style="background-color: yellow;">1</span><br />
<br />
<br />
Friends please find below the code for this problem.</div>
<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> com<span style="color: #333333;">.</span><span style="color: #0000cc;">recursion</span><span style="color: #333333;">.</span><span style="color: #0000cc;">backtracking</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Maze</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> mazeForDFS<span style="color: #333333;">[][]</span> <span style="color: #333333;">=</span> <span style="color: #333333;">{</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">}</span>
<span style="color: #333333;">};</span>
<span style="color: #333399; font-weight: bold;">int</span> mazeForDP<span style="color: #333333;">[][]</span> <span style="color: #333333;">=</span> <span style="color: #333333;">{</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">},</span>
<span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">}</span>
<span style="color: #333333;">};</span>
<span style="color: #333399; font-weight: bold;">boolean</span> isPathAvailableDFS <span style="color: #333333;">=</span> isPathAvailable<span style="color: #333333;">(</span>mazeForDFS<span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">,</span> mazeForDFS<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">,</span> mazeForDFS<span style="color: #333333;">[</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">].</span><span style="color: #0000cc;">length</span><span style="color: #333333;">);</span>
<span style="color: #333399; font-weight: bold;">boolean</span> isPathAvailableDP <span style="color: #333333;">=</span> isPathAvailable<span style="color: #333333;">(</span>mazeForDP<span style="color: #333333;">);</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"DFS way : "</span> <span style="color: #333333;">+</span> isPathAvailableDFS<span style="color: #333333;">);</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"DP way : "</span> <span style="color: #333333;">+</span> isPathAvailableDP<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #008800; font-weight: bold;">final</span> <span style="color: #333399; font-weight: bold;">int</span> VISITED <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * This is a recursive approach based upon recursion and Back tracking. If a</span>
<span style="color: #888888;"> * end point is reached then true is returned all the way up to the first</span>
<span style="color: #888888;"> * calling of the method, else false is returned. False is propagated down</span>
<span style="color: #888888;"> * the call stack if all the options [top, left, right, down] are explored</span>
<span style="color: #888888;"> * and no other cell is left to explore.</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * @param maze</span>
<span style="color: #888888;"> * @param i</span>
<span style="color: #888888;"> * @param j</span>
<span style="color: #888888;"> * @param rows</span>
<span style="color: #888888;"> * @param columns</span>
<span style="color: #888888;"> * @return true if path exists else returns false;</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">isPathAvailable</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[][]</span> maze<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> i<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> j<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> rows<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> columns<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>i <span style="color: #333333;">==</span> rows <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">&&</span> j <span style="color: #333333;">==</span> columns <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
maze<span style="color: #333333;">[</span>i<span style="color: #333333;">][</span>j<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> VISITED<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>j <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;"><</span> columns <span style="color: #333333;">&&</span> maze<span style="color: #333333;">[</span>i<span style="color: #333333;">][</span>j <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;">!=</span> VISITED<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>isPathAvailable<span style="color: #333333;">(</span>maze<span style="color: #333333;">,</span> i<span style="color: #333333;">,</span> j <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> rows<span style="color: #333333;">,</span> columns<span style="color: #333333;">))</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>i <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;"><</span> rows <span style="color: #333333;">&&</span> maze<span style="color: #333333;">[</span>i <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">][</span>j<span style="color: #333333;">]</span> <span style="color: #333333;">!=</span> VISITED<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>isPathAvailable<span style="color: #333333;">(</span>maze<span style="color: #333333;">,</span> i <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> j<span style="color: #333333;">,</span> rows<span style="color: #333333;">,</span> columns<span style="color: #333333;">))</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>j <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">>=</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">&&</span> maze<span style="color: #333333;">[</span>i<span style="color: #333333;">][</span>j <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;">!=</span> VISITED<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>isPathAvailable<span style="color: #333333;">(</span>maze<span style="color: #333333;">,</span> i<span style="color: #333333;">,</span> j <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> rows<span style="color: #333333;">,</span> columns<span style="color: #333333;">))</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>i <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">>=</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">&&</span> maze<span style="color: #333333;">[</span>i <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">][</span>j<span style="color: #333333;">]</span> <span style="color: #333333;">!=</span> VISITED<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>isPathAvailable<span style="color: #333333;">(</span>maze<span style="color: #333333;">,</span> i <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> j<span style="color: #333333;">,</span> rows<span style="color: #333333;">,</span> columns<span style="color: #333333;">))</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #888888;">/**</span>
<span style="color: #888888;"> * This method uses Dynamic programming to solve the problem. It exploits</span>
<span style="color: #888888;"> * the information for all the first row and column information and then</span>
<span style="color: #888888;"> * verifies the rest of the cells if they are reachable. In case they are</span>
<span style="color: #888888;"> * not reachable this method marks them as 0, as they are as good as cells</span>
<span style="color: #888888;"> * with value = 0;</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">boolean</span> <span style="color: #0066bb; font-weight: bold;">isPathAvailable</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[][]</span> maze<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span> rows <span style="color: #333333;">=</span> maze<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">;</span>
<span style="color: #333399; font-weight: bold;">int</span> coloumns <span style="color: #333333;">=</span> maze<span style="color: #333333;">[</span><span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">].</span><span style="color: #0000cc;">length</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> i <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span> i <span style="color: #333333;"><</span> rows<span style="color: #333333;">;</span> i<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">for</span> <span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> j <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span> j <span style="color: #333333;"><</span> coloumns<span style="color: #333333;">;</span> j<span style="color: #333333;">++)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>maze<span style="color: #333333;">[</span>i<span style="color: #333333;">][</span>j<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">&&</span> maze<span style="color: #333333;">[</span>i <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">][</span>j<span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">&&</span> maze<span style="color: #333333;">[</span>i<span style="color: #333333;">][</span>j <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
maze<span style="color: #333333;">[</span>i<span style="color: #333333;">][</span>j<span style="color: #333333;">]</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">return</span> maze<span style="color: #333333;">[</span>rows <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">][</span>coloumns <span style="color: #333333;">-</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /></div>
</div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-80090776922940507652015-08-28T13:24:00.002-07:002015-08-28T13:24:24.453-07:00Compute 'x' raised to power 'n' in O(logN) time using Java<div dir="ltr" style="text-align: left;" trbidi="on">
Hello friends,<br />
<br />
In continuation to the recursive algorithms, I am here with you with another problem.<br />
<br />
Suppose we have a number 'x' a another positive Integer 'n'. We need to find the value of 'x' raised to power to 'n'.<br />
<br />
Friends please find below the code in java for this.<br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> com<span style="color: #333333;">.</span><span style="color: #0000cc;">recursion</span><span style="color: #333333;">.</span><span style="color: #0000cc;">power</span><span style="color: #333333;">;</span></pre>
</div>
<br />
<br /><span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">java.util.Scanner</span><span style="color: #333333;">;</span><br /><br /><span style="color: #888888;">/**</span><br /><span style="color: #888888;"> * </span><br /><span style="color: #888888;"> * @author krishna.k</span><br /><span style="color: #888888;"> * </span><br /><span style="color: #888888;"> * This class computes the value of 'x' raised to power of 'n' in time</span><br /><span style="color: #888888;"> * complexity of O(log n). 'x' is Integer, and n is a positive Integer</span><br /><span style="color: #888888;"> * including 0.</span><br /><span style="color: #888888;"> * </span><br /><span style="color: #888888;"> * </span><br /><span style="color: #888888;"> * </span><br /><span style="color: #888888;"> *</span><br /><span style="color: #888888;"> */</span><br /><span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">PowerComputation</span> <span style="color: #333333;">{</span><br /> <span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span><br /> Scanner sc <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Scanner<span style="color: #333333;">(</span>System<span style="color: #333333;">.</span><span style="color: #0000cc;">in</span><span style="color: #333333;">);</span><br /> System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Enter the value of x (base)"</span><span style="color: #333333;">);</span><br /> <span style="color: #333399; font-weight: bold;">int</span> x <span style="color: #333333;">=</span> sc<span style="color: #333333;">.</span><span style="color: #0000cc;">nextInt</span><span style="color: #333333;">();</span><br /> System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Enter a positve integer n (power)"</span><span style="color: #333333;">);</span><br /> <span style="color: #333399; font-weight: bold;">int</span> n <span style="color: #333333;">=</span> sc<span style="color: #333333;">.</span><span style="color: #0000cc;">nextInt</span><span style="color: #333333;">();</span><br /> System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Value of "</span> <span style="color: #333333;">+</span> x <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">" raised to power "</span> <span style="color: #333333;">+</span> n <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">" is "</span> <span style="color: #333333;">+</span> computePower<span style="color: #333333;">(</span>x<span style="color: #333333;">,</span> n<span style="color: #333333;">));</span><br /> <span style="color: #333333;">}</span><br /><br /> <span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">int</span> <span style="color: #0066bb; font-weight: bold;">computePower</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span> x<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> n<span style="color: #333333;">)</span> <span style="color: #333333;">{</span><br /> <span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>x <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span> <span style="color: #333333;">||</span> x <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">1</span> <span style="color: #333333;">||</span> n <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span><br /> <span style="color: #008800; font-weight: bold;">return</span> x<span style="color: #333333;">;</span><br /> <span style="color: #333333;">}</span><br /> <span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>n <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span><br /> <span style="color: #008800; font-weight: bold;">return</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">;</span><br /> <span style="color: #333333;">}</span><br /> <span style="color: #333399; font-weight: bold;">int</span> temp <span style="color: #333333;">=</span> computePower<span style="color: #333333;">(</span>x<span style="color: #333333;">,</span> n <span style="color: #333333;">/</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">);</span><br /> <span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>n <span style="color: #333333;">%</span> <span style="color: #0000dd; font-weight: bold;">2</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span><br /> <span style="color: #008800; font-weight: bold;">return</span> temp <span style="color: #333333;">*</span> temp<span style="color: #333333;">;</span><br /> <span style="color: #333333;">}</span> <span style="color: #008800; font-weight: bold;">else</span> <span style="color: #333333;">{</span><br /> <span style="color: #008800; font-weight: bold;">return</span> x <span style="color: #333333;">*</span> temp <span style="color: #333333;">*</span> temp<span style="color: #333333;">;</span><br /> <span style="color: #333333;">}</span><br /> <span style="color: #333333;">}</span><br /><span style="color: #333333;">}</span></div>
<br />Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0tag:blogger.com,1999:blog-2076702334425737754.post-54212696813309266632015-08-28T12:48:00.002-07:002015-08-30T09:09:04.720-07:00Print the elements of the array in straight order and in reverse order using Recursion in Java<div dir="ltr" style="text-align: left;" trbidi="on">
Hello friends,<br />
<br />
I am here with another question in continuation to our simple recursive algorithm based questions.<br />
<br />
If we have an array of numbers, we need to <b>print the elements of the array in straight order and in reverse order. </b><br />
<br />
We can easily do this using iteration but for learning purpose lets try doing this using recursion.<br />
<br />
Note that to print the elements in the reverse order I have used two methods, one uses simple index based manipulation but lets observe the other method : printReverseInterestingWay(). While other method prints the elements as it visits the element first time but this method prints the element during <b>re-visit</b> (following the recurrence method calls in stack)<br />
<br />
Friends Please find the code below.<br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> com<span style="color: #333333;">.</span><span style="color: #0000cc;">recursion</span><span style="color: #333333;">.</span><span style="color: #0000cc;">printarray</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">StraightReversePrintArray</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">main</span><span style="color: #333333;">(</span>String<span style="color: #333333;">[]</span> args<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> input <span style="color: #333333;">=</span> <span style="color: #333333;">{</span> <span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">2</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">3</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">4</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">6</span><span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">8</span> <span style="color: #333333;">};</span>
<span style="color: #333399; font-weight: bold;">int</span> size <span style="color: #333333;">=</span> input<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">;</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Straight printing of the Array: "</span><span style="color: #333333;">);</span>
printStraight<span style="color: #333333;">(</span>input<span style="color: #333333;">,</span> size<span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">);</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Reverse printing of the Array: "</span><span style="color: #333333;">);</span>
printReverse<span style="color: #333333;">(</span>input<span style="color: #333333;">,</span> size<span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">);</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"Reverse printing of the Array using interesting way: "</span><span style="color: #333333;">);</span>
printReverseInterestingWay<span style="color: #333333;">(</span>input<span style="color: #333333;">,</span> size<span style="color: #333333;">,</span> <span style="color: #0000dd; font-weight: bold;">0</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">printStraight</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> input<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> i<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>i <span style="color: #333333;"><</span> size<span style="color: #333333;">){</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>input<span style="color: #333333;">[</span>i<span style="color: #333333;">]);</span>
printStraight<span style="color: #333333;">(</span>input<span style="color: #333333;">,</span> size<span style="color: #333333;">,</span> i<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">printReverse</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> input<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> i<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>i <span style="color: #333333;"><</span> size<span style="color: #333333;">){</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>input<span style="color: #333333;">[</span>size<span style="color: #333333;">-</span>i<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">]);</span>
printReverse<span style="color: #333333;">(</span>input<span style="color: #333333;">,</span> size<span style="color: #333333;">,</span> i<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">printReverseInterestingWay</span><span style="color: #333333;">(</span><span style="color: #333399; font-weight: bold;">int</span><span style="color: #333333;">[]</span> input<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> size<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> i<span style="color: #333333;">){</span>
<span style="color: #008800; font-weight: bold;">if</span><span style="color: #333333;">(</span>i <span style="color: #333333;"><</span> size<span style="color: #333333;">){</span>
printReverseInterestingWay<span style="color: #333333;">(</span>input<span style="color: #333333;">,</span> size<span style="color: #333333;">,</span> i<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">);</span>
System<span style="color: #333333;">.</span><span style="color: #0000cc;">out</span><span style="color: #333333;">.</span><span style="color: #0000cc;">println</span><span style="color: #333333;">(</span>input<span style="color: #333333;">[</span>i<span style="color: #333333;">]);</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span></pre>
</div>
<br /></div>
Krishna Kumarhttp://www.blogger.com/profile/15727160511317276333noreply@blogger.com0