<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3113019092039994633</id><updated>2024-09-01T01:52:33.505-07:00</updated><category term="c"/><category term="algorithm"/><category term="c++"/><category term="computer graphics"/><category term="python"/><category term="Data Structures"/><category term="String Matching"/><category term="operating system"/><category term="Dynamic Programming"/><category term="c#"/><category term="visual studio"/><category term="Artificial Intellignce"/><category term="Dynamic Data Structures"/><category term="Graph Theory"/><category term="Strings"/><category term="regex"/><category term="AVL tree"/><category term="Binary Search Tree"/><category term="Breadth first Search"/><category term="Divide and Conquer"/><category term="Fibonnaci"/><category term="Greedy Scheduling"/><category term="Implementation"/><category term="Logic"/><category term="Troubleshoot"/><category term="class"/><category term="derby"/><category term="embedded driver"/><category term="indexer"/><category term="java"/><category term="network security"/><category term="oops"/><category term="search engine"/><category term="sorting"/><category term="ubantu"/><title type='text'>CODING SIMPLIFIED</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://trycode.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>61</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-4837191621577495125</id><published>2020-04-04T09:02:00.001-07:00</published><updated>2020-04-04T09:02:20.739-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="class"/><category scheme="http://www.blogger.com/atom/ns#" term="oops"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type='text'>OOPS Python : Create Class</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;class Country():&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Class object Attribute&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; area = 3287000&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self,name,population):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.population = population&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.name=name&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def describe(self):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(&quot;population of {} is {}&quot;.format(self.name,self.population))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print(&quot;Area sq km of {} is {}&quot;.format(self.name,self.area)) also&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(&quot;Area sq km of {} is {}&quot;.format(self.name,Country.area))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def update_population(self,new_population):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.population = new_population&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;c1 = Country(&#39;India&#39;,1300000000)&lt;br /&gt;c1.update_population(1350000000)&lt;br /&gt;c1.describe()&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/4837191621577495125'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/4837191621577495125'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2020/04/oops-python-create-class.html' title='OOPS Python : Create Class'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-4720800833200239655</id><published>2020-04-02T09:04:00.001-07:00</published><updated>2020-04-02T09:04:52.376-07:00</updated><title type='text'>Theano prompts to install m2w64-toolchain to improve performance</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;WARNING (theano.configdefaults): g++ not available, if using conda: `conda install m2w64-toolchain`&lt;br /&gt;WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;Steps to Install in Anaconda:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;conda install msys2/m2w64-toolchain &lt;/li&gt;
&lt;li&gt;anaconda search -t conda msys2/m2w64-toolchain &lt;/li&gt;
&lt;li&gt;anaconda show msys2/m2w64-toolchain&lt;/li&gt;
&lt;li&gt;conda install --channel https://conda.anaconda.org/msys2 m2w64-toolchain&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/4720800833200239655'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/4720800833200239655'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2020/04/theano-prompts-to-install-m2w64.html' title='Theano prompts to install m2w64-toolchain to improve performance'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-5553938884167885514</id><published>2020-04-02T09:01:00.000-07:00</published><updated>2020-04-02T09:01:10.787-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="indexer"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="search engine"/><title type='text'>Indexer for search engine in python</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
import sys&lt;br /&gt;import os&lt;br /&gt;import urllib&lt;br /&gt;import re&lt;br /&gt;from bs4 import BeautifulSoup&lt;br /&gt;#first time&lt;br /&gt;#from whoosh.fields import Schema, TEXT, KEYWORD, ID, STORED ,NUMERIC&lt;br /&gt;#from whoosh.index import create_in, open_dir&lt;br /&gt;#from whoosh.query import *&lt;br /&gt;import whoosh.index as index&lt;br /&gt;ix = index.open_dir(&quot;index&quot;)&lt;br /&gt;#then onwards&lt;br /&gt;from whoosh.analysis.tokenizers import RegexTokenizer&lt;br /&gt;from whoosh.analysis.tokenizers import IDTokenizer&lt;br /&gt;#--------------------------------------------------------------------------------------&lt;br /&gt;#creating the schema&lt;br /&gt;schema = Schema(lid= TEXT(stored=True),ldata=TEXT(stored=True))&lt;br /&gt;#creating the index&lt;br /&gt;if not os.path.exists(&quot;index&quot;):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.mkdir(&quot;index&quot;)&lt;br /&gt;ix = create_in(&quot;index&quot;,schema)&lt;br /&gt;ix = open_dir(&quot;index&quot;)&lt;br /&gt;writer = ix.writer()&lt;br /&gt;#--------------------------------------------------------------------------------------&lt;br /&gt;soup = BeautifulSoup(open(&quot;39/390099&quot;))&lt;br /&gt;#tag = soup.find(&#39;title&#39;)&lt;br /&gt;#print(tag.text)&lt;br /&gt;#print(soup.prettify())&lt;br /&gt;#for link in soup.find_all(&#39;a&#39;):&lt;br /&gt;#&amp;nbsp;&amp;nbsp; print(link.get(&#39;href&#39;))&lt;br /&gt;#print(soup.get_text())&lt;br /&gt;text1=soup.get_text()&lt;br /&gt;text2=text1.split()&lt;br /&gt;&lt;br /&gt;def LowercaseFilter(tokens):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for t in tokens:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t.text = t.text.lower()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yield t&lt;br /&gt;&lt;br /&gt;regt = RegexTokenizer()&lt;br /&gt;idt = IDTokenizer()&lt;br /&gt;#-----------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;for token in regt(text1):&lt;br /&gt;&amp;nbsp;&amp;nbsp;
 
writer.add_document(lid=unicode(LowercaseFilter(token.text.encode(&#39;utf-8&#39;))),ldata=unicode(LowercaseFilter(token.text.encode(&#39;utf-8&#39;))))&lt;br /&gt;&amp;nbsp;&amp;nbsp; break&lt;br /&gt;&amp;nbsp;&amp;nbsp; #print unicode(token.text.encode(&#39;utf-8&#39;))&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;#length=len(words_list)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; #print unicode(token) , fdist1[token]&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; #print words_list[i]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#------------------------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;testVar=raw_input(&quot;enter a search keyword : &quot;)&lt;br /&gt;from whoosh.qparser import QueryParser&lt;br /&gt;ix.searcher().documents() &lt;br /&gt;with ix.searcher() as searcher:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #query = QueryParser(&quot;ldata&quot;, ix.schema).parse(u&#39;methylotrophus&#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; query = QueryParser(&quot;ldata&quot;, ix.schema).parse(testVar)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; results = searcher.search(query)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for result in results:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print result&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/5553938884167885514'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/5553938884167885514'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2020/04/indexer-for-search-engine-in-python.html' title='Indexer for search engine in python'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-3525494600376273875</id><published>2020-04-02T08:56:00.001-07:00</published><updated>2020-04-02T08:56:30.779-07:00</updated><title type='text'> are python strings mutable ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
No python strings are not mutable.&lt;br /&gt;
That means you cannot use indexing to change individual characters in a string in python.&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/3525494600376273875'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/3525494600376273875'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2020/04/are-python-strings-mutable.html' title=' are python strings mutable ?'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-6695176040790446550</id><published>2020-04-02T08:53:00.004-07:00</published><updated>2020-04-02T08:53:59.726-07:00</updated><title type='text'>pip install to a local folder , pip install from a local folder</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
pip install to a local folder&amp;nbsp; &lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;pip download --dest localpip/ --find-links localpip/ requests&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;pip install from a local folder&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;pip --find-links localpip/ numpy&lt;/span&gt;&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/6695176040790446550'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/6695176040790446550'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2020/04/pip-install-to-local-folder-pip-install.html' title='pip install to a local folder , pip install from a local folder'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-1699977628931895850</id><published>2020-04-02T08:51:00.001-07:00</published><updated>2020-04-02T08:51:53.209-07:00</updated><title type='text'>apt-get install to a folder of your choice</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;sudo apt-get install --download-only &#39;required-library&#39; -o Dir::Cache::archives=&#39;path to your folder&#39;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;example path = &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;&#39;/home/ubuntu/test/&#39;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;example required library =&amp;nbsp; numpy&amp;nbsp;&lt;/span&gt; &lt;/span&gt;&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/1699977628931895850'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/1699977628931895850'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2020/04/apt-get-install-to-folder-of-your-choice.html' title='apt-get install to a folder of your choice'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-7452967793812853324</id><published>2020-04-02T08:22:00.001-07:00</published><updated>2020-04-02T08:22:24.714-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="Strings"/><title type='text'>find all the substrings in a python string</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;def find_subs(s):&lt;br /&gt;&amp;nbsp; n = len(s)&lt;br /&gt;&amp;nbsp; return [s[i:j + 1] for i in range(n) for j in range(i,n)]&lt;/span&gt;&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/7452967793812853324'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/7452967793812853324'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2020/04/find-all-substrings-in-python-string.html' title='find all the substrings in a python string'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-1878219014530083768</id><published>2020-04-02T07:58:00.001-07:00</published><updated>2020-04-02T07:58:46.702-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="Fibonnaci"/><title type='text'>Fibonacci series starting with any two numbers</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;def multiply(F, M): &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x = (F[0][0] * M[0][0] + F[0][1] * M[1][0]) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; y = (F[0][0] * M[0][1] + F[0][1] * M[1][1]) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; z = (F[1][0] * M[0][0] + F[1][1] * M[1][0]) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; w = (F[1][0] * M[0][1] + F[1][1] * M[1][1]) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; F[0][0] = x &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; F[0][1] = y &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; F[1][0] = z &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; F[1][1] = w &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;def power(F, n): &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if( n == 0 or n == 1):return &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; M = [[0, 1],[1, 1]]&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; power(F, n // 2) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; multiply(F, F) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (n % 2 != 0): &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; multiply(F, M)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;&lt;br /&gt;def fib(a,b,n): &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; F = [[0, 1],[1, 1]] &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (n == 0): return a&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (n == 1): return b&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; power(F, n - 1) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return F[0][1]*a + F[1] [1]*b&lt;/span&gt;&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/1878219014530083768'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/1878219014530083768'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2020/04/fibonacci-series-starting-with-any-two.html' title='Fibonacci series starting with any two numbers'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-2019817814052678533</id><published>2020-04-02T07:52:00.001-07:00</published><updated>2020-04-02T07:52:12.684-07:00</updated><title type='text'>How to initialize dynamic variables</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Example 1: &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0Fm_G5zyhpUjjEAP2MPTWmJ7DEX8ykrBWKPE_zK9U-9K9PFHOqY_oTFKGKgA4QAmrMzkmuWSZdGVjBDjyvxh_FqBNGE8mjYOHGj7LlwahrWGbsD7IqZSp0AiWGHzL8p6xvGC1qkyc04M/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;239&quot; data-original-width=&quot;549&quot; height=&quot;276&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0Fm_G5zyhpUjjEAP2MPTWmJ7DEX8ykrBWKPE_zK9U-9K9PFHOqY_oTFKGKgA4QAmrMzkmuWSZdGVjBDjyvxh_FqBNGE8mjYOHGj7LlwahrWGbsD7IqZSp0AiWGHzL8p6xvGC1qkyc04M/s640/1.png&quot; width=&quot;640&quot; /&gt;&amp;nbsp;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
Example 2 :&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;pre class=&quot;lang-c prettyprint prettyprinted&quot;&gt;&lt;code&gt;&lt;span class=&quot;pln&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt; malloc&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;(len(char)*5)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/2019817814052678533'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/2019817814052678533'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2020/04/how-to-initialize-dynamic-variables.html' title='How to initialize dynamic variables'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0Fm_G5zyhpUjjEAP2MPTWmJ7DEX8ykrBWKPE_zK9U-9K9PFHOqY_oTFKGKgA4QAmrMzkmuWSZdGVjBDjyvxh_FqBNGE8mjYOHGj7LlwahrWGbsD7IqZSp0AiWGHzL8p6xvGC1qkyc04M/s72-c/1.png" height="72" width="72"/></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-1821378303088534895</id><published>2020-04-02T05:34:00.003-07:00</published><updated>2020-04-02T05:34:47.510-07:00</updated><title type='text'>Why lowercase variable is used other than uppercase?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Practically speaking variables should be allowed in any case, but just to follow convention in a particular domain we use certain format of words.&lt;br /&gt;For example Class-names usually start with&amp;nbsp; UPPERCASE and if you want to use same name for object it can be only possible by using lowercase.&lt;br /&gt;&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/1821378303088534895'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/1821378303088534895'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2020/04/why-lowercase-variable-is-used-other.html' title='Why lowercase variable is used other than uppercase?'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-1553618574006415880</id><published>2019-02-18T04:24:00.003-08:00</published><updated>2019-02-18T04:24:35.210-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="regex"/><title type='text'>python remove text from string after  character(s) without using regex</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;pre class=&quot;lang-py prettyprint prettyprinted&quot; style=&quot;background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow-wrap: normal; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;&quot;&gt;&lt;code style=&quot;border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, &amp;quot;Lucida Console&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Bitstream Vera Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;pivot &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;...&#39;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
required &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; text&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(pivot&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/1553618574006415880'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/1553618574006415880'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2019/02/python-remove-text-from-string-after.html' title='python remove text from string after  character(s) without using regex'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-5149670163029261409</id><published>2019-02-18T01:57:00.001-08:00</published><updated>2020-04-02T08:29:44.288-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="regex"/><title type='text'>regex to find datetime in text format</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;import re&lt;br /&gt;r = re.compile(&#39;(?P&amp;lt;dow&amp;gt;[a-zA-Z]+,) (?P&amp;lt;date&amp;gt;[0-9]{2}) (?P&amp;lt;month&amp;gt;[A-Za-z]+) (?P&amp;lt;year&amp;gt;[0-9]{4}) (?P&amp;lt;hour&amp;gt;[0-9]{2}):(?P&amp;lt;minute&amp;gt;[0-9]{2}) (?P&amp;lt;ampm&amp;gt;[A-Z]{2})&#39;)&lt;br /&gt;&lt;br /&gt;s = &quot;Monday, 14 January 2019 11:50 PM&quot;&lt;br /&gt;&lt;br /&gt;print([m.groupdict() for m in r.finditer(s)][0])&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;pre style=&quot;-webkit-text-stroke-width: 0px; background-color: white; border-radius: 0px; border: 0px; box-sizing: border-box; color: black; display: block; font-family: monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; line-height: inherit; margin: 0px; orphans: 2; overflow-wrap: break-word; overflow: auto; padding: 0px; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: pre-wrap; widows: 2; word-break: break-all; word-spacing: 0px;&quot;&gt;output :&lt;/pre&gt;
&lt;pre style=&quot;-webkit-text-stroke-width: 0px; background-color: white; border-radius: 0px; border: 0px; box-sizing: border-box; color: black; display: block; font-family: monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; line-height: inherit; margin: 0px; orphans: 2; overflow-wrap: break-word; overflow: auto; padding: 0px; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: pre-wrap; widows: 2; word-break: break-all; word-spacing: 0px;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre style=&quot;-webkit-text-stroke-width: 0px; background-color: white; border-radius: 0px; border: 0px; box-sizing: border-box; color: black; display: block; font-family: monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; line-height: inherit; margin: 0px; orphans: 2; overflow-wrap: break-word; overflow: auto; padding: 0px; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: pre-wrap; widows: 2; word-break: break-all; word-spacing: 0px;&quot;&gt;{&#39;dow&#39;: &#39;Monday,&#39;, &#39;date&#39;: &#39;14&#39;, &#39;month&#39;: &#39;January&#39;, &#39;year&#39;: &#39;2019&#39;, &#39;hour&#39;: &#39;11&#39;, &#39;minute&#39;: &#39;50&#39;, &#39;ampm&#39;: &#39;PM&#39;}&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/5149670163029261409'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/5149670163029261409'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2019/02/regex-to-find-datetime-in-text-format.html' title='regex to find datetime in text format'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-5942726483590845278</id><published>2016-12-14T05:34:00.001-08:00</published><updated>2016-12-14T05:47:59.338-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="algorithm"/><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="Divide and Conquer"/><title type='text'>Merge Sort in c++</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;pre&gt;#include&amp;lt;iostream&amp;gt;
#include&amp;lt;vector&amp;gt;
using namespace std;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;void merge(vector&amp;lt;int&amp;gt; &amp;amp;v,int l, int m,int r)
  {
&amp;nbsp;&amp;nbsp;&amp;nbsp; vector&amp;lt;int&amp;gt; a(v.begin()+l,v.begin()+m+1);
&amp;nbsp;&amp;nbsp;&amp;nbsp; vector&amp;lt;int&amp;gt; b(v.begin()+m+1,v.begin()+r+1);
&amp;nbsp;&amp;nbsp;&amp;nbsp; int ptr1=0,ptr2=0,ptr=l;
&amp;nbsp;&amp;nbsp;&amp;nbsp; while(ptr1&amp;lt;a.size() &amp;amp;&amp;amp; ptr2&amp;lt;b.size())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(a[ptr1]&amp;lt;b[ptr2])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v[ptr++]=a[ptr1++];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v[ptr++]=b[ptr2++];
&amp;nbsp;&amp;nbsp;&amp;nbsp; while(ptr1&amp;lt;a.size())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v[ptr++]=a[ptr1++];
&amp;nbsp;&amp;nbsp;&amp;nbsp; while(ptr2&amp;lt;b.size())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v[ptr++]=b[ptr2++];
  }

void mergesort(vector&amp;lt;int&amp;gt; &amp;amp;vec,int l,int r )
   {
&amp;nbsp;&amp;nbsp;&amp;nbsp;   if(l&amp;lt;r)
&amp;nbsp;&amp;nbsp;&amp;nbsp;    {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;    int m=(l+(r-1))/2;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;    mergesort(vec,l,m);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;    mergesort(vec,m+1,r);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;    merge(vec,l,m,r);
&amp;nbsp;&amp;nbsp;&amp;nbsp;    }
   }

int main()

  {

&amp;nbsp;&amp;nbsp;&amp;nbsp; int arr[] ={99,8,22,11,44,55,2,1,5,26,98,8,888,36,99,75,48,74,587,4};
&amp;nbsp;&amp;nbsp;&amp;nbsp; vector&amp;lt;int&amp;gt; vec(arr,arr+sizeof(arr)/sizeof(int));
&amp;nbsp;&amp;nbsp;&amp;nbsp; mergesort(vec,0,(vec.size())-1);
&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int i=0;i&amp;lt;vec.size();i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;vec[i]&amp;lt;&amp;lt;&quot; &quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;

  }
&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/5942726483590845278'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/5942726483590845278'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2016/12/merge-sort-in-c.html' title='Merge Sort in c++'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-5193401353640062781</id><published>2016-11-14T09:52:00.001-08:00</published><updated>2016-12-14T05:51:15.847-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="Data Structures"/><category scheme="http://www.blogger.com/atom/ns#" term="Implementation"/><category scheme="http://www.blogger.com/atom/ns#" term="Logic"/><title type='text'>C++ Program to print a 2-d matrix/vector in spiral order</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;pre&gt;vector&amp;lt;int&amp;gt; spiralOrder(const vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt; &amp;amp;A)

{

    vector&amp;lt;int&amp;gt; result;
    long min_x=0,min_y=0,done=0,count=0,i=0,j=0;
    long n,max_x=A[0].size()-1, m,max_y=A.size()-1;
    long size=(max_x+1)*(max_y+1);
    while(count&amp;lt;size)
        {  
            if(i==min_y &amp;amp;&amp;amp; j==min_x)
                {  if(done==1)
                       { min_x++;min_y++;max_x--;max_y--;i=min_y;j=min_x;  }
                    else done=1;
                }
            result.push_back(A[i][j]);
            count++;
            if(i==min_y &amp;amp;&amp;amp; j&amp;lt;max_x)        j++;
            else if(i==min_y &amp;amp;&amp;amp; j==max_x)  i++;
            else if(i&amp;lt;max_y &amp;amp;&amp;amp; j==max_x)   i++;
            else if(i==max_y &amp;amp;&amp;amp; j==max_x)  j--;
            else if(i==max_y &amp;amp;&amp;amp; j&amp;gt;min_x)   j--;
            else if(i==max_y &amp;amp;&amp;amp; j==min_x)  i--;
            else if(i&amp;gt;min_y &amp;amp;&amp;amp; j==min_x)   i--;
        }
    return result;
}&lt;int&gt;&lt;vector int=&quot;&quot;&gt;&lt;int&gt;&lt;size count=&quot;&quot; done=&quot;1;&quot; else=&quot;&quot; i=&quot;=max_y&quot; if=&quot;&quot; j--=&quot;&quot; j=&quot;&quot; max_x--=&quot;&quot; max_x=&quot;&quot; max_y--=&quot;&quot; max_y=&quot;&quot; min_x=&quot;&quot; min_y=&quot;&quot; result.push_back=&quot;&quot;&gt;
&lt;/size&gt;&lt;/int&gt;&lt;/vector&gt;&lt;/int&gt;&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/5193401353640062781'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/5193401353640062781'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2016/11/c-program-to-print-2-d-matrixvector-in.html' title='C++ Program to print a 2-d matrix/vector in spiral order'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-3106924103092994157</id><published>2016-06-26T04:31:00.004-07:00</published><updated>2016-06-26T04:32:55.223-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="algorithm"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="sorting"/><title type='text'>Python code for Quick Sort using original Hoare partition scheme</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
from random import randint&lt;br /&gt;
def quicksort(array, low, high):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; if low &amp;lt; high:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p = partition(array, low, high)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; quicksort(array, low, p)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; quicksort(array, p + 1, high)&lt;br /&gt;
&lt;br /&gt;
def partition(array, low, high):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; pivot = array[low]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; i=low-1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; j=high+1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; while 1:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; i = i + 1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; while array[i] &amp;lt; pivot:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = i + 1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; j=j-1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while array[j] &amp;gt; pivot:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; j=j-1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i &amp;gt;= j:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return j&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array[i],array[j]=array[j],array[i]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
array=[]&lt;br /&gt;
for p in range(10):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; array.append(randint(1,100))&lt;br /&gt;
&lt;br /&gt;
quicksort(array,0,len(array)-1)&lt;br /&gt;
print array&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/3106924103092994157'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/3106924103092994157'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2016/06/python-code-for-quick-sort-using.html' title='Python code for Quick Sort using original Hoare partition scheme'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-1625476412028252352</id><published>2016-03-20T08:18:00.000-07:00</published><updated>2016-03-20T08:18:24.154-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="algorithm"/><category scheme="http://www.blogger.com/atom/ns#" term="Artificial Intellignce"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type='text'>Implementation  of iterative deepening A* (Star) Algorithm</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
#node&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; current node&lt;br /&gt;#g&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; the cost to reach current node&lt;br /&gt;#f&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; estimated cost of the cheapest path (root..node..goal)&lt;br /&gt;#h(node)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; estimated cost of the cheapest path (node..goal)&lt;br /&gt;#cost(node, succ)&amp;nbsp; step cost function&lt;br /&gt;#is_goal(node)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; goal test&lt;br /&gt;#successors(node)&amp;nbsp; node expanding function&lt;br /&gt;V={}&lt;br /&gt;E={}&lt;br /&gt;V=({&#39;A&#39;:7,&#39;B&#39;:9,&#39;C&#39;:6,&#39;D&#39;:5,&#39;E&#39;:6,&#39;F&#39;:4.5,&#39;H&#39;:4,&#39;I&#39;:2,&#39;J&#39;:3,&#39;K&#39;:3.5,&#39;G&#39;:0})&lt;br /&gt;E=({(&#39;B&#39;,&#39;D&#39;):2,(&#39;A&#39;,&#39;B&#39;):4,(&#39;A&#39;,&#39;C&#39;):4,(&#39;A&#39;,&#39;D&#39;):7,(&#39;D&#39;,&#39;E&#39;):6,(&#39;E&#39;,&#39;F&#39;):5,(&#39;D&#39;,&#39;F&#39;):8,(&#39;D&#39;,&#39;H&#39;):5,(&#39;H&#39;,&#39;I&#39;):3,(&#39;I&#39;,&#39;J&#39;):3,(&#39;J&#39;,&#39;K&#39;):3,(&#39;K&#39;,&#39;H&#39;):3,(&#39;F&#39;,&#39;G&#39;):5})&lt;br /&gt;INFINITY=10000000&lt;br /&gt;cameFrom={}&lt;br /&gt;def h(node):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return V[node]&lt;br /&gt;def cost(node, succ):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return E[node,succ]&lt;br /&gt;&lt;br /&gt;def successors(node):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; neighbours=[]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for item in E:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if node==item[0][0]:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; neighbours.append(item[1][0])&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return neighbours&lt;br /&gt;&lt;br /&gt;def reconstruct_path(cameFrom, current):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; total_path = [current]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while current in cameFrom:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; current = cameFrom[current]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; total_path.append(current)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return total_path&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;def ida_star(root,goal):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; global cameFrom&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def search(node, g, bound):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; min_node=None&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; global cameFrom&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; f = g + h(node)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if f &amp;gt; bound:return f&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if node==goal:return &quot;FOUND&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; minn = INFINITY&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for succ in successors(node):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; t = search(succ, g + cost(node, succ), bound)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if t == &quot;FOUND&quot;:return &quot;FOUND&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if t &amp;lt; minn:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; minn = t&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; min_node=succ&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; cameFrom[min_node]=node&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return minn&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; bound= h(root)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count =1&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while 1:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; print &quot;itertion&quot;+str(count)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; count+=1&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; t = search(root, 0, bound)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if t == &quot;FOUND&quot;:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; print reconstruct_path(cameFrom, goal)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return bound&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if t == INFINITY:return &quot;NOT_FOUND&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; bound = t&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;print ida_star(&#39;A&#39;,&#39;G&#39;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/1625476412028252352'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/1625476412028252352'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2016/03/implementation-of-iterative-deepening.html' title='Implementation  of iterative deepening A* (Star) Algorithm'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-2885114230846110733</id><published>2016-03-18T18:10:00.000-07:00</published><updated>2016-03-18T19:36:39.863-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Artificial Intellignce"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type='text'>Implementation of A* algorithm in python</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
V={}&lt;br /&gt;
E={}&lt;br /&gt;
V=({&#39;A&#39;:7,&#39;B&#39;:9,&#39;C&#39;:6,&#39;D&#39;:5,&#39;E&#39;:6,&#39;F&#39;:4.5,&#39;H&#39;:4,&#39;I&#39;:2,&#39;J&#39;:3,&#39;K&#39;:3.5,&#39;G&#39;:0})&lt;br /&gt;
E=({(&#39;B&#39;,&#39;D&#39;):2,(&#39;A&#39;,&#39;B&#39;):4,(&#39;A&#39;,&#39;C&#39;):4,(&#39;A&#39;,&#39;D&#39;):7,(&#39;D&#39;,&#39;E&#39;):6,(&#39;E&#39;,&#39;F&#39;):4.5,(&#39;D&#39;,&#39;F&#39;):8,(&#39;D&#39;,&#39;H&#39;):4,(&#39;H&#39;,&#39;I&#39;):3,(&#39;I&#39;,&#39;J&#39;):3,(&#39;J&#39;,&#39;K&#39;):3,(&#39;K&#39;,&#39;H&#39;):3,(&#39;F&#39;,&#39;G&#39;):5})&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
INFINITY=10000000&lt;br /&gt;
def find_neighbours(node):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; neighbours=[]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for item in E:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if node==item[0][0]:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; neighbours.append(item[1][0])&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return neighbours&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def reconstruct_path(cameFrom, current):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; total_path = [current]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; while current in cameFrom:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; current = cameFrom[current]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; total_path.append(current)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return total_path&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; #&lt;br /&gt;
&lt;br /&gt;
def Astar(start, goal):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; current = start&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; fScore={}&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; gScore={}&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # The set of currently discovered nodes still to be evaluated.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; openSet = set()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # The set of nodes already evaluated.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; closedSet = set()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Initially, only the start node is known.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; openSet.add(current)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # For each node, which node it can most efficiently be reached from.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # If a node can be reached from many nodes, cameFrom will eventually contain the&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # most efficient previous step.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; cameFrom ={}#the empty map&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # For each node, the cost of getting from the start node to that node.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for node in V:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; gScore[node] = INFINITY #map with default value of Infinity&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # The cost of going from start to start is zero.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; gScore[start] = 0 &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # For each node, the total cost of getting from the start node to the goal&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # by passing by that node. That value is partly known, partly heuristic.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for node in V:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; fScore[node] = INFINITY #map with default value of Infinity&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # For the first node, that value is completely heuristic.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; fScore[start] = V[start]#heuristic_cost_estimate(start, goal)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def heuristic_cost_estimate(node, goal):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return E[cameFrom[node],node]+V[node]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; count=0&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; while openSet:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count+=1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if count&amp;gt;10:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; break&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; print openSet&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; minn=INFINITY&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for node in openSet:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if fScore[node]&amp;lt;minn:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; current=node&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if current==None:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; current=start&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #current = node in openSet having the lowest fScore[] value)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if current == goal:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return reconstruct_path(cameFrom, goal)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; openSet.remove(current)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Add it to the closed set&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; closedSet.add(current)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for neighbor in find_neighbours(current):&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if neighbor in closedSet:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; continue&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Ignore the neighbor which is already evaluated.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # The distance from start to goal passing through current and the neighbor.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tentative_gScore = gScore[current] + E[(current, neighbor)]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if neighbor not in openSet:&amp;nbsp;&amp;nbsp;&amp;nbsp; # Discover a new node&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; openSet.add(neighbor)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif tentative_gScore &amp;gt;= gScore[neighbor]:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; continue&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # This is not a better path.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # This path is the best until now. Record it!&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cameFrom[neighbor] = current&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gScore[neighbor] = tentative_gScore&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fScore[neighbor] = gScore[neighbor] + heuristic_cost_estimate(neighbor, goal)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return &quot;failure&quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
print Astar(&#39;A&#39;,&#39;K&#39;)&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/2885114230846110733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/2885114230846110733'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2016/03/implementation-of-algorithm-in-python.html' title='Implementation of A* algorithm in python'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-6422007895829743332</id><published>2015-12-08T05:55:00.000-08:00</published><updated>2015-12-08T05:55:32.423-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c"/><category scheme="http://www.blogger.com/atom/ns#" term="Strings"/><title type='text'>Read very large strings of UNKNOWN length</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
char buffer[10];&lt;br /&gt;
&amp;nbsp; &amp;nbsp; char *s = 0;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; size_t cur_len = 0;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; while (fgets(buffer, sizeof(buffer), stdin) != 0)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; size_t buf_len = strlen(buffer);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; char *extra = realloc(s, buf_len + cur_len + 1);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (extra == 0)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s = extra;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; strcpy(s + cur_len, buffer);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cur_len += buf_len;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/6422007895829743332'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/6422007895829743332'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2015/12/read-very-large-strings-of-unknown.html' title='Read very large strings of UNKNOWN length'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-2373402822630407213</id><published>2015-11-06T07:55:00.001-08:00</published><updated>2015-11-06T12:34:29.567-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="algorithm"/><category scheme="http://www.blogger.com/atom/ns#" term="c"/><category scheme="http://www.blogger.com/atom/ns#" term="Dynamic Data Structures"/><category scheme="http://www.blogger.com/atom/ns#" term="Graph Theory"/><title type='text'>Graph implementation using adjacency list</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
typedef struct node&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; int key;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; struct node * next;&lt;br /&gt;
}node;&lt;br /&gt;
typedef struct list&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; struct node * head;&lt;br /&gt;
}list;&lt;br /&gt;
typedef struct GRAPH&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; int V;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; struct list * array;&lt;br /&gt;
}GRAPH;&lt;br /&gt;
node * newnode(int k)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; node *n=(node *)malloc(1*sizeof(node));&lt;br /&gt;
&amp;nbsp; &amp;nbsp; n-&amp;gt;key=k;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; return n;&lt;br /&gt;
}&lt;br /&gt;
GRAPH *newgraph(GRAPH * g,int v)&lt;br /&gt;
{ &amp;nbsp; g=(GRAPH *)malloc(sizeof(GRAPH));&lt;br /&gt;
&amp;nbsp; &amp;nbsp; g-&amp;gt;V=v;int i;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; g-&amp;gt;array=(list *)malloc(v*sizeof(g-&amp;gt;array));&lt;br /&gt;
&amp;nbsp; &amp;nbsp; for(i=0;i&amp;lt;v;i++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;g-&amp;gt;array[i].head=NULL;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; return g;&lt;br /&gt;
}&lt;br /&gt;
void add_edge(GRAPH * g,int s , int t)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; node *n=newnode(t);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; n-&amp;gt;next=g-&amp;gt;array[s].head;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; g-&amp;gt;array[s].head=n;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; node *n2=newnode(s);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; n2-&amp;gt;next=g-&amp;gt;array[t].head;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; g-&amp;gt;array[t].head=n2;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void delete_edge(GRAPH * g,int s , int t)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;if(g-&amp;gt;array[s].head==NULL){printf(&quot;There is no edge between %d and %d \n&quot;, s , t);return;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; node * ptr1=g-&amp;gt;array[s].head;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; if(ptr1-&amp;gt;next==NULL)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {if(ptr1-&amp;gt;key==t){free(ptr1);ptr1=NULL;}return;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; if(ptr1-&amp;gt;key==t)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; { &amp;nbsp;g-&amp;gt;array[s].head=ptr1-&amp;gt;next;free(ptr1);return;}&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; node * ptr2=g-&amp;gt;array[s].head-&amp;gt;next;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; while(ptr2!=NULL)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(ptr2-&amp;gt;key!=t)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ptr1=ptr2;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ptr2=ptr2-&amp;gt;next;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else break;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp;if(ptr2!=NULL)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; if(ptr2-&amp;gt;key==t)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {ptr1-&amp;gt;next=ptr2-&amp;gt;next;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; free(ptr2);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; else printf(&quot;There is no edge between %d and %d \n&quot;, s , t);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; else&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;printf(&quot;There is no edge between %d and %d \n&quot;, s , t);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
void printgraph(GRAPH *g)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; int v,i;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; v=g-&amp;gt;V;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; for(i=0;i&amp;lt;v;i++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; { &amp;nbsp; node * ptr=g-&amp;gt;array[i].head; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;printf(&quot;%d-&amp;gt;&quot;,i);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; while(ptr!=NULL)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;%d-&amp;gt;&quot;,ptr-&amp;gt;key);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ptr=ptr-&amp;gt;next;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
void remove_edge(GRAPH *graph ,int a , int b)&lt;br /&gt;
{ &amp;nbsp; printf(&quot;deleting edge %d-%d \n&quot;,a,b);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; delete_edge(graph,a,b);delete_edge(graph,b,a);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{ &amp;nbsp; int size=5;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; GRAPH *graph=newgraph(graph,size);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; add_edge(graph,0,1);add_edge(graph,0,2);add_edge(graph,0,4);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; add_edge(graph,1,4);add_edge(graph,1,2);add_edge(graph,1,3);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; add_edge(graph,2,3);add_edge(graph,2,4);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; add_edge(graph,3,4);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; printgraph(graph);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; remove_edge(graph,2,3);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; remove_edge(graph,1,4);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; remove_edge(graph,1,3);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;printgraph(graph);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; printf(&quot;success\n&quot;);&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/2373402822630407213'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/2373402822630407213'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2015/11/graph-implementation-using-adjacency.html' title='Graph implementation using adjacency list'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-8672679012194512973</id><published>2015-10-13T11:14:00.002-07:00</published><updated>2015-10-13T11:14:34.620-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c"/><title type='text'>program to find the linearly dependent columns in multidimensional array</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
int i,j,k,m,n,len,col,a[9][9]={{2,3,6,5,1,2,3,6,9},{2,3,6,5,4,2,3,6,2},{2,3,6,5,4,2,3,1,9},{2,3,6,5,4,2,3,6,9},{2,3,6,5,4,2,3,6,9},&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{2,3,6,5,4,2,3,6,9},{2,3,6,5,4,3,3,6,9},{2,3,6,5,4,2,4,6,9},{2,3,6,5,8,2,3,6,9}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; };&lt;br /&gt;
&lt;br /&gt;
for(i=0;i&amp;lt;8;i++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; for(j=i+1;j&amp;lt;9;j++)&lt;br /&gt;
{ printf(&quot;here&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;if(a[0][i]%a[0][j]==0)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;{ &amp;nbsp;printf(&quot;here1&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;len=1;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;col=i;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for(k=1;k&amp;lt;9;k++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(a[k][i]%a[k][j]!=0)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;len=0;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;printf(&quot;here2&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;else if(a[0][j]%a[0][i]==0)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;{ &amp;nbsp; len=1;printf(&quot;here3&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;col=j;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for(k=1;k&amp;lt;9;k++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{ &amp;nbsp; len=1;printf(&quot;in55&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(a[k][j]%a[k][i]!=0)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;len=0;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;printf(&quot;in56&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;printf(&quot;here4&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;if(len==1)printf(&quot;\ncolumn : %d is linearly dependent&quot;,col);&lt;br /&gt;
}&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/8672679012194512973'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/8672679012194512973'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2015/10/program-to-find-linearly-dependent.html' title='program to find the linearly dependent columns in multidimensional array'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-7615966148449675511</id><published>2015-10-10T03:59:00.000-07:00</published><updated>2015-10-10T03:59:35.018-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="algorithm"/><category scheme="http://www.blogger.com/atom/ns#" term="c"/><category scheme="http://www.blogger.com/atom/ns#" term="Dynamic Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="String Matching"/><title type='text'>Implementation of longest common sub-sequence in c</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
int max(int a,int b){return (a&amp;gt;b)?a:b;}&lt;br /&gt;
char *x, *y;&lt;br /&gt;
int lcs(int i,int j)&lt;br /&gt;
&amp;nbsp;{&lt;br /&gt;
&amp;nbsp; if(i==0||j==0)return 0;&lt;br /&gt;
&amp;nbsp; else if(i&amp;gt;0&amp;amp;&amp;amp;j&amp;gt;0&amp;amp;&amp;amp;x[i]==y[j]) return lcs(i-1,j-1)+1;&lt;br /&gt;
&amp;nbsp; else if(i&amp;gt;0&amp;amp;&amp;amp;j&amp;gt;0&amp;amp;&amp;amp;x[i]!=y[j]) return max(lcs(i-1,j),lcs(i,j-1));&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{int n=10,m=5;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;x=(char *)malloc(n*sizeof(char ));&lt;br /&gt;
&amp;nbsp;y=(char *)malloc(m*sizeof(char ));&lt;br /&gt;
&amp;nbsp;gets(x);&lt;br /&gt;
&amp;nbsp;gets(y);&lt;br /&gt;
&amp;nbsp;//sizeof longest common subsequence among first n letters of x and first m letters of y&lt;br /&gt;
&amp;nbsp;printf(&quot;%d&quot;,lcs(n,m));&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/7615966148449675511'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/7615966148449675511'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2015/10/implementation-of-longest-common-sub.html' title='Implementation of longest common sub-sequence in c'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-4200603111214796845</id><published>2015-10-08T07:02:00.000-07:00</published><updated>2015-10-08T07:03:21.529-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c"/><category scheme="http://www.blogger.com/atom/ns#" term="Graph Theory"/><title type='text'>Represent graph with adjacency list : C program</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
typedef struct node{int key;struct node * next;}node;&lt;br /&gt;
node * init_node(node * n,int b){n=(node *)malloc(sizeof(node));n-&amp;gt;key=b;n-&amp;gt;next=NULL;return n;}&lt;br /&gt;
node **list,*front=NULL,*rear=NULL;&lt;br /&gt;
void enqueue(node * n)&lt;br /&gt;
{ if(rear==NULL)front=rear=n;&lt;br /&gt;
&amp;nbsp; else{ rear-&amp;gt;next=n;rear=n; } }&lt;br /&gt;
&lt;br /&gt;
void add_edge(int a,int b)&lt;br /&gt;
{ &amp;nbsp;node * ptr=NULL,*n=NULL;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;n=init_node(n,b);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; if(list[a]-&amp;gt;next==NULL){list[a]-&amp;gt;next=n;}&lt;br /&gt;
&amp;nbsp; else{ &amp;nbsp;ptr=list[a]; while(ptr-&amp;gt;next!=NULL)ptr=ptr-&amp;gt;next;ptr-&amp;gt;next=n;}&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{int n=4,i,j;node * ptr=NULL;&lt;br /&gt;
&amp;nbsp;list=(node **)malloc(n*(sizeof(node *)));&lt;br /&gt;
&lt;br /&gt;
for(i=0;i&amp;lt;n;i++)&lt;br /&gt;
{ &amp;nbsp;list[i]=(node *)malloc(n*(sizeof(node *)));list[i]-&amp;gt;next=NULL;list[i]-&amp;gt;key=i;}&lt;br /&gt;
&lt;br /&gt;
add_edge(0,3);add_edge(0,1);add_edge(1,3);&lt;br /&gt;
add_edge(2,0);add_edge(3,2);add_edge(2,1);&lt;br /&gt;
for(j=0;j&amp;lt;n;j++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; if(list[j]-&amp;gt;next!=NULL)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{ printf(&quot;[ %d ]&quot;,j);ptr=list[j]-&amp;gt;next;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;while(ptr!=NULL){printf(&quot;--&amp;gt; %d &quot;,ptr-&amp;gt;key);ptr=ptr-&amp;gt;next;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
printf(&quot;IN THE END......&quot;);&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/4200603111214796845'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/4200603111214796845'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2015/10/represent-graph-with-adjacency-list-c.html' title='Represent graph with adjacency list : C program'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-682359580889320712</id><published>2015-10-03T10:41:00.000-07:00</published><updated>2015-10-03T13:08:17.565-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="algorithm"/><category scheme="http://www.blogger.com/atom/ns#" term="c"/><category scheme="http://www.blogger.com/atom/ns#" term="String Matching"/><title type='text'>Program for String Matching with Finite Automata in C</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
char * prefix(char * c,int start, int end,int size)&lt;br /&gt;
{ &amp;nbsp; int i;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; char *temp=(char *)malloc(size*sizeof(char));&lt;br /&gt;
&amp;nbsp; &amp;nbsp; for(i=0;i&amp;lt;size;i++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;temp[i]=c[start++];&lt;br /&gt;
&amp;nbsp; &amp;nbsp; return temp;&lt;br /&gt;
}&lt;br /&gt;
char * suffix(char * c,int start, int end,int size)&lt;br /&gt;
{ &amp;nbsp; int i,j;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; char *temp=(char *)malloc(size*sizeof(char));&lt;br /&gt;
&amp;nbsp; &amp;nbsp; for(j=0,i=end-size+1;i&amp;lt;=end;i++,j++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;temp[j]=c[i];&lt;br /&gt;
&amp;nbsp; &amp;nbsp; return temp;&lt;br /&gt;
}&lt;br /&gt;
int match(char * a, char *b)&lt;br /&gt;
{ &amp;nbsp;int i=0;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; while(a[i]!=&#39;\0&#39;)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; if(a[i]!=b[i])&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;return 0;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; i++;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; return 1;&lt;br /&gt;
}&lt;br /&gt;
int sigma(char * t , char * p ,int i)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; int j,v=0;&lt;br /&gt;
&amp;nbsp; for(j=0;p[j]!=&#39;\0&#39;;j++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;if(match(suffix(t,0,i,j+1),prefix(p,0,j,j+1)))&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;v=j+1;&lt;br /&gt;
&amp;nbsp; return v;&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{ &amp;nbsp;char a[]=&quot;dfhghjgfjschhscgchgfbgfsgfjh&quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;char b[]=&quot;jhgfj&quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;printf(&quot;%d\n&quot;,sigma(a,b,8));&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
}&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/682359580889320712'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/682359580889320712'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2015/10/program-for-string-matching-with-finite.html' title='Program for String Matching with Finite Automata in C'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-412196199033531034</id><published>2015-10-02T13:52:00.000-07:00</published><updated>2015-10-02T14:02:10.620-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="algorithm"/><category scheme="http://www.blogger.com/atom/ns#" term="c"/><category scheme="http://www.blogger.com/atom/ns#" term="String Matching"/><title type='text'>Implmentation of Rabin-Karp Algorithm in c</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;#include&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;int hash (char * a,int s,int t)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;{ int h=0;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; for(;s&amp;lt;=t;s++)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; h+=a[s];&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return h;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;int match(char * a,int a1,int a2,char * b, int b1,int b2)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;{ &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; for(;a1&amp;lt;=a2,b1&amp;lt;=b2;a1++,b1++)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{ if(a[a1]!=b[b1])&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return 0;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return 1;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;} &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;void rk(char*a,char *b,int as,int bs)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;{&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp;int ph=hash(b,0,bs-1),i;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp;for(i=0;i&amp;lt;(as-bs+1);i++)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; { if(hash(a,i,i+bs-1)==ph)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(match(a,i,i+bs-1,b,0,bs-1))&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; { printf(&quot; &amp;nbsp;match for &amp;lt; %s &amp;gt; found at position : %d &quot;,b,i+1);}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;void main()&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;{ &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp;char t[]=&quot;abcdefghijklmnopqrstuvwxyz&quot;;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp;char p[]=&quot;klmnop&quot;;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; int st=sizeof(t)-1;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; int &amp;nbsp;sp=sizeof(p)-1;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; rk(t,p,st,sp);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/412196199033531034'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/412196199033531034'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2015/10/implmentation-of-rabin-karp-algorithm.html' title='Implmentation of Rabin-Karp Algorithm in c'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry><entry><id>tag:blogger.com,1999:blog-3113019092039994633.post-8806434239056896993</id><published>2015-09-29T06:27:00.002-07:00</published><updated>2015-09-29T06:27:49.429-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c"/><category scheme="http://www.blogger.com/atom/ns#" term="String Matching"/><title type='text'>Simple string matching algorithm to find position of a pattern in a given string without using any string function in C</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include&amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{ int i=0,j,count;&lt;br /&gt;
&amp;nbsp; char string[]={&quot;kfhisdcodesoecodeupzz&quot;};&lt;br /&gt;
&amp;nbsp; char pattern[]={&quot;code&quot;};&lt;br /&gt;
&amp;nbsp;&lt;br /&gt;
&amp;nbsp;&lt;br /&gt;
&amp;nbsp; for(i=0;i&amp;lt;sizeof(string)-1;i++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(string[i]==pattern[0])&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{ count =1;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for(j=1;j&amp;lt;sizeof(pattern)-1;j++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(pattern[j]==string[i+j])&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;count++;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else break;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(count==(sizeof(pattern)-1))&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;printf(&quot;\none match at position : %d &quot;,i);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
printf(&quot;\n&quot;);&lt;br /&gt;
}&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/8806434239056896993'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3113019092039994633/posts/default/8806434239056896993'/><link rel='alternate' type='text/html' href='http://trycode.blogspot.com/2015/09/simple-string-matching-algorithm-to.html' title='Simple string matching algorithm to find position of a pattern in a given string without using any string function in C'/><author><name>manish</name><uri>http://www.blogger.com/profile/16400043605802034362</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/-gWB-Apa7j6A/Ts2fA2Pa2aI/AAAAAAAABU4/cLgS3y28zE4/s220/111022-112147.jpg'/></author></entry></feed>