<?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-1270065828866707992</id><updated>2024-11-01T04:09:14.711-07:00</updated><category term="4 digit lock"/><category term="8-Queen Solution Backtacking Branch and Bound"/><category term="Bellman Ford Cpp STL implementation"/><category term="C++ STL dijkstra implementaion"/><category term="DAG CPP STL implementation"/><category term="Floyd Warshall CPP STL  implementaion"/><category term="Jhonson APSP Impmentation CPP STL"/><category term="google cheat search engine fake"/><category term="security"/><title type='text'>DumB-ShAre-ArtS</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ananyamallik.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://ananyamallik.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04197657759022166885</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>14</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1270065828866707992.post-8591510735546853860</id><published>2011-02-11T03:00:00.000-08:00</published><updated>2011-02-11T03:21:46.549-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="google cheat search engine fake"/><title type='text'>Is Google cheating on us</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
Just observed something.you type any query in google and search for it and google returns result very quicly and says&lt;br /&gt;
&amp;nbsp;About 4,850,000 results  (0.11 seconds)&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i55.tinypic.com/voloxl.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;358&quot; src=&quot;http://i55.tinypic.com/voloxl.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
You can see that result on page 2 starts with result number 10 i.e start=10 u can watch that in url above.&lt;br /&gt;
&lt;br /&gt;
Now when i change that start value to 500 i.e start=500 observe what happened&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;http://i51.tinypic.com/14csl1j.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;358&quot; src=&quot;http://i51.tinypic.com/14csl1j.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&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/AVvXsEiM7bEHu3AR4Q7qDyEApGY3HQIqdbh69Jjp473qFs1S15Rx67aRRpdlrqwaWYd_K692qnmBnZH9dnYTC79ugQjJs2PCn0T0izSo4210OzFYYfp1p7NRWvAnDrpo_NpBLSvIDd9TwVKH5No/s1600/2.jpeg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;
&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i52.tinypic.com/2zpim2c.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;
&lt;/a&gt;&lt;/div&gt;Number of result is reduced to 453 i.e&amp;nbsp; About 4,850,000 results  (0.11 seconds)&amp;nbsp; is now changed to page 47 of 453 result.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Again when i changed start value from 500 to 1000 google reviles its secrete &lt;br /&gt;
watch out:-&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i52.tinypic.com/ixdu39.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;358&quot; src=&quot;http://i52.tinypic.com/ixdu39.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i53.tinypic.com/1kmxh.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;
&lt;/a&gt;&lt;/div&gt;&lt;i&gt;&quot;Sorry, Google does not serve more than 1000 results for any query. (You asked for results starting from 1000.)&quot;&lt;/i&gt;&lt;br /&gt;
Then is message returned by google in first place that&amp;nbsp; &quot;&lt;i&gt;about 4,850,000 results&lt;/i&gt;&quot; found justified ?????&lt;br /&gt;
&lt;br /&gt;
Isn&#39;t  it a sort of cheating with its user, giving false  impression that it  is serving so fast for result set containing millions  of items in-spite  of fact that it is returning 1000 result at max for  any query ...&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;---Regards&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp; Sagar Sharma&lt;/b&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ananyamallik.blogspot.com/feeds/8591510735546853860/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ananyamallik.blogspot.com/2011/02/is-google-cheating-on-ius.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/8591510735546853860'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/8591510735546853860'/><link rel='alternate' type='text/html' href='http://ananyamallik.blogspot.com/2011/02/is-google-cheating-on-ius.html' title='Is Google cheating on us'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04197657759022166885</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://i55.tinypic.com/voloxl_th.jpg" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1270065828866707992.post-9100116622558721360</id><published>2010-11-28T04:42:00.000-08:00</published><updated>2011-03-31T06:55:26.787-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="4 digit lock"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><title type='text'>How to not secure urself ...</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Seen it somewhere so thought abt&amp;nbsp; posting it here ...&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&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/AVvXsEhT8EQEWIFhpZlkYwGXn68wDnMbUTfe55pWXiasF7ll5sufASZDjJUDLRahrPjOoZ8A4LORrM0ZZNxRTCQWUSRyqyQF7V8o7jx5W7EsfxXqyKJW7Ei1X_h9KVjJnKp8twiCOQJlyjs0agw/s1600/secfailsmall-273x300.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhT8EQEWIFhpZlkYwGXn68wDnMbUTfe55pWXiasF7ll5sufASZDjJUDLRahrPjOoZ8A4LORrM0ZZNxRTCQWUSRyqyQF7V8o7jx5W7EsfxXqyKJW7Ei1X_h9KVjJnKp8twiCOQJlyjs0agw/s400/secfailsmall-273x300.jpg&quot; width=&quot;364&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
See n observer how much difficult is it to crack this 4 digit door lock code.. :D&lt;br /&gt;
with this lock someone secured his assets ... i m genuinely concerned if insurance company will pay for loss of his assets....well as a insurence inspector i must nt ..&lt;br /&gt;
wat say fellas ...&lt;br /&gt;
For more info on security issues goto :-&amp;nbsp;&lt;a href=&quot;http://securityresearch.in/beta/&quot;&gt;http://securityresearch.in/&lt;/a&gt; &lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ananyamallik.blogspot.com/feeds/9100116622558721360/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ananyamallik.blogspot.com/2010/11/how-to-not-secure-urself.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/9100116622558721360'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/9100116622558721360'/><link rel='alternate' type='text/html' href='http://ananyamallik.blogspot.com/2010/11/how-to-not-secure-urself.html' title='How to not secure urself ...'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04197657759022166885</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhT8EQEWIFhpZlkYwGXn68wDnMbUTfe55pWXiasF7ll5sufASZDjJUDLRahrPjOoZ8A4LORrM0ZZNxRTCQWUSRyqyQF7V8o7jx5W7EsfxXqyKJW7Ei1X_h9KVjJnKp8twiCOQJlyjs0agw/s72-c/secfailsmall-273x300.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1270065828866707992.post-8344841893676701725</id><published>2010-11-17T07:00:00.000-08:00</published><updated>2011-03-31T06:56:06.124-07:00</updated><title type='text'>ARP poisoning attack and countermeasure (MAN IN THE MIDDLE ATTACK) MITM</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;One of the active evesdropping attack in current scenario used against individual and organisational is &lt;i&gt;MAN-IN-THE-MIDDLE&lt;/i&gt; often know as &lt;i&gt;MITM&lt;/i&gt; attack.It is basically exploits the &lt;i&gt;ARP&lt;/i&gt;(Address Resolution Protocol).This attack is categorized as Layer 2 attack ,i.e it works on layer -2(MAC Sublayer) of TCP/IP model most of u must be knowing.&lt;br /&gt;
&lt;br /&gt;
MITM attack include: apr poisioning , DNS spoofing , http session hijaking&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ARP&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This protocol is made to facilitate layer-2(MAC) to layer-3(IP) address transaltion.APR is based on 2 packats ARP_REQUEST and ARP_RESPONSE&lt;br /&gt;
&lt;br /&gt;
Aim of these 2 packats are to locate the hardware address associated with the provided IP-address.&lt;br /&gt;
&lt;br /&gt;
ARP_REQUEST is like it says my IP is AA.AA.AA.AA ,and my MAC address is &lt;br /&gt;
AA:AA:AA:AA:AA:AA i want to send some data to destination whose IP is BB.BB.BB.BB i don&#39;t know the Hardware address pls tell me.depicted in pic given and similarly &lt;i&gt;ARP_RESPONSE&lt;/i&gt; packet is generated answering the requested question.Once this transmission is over the transmitting device updates its &lt;u&gt;&lt;i&gt;ARP_CACHE_TABLE&lt;/i&gt;&lt;/u&gt;,and then the communication starts.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i55.tinypic.com/2nlvk7b.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;283&quot; src=&quot;http://i55.tinypic.com/2nlvk7b.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ARP POISIONING &lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
ARP is insecured protocol,devices using &lt;i&gt;ARP&lt;/i&gt; can take update at any time.This means that any host in network can reply with &lt;i&gt;ARP_REPLY&lt;/i&gt; and force the another host to update its &lt;i&gt;ARP_CACHE&amp;nbsp; &lt;/i&gt;with new poisoned value.&lt;br /&gt;
&lt;br /&gt;
This feature of ARP can be used in malicious manner that user thinks that it is communicating with intended user in spite of fact actually it is communicating with attacker.&lt;br /&gt;
&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;http://i53.tinypic.com/aw9nnm.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://i53.tinypic.com/aw9nnm.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Now i m gonna show you the demonstration for ARP_POSIONING. For recreating by demonstration u need&amp;nbsp; &lt;br /&gt;
1)unix OS&lt;br /&gt;
2)ettrecap utility&lt;br /&gt;
&lt;br /&gt;
there are many pluginswhich are provided by&amp;nbsp; ettrecap.&lt;br /&gt;
that u can find using&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;$man ettrecap&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
use the command given below to start arp posoning n listening to private data,poior to that be sure to be in superuser mode .&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;#&lt;/b&gt;&lt;b&gt;ettercap -T -q -M arp:remote -i etho -P repoison_arp // //&lt;/b&gt;&lt;br /&gt;
&lt;b&gt; &lt;/b&gt;&lt;br /&gt;
above command will scan all the host in ur subnet and will poison dere &lt;i&gt;arp_cache.&lt;/i&gt;&lt;br /&gt;
&lt;b&gt;-T&lt;/b&gt;&lt;i&gt;&amp;nbsp; --&lt;/i&gt; this cap is for running ettrecap in text mode&lt;br /&gt;
&lt;b&gt;-q&lt;/b&gt;&amp;nbsp; -- this cap is for showing only usufull information not the entire packet&lt;br /&gt;
&lt;b&gt;-M&lt;/b&gt; -- this cap is for starting MITM attack&lt;br /&gt;
&lt;b&gt;-i&amp;nbsp;&amp;nbsp; &lt;/b&gt;--this cap is for selection of netwrok interface on which MITM will work&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; it can be eth0 or wlan0 or watever interface u are interested in&lt;br /&gt;
&lt;b&gt;-P&lt;/b&gt; -- this is for using the plugin provided by the utility&lt;br /&gt;
&lt;b&gt;// //&lt;/b&gt; --it is there for selecting the user range within subnet default is whole&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; subnet&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After executing this command u&#39;ll get the private data of users within subnet .&lt;br /&gt;
above tutorial was intended entirely for purpose of understanding.pls don&#39;t use them for malacious purpose .&lt;br /&gt;
&lt;br /&gt;
it&#39;s awl for nw&lt;br /&gt;
&lt;br /&gt;
For more info goto :-&amp;nbsp;&lt;a href=&quot;http://securityresearch.in/beta/&quot;&gt;http://securityresearch.in/&lt;/a&gt;&lt;br /&gt;
Next post will be about &lt;b&gt;DNS_SPOOFING&lt;/b&gt; till then tadasssssssss..&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ananyamallik.blogspot.com/feeds/8344841893676701725/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ananyamallik.blogspot.com/2010/11/arp-poisoning-attack-and-countermeasure.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/8344841893676701725'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/8344841893676701725'/><link rel='alternate' type='text/html' href='http://ananyamallik.blogspot.com/2010/11/arp-poisoning-attack-and-countermeasure.html' title='ARP poisoning attack and countermeasure (MAN IN THE MIDDLE ATTACK) MITM'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04197657759022166885</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://i55.tinypic.com/2nlvk7b_th.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1270065828866707992.post-3742522226586200309</id><published>2010-10-31T10:09:00.000-07:00</published><updated>2010-10-31T10:09:00.946-07:00</updated><title type='text'>How to program for IP - resolver against a host-name</title><content type='html'>For this matter u need to have some&amp;nbsp;prerequisite&amp;nbsp;:-&lt;br /&gt;
1)Knowledge of C language&lt;br /&gt;
2)Unix based system on ur Box&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now here we go is the code for resolving the IP address from given hostnames:&lt;br /&gt;
given program in line no 40 gets the address info with help of getaddrinfo( ) function line no. 46 to 61 prints the Ip addresses. Loop from 46 to 61 is for the case if server is having multiple Ip&#39;s .User can give n numbers of hostname and corresponding IP&#39;ll be resolved.&lt;br /&gt;
Explanation of program is described just after the program .&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(204, 204, 204); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: dashed; border-top-width: 1px; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 450px;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  //   Ipresolver.c  
2:  //     
3:  //   Copyright 2010 ananya &amp;lt;ananya@kgeek-laptop&amp;gt;   
4:  //     
5:  //   This program is free software; you can redistribute it and/or modify  
6:  //   it under the terms of the GNU General Public License as published by  
7:  //   the Free Software Foundation; either version 2 of the License, or  
8:  //   (at your option) any later version.  
9:  //     
10:  //   This program is distributed in the hope that it will be useful,  
11:  //   but WITHOUT ANY WARRANTY; without even the implied warranty of  
12:  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
13:  //   GNU General Public License for more details.  
14:  //     
15:  //   You should have received a copy of the GNU General Public License  
16:  //   along with this program; if not, write to the Free Software  
17:  //   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,  
18:  //   MA 02110-1301, USA.  
19:  #include &amp;lt;stdio.h&amp;gt;  
20:  #include &amp;lt;string.h&amp;gt;  
21:  #include &amp;lt;sys/types.h&amp;gt;  
22:  #include &amp;lt;sys/socket.h&amp;gt;  
23:  #include &amp;lt;netdb.h&amp;gt;  
24:  #include &amp;lt;arpa/inet.h&amp;gt;  
25:  int main(int argc, char *argv[])  
26:  {  
27:    struct addrinfo hints, *res, *p;  
28:    int status,i;  
29:    char ipstr[INET6_ADDRSTRLEN];  
30:    if (argc == 1) {  
31:      fprintf(stderr,&quot;usage: showip hostname[n]\n&quot;);  
32:      return 1;  
33:    }  
34:   for(i=1;i&amp;lt;argc;i++)  
35:   {  
36:    printf(&quot;************************************************\n&quot;);  
37:    memset(&amp;amp;hints, 0, sizeof hints);  
38:    hints.ai_family = AF_UNSPEC;   
39:    hints.ai_socktype = SOCK_STREAM;  
40:    if ((status = getaddrinfo(argv[i], NULL, &amp;amp;hints, &amp;amp;res)) != 0) {      //getaddrinfo() call goes here   
41:      fprintf(stderr, &quot;getaddrinfo: %s\n&quot;, gai_strerror(status));      //Ip and other info regarding hostname is stored in struct addrinfo res     
42:      return 2;  
43:    }  
44:    //printf(&quot;%d\n&quot;,status);  
45:    printf(&quot;IP addresses for %s:\n\n&quot;, argv[i]);  
46:    for(p = res;p != NULL; p = p-&amp;gt;ai_next) {                  //Loop goes for different Ips if hostname has multiple Ip&#39;s  
47:      void *addr;  
48:      //in_port_t port;  
49:      char *ipver;  
50:      if (p-&amp;gt;ai_family == AF_INET) {                    //If it is IPv4  
51:        struct sockaddr_in *ipv4 = (struct sockaddr_in *)p-&amp;gt;ai_addr;     
52:        addr = &amp;amp;(ipv4-&amp;gt;sin_addr);                     //Extracting Ip address in binary format   
53:        //port=ipv4-&amp;gt;sin_port;  
54:        ipver = &quot;IPv4&quot;;                            
55:      } else {                               //If it is IPv6                
56:        struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p-&amp;gt;ai_addr;    
57:        addr = &amp;amp;(ipv6-&amp;gt;sin6_addr);  
58:        ipver = &quot;IPv6&quot;;  
59:      }  
60:      inet_ntop(p-&amp;gt;ai_family, addr, ipstr, sizeof ipstr);          //convert binary Ip notation in text i.e dotted decimal form  
61:      printf(&quot; %s: %s \n&quot;, ipver, ipstr);  
62:    }  
63:  }  
64:    freeaddrinfo(res);   
65:    return 0;  
66:  }  &lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
Compiling Info:-&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(204, 204, 204); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: dashed; border-top-width: 1px; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 450px;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;$ gcc IPresolver.c -o Ipresolver.o  &lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(204, 204, 204); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: dashed; border-top-width: 1px; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 450px;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;$ ./Ipresolver.o www.nitk.ac.in www.google.com www.slashdot.org&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
Corresponding Output:-&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: rgb(204, 204, 204); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: dashed; border-top-width: 1px; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 450px;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; ************************************************  
 IP addresses for www.nitk.ac.in:  
  IPv4: 210.212.194.8   
 ************************************************  
 IP addresses for www.google.com:  
  IPv4: 72.14.213.105   
  IPv4: 72.14.213.106   
  IPv4: 72.14.213.147   
  IPv4: 72.14.213.99   
  IPv4: 72.14.213.103   
  IPv4: 72.14.213.104   
 ************************************************  
 IP addresses for www.slashdot.org:  
  IPv4: 216.34.181.48   &lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;div&gt;so here we go:-&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Socket Descriptor it is of type int.&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background-origin: initial; border-bottom-color: rgb(204, 204, 204); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: dashed; border-top-width: 1px; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 450px;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:   struct addrinfo {  
2:          int       ai_flags;              // AI_PASSIVE, AI_CANONNAME, etc.  
3:          int       ai_family;             //AF_INET (IPv_4),AF_INET6 (IPV_6)  
4:          int       ai_socktype;          //SOCK_STREAM,SOCK_DGRM  
5:          int       ai_protocol;           //Usually &quot;0&quot;  
6:          size_t     ai_addrlen;           // size of ai_addr in bytes   
7:          struct sockaddr *ai_addr;         //struct sockaddr_in or _in6          
8:          char      *ai_canonname;       //full canonical hostname  
9:          struct addrinfo *ai_next;          //next node in lineked list  
10:        };  &lt;/code&gt;&lt;/pre&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;u can even get this struct info using konsole command :-&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background-origin: initial; border-bottom-color: rgb(204, 204, 204); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: dashed; border-top-width: 1px; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 450px;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;$ man getaddrinfo  &lt;/code&gt;&lt;/pre&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background-origin: initial; border-bottom-color: rgb(204, 204, 204); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: dashed; border-top-width: 1px; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 450px;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  struct sockaddr {  
2:          sa_family_t sa_family;  
3:          char    sa_data[14];  
4:        }  &lt;/code&gt;&lt;/pre&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;the only purpose of above is to cast the structure pointer passed in addr in order to avoid compiler warnings.&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;u can even get this struct info using konsole command :-&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background-origin: initial; border-bottom-color: rgb(204, 204, 204); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: dashed; border-top-width: 1px; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 450px;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;$ man bind  &lt;/code&gt;&lt;/pre&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;To deal with&amp;nbsp;&lt;nobr&gt;&lt;tt class=&quot;type&quot;&gt;struct sockaddr&lt;/tt&gt;&lt;/nobr&gt;, programmers created a parallel structure:&amp;nbsp;&lt;a href=&quot;&quot; name=&quot;indexId434909-72&quot;&gt;&lt;/a&gt;&lt;nobr&gt;&lt;tt class=&quot;type&quot;&gt;struct sockaddr_in&lt;/tt&gt;&lt;/nobr&gt;&amp;nbsp;(&quot;in&quot; for &quot;Internet&quot;) to be used with IPv4. and sockaddr_in6 for IPv6&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Structure sockaddr_in6&lt;/div&gt;&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background-origin: initial; border-bottom-color: rgb(204, 204, 204); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: dashed; border-top-width: 1px; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 450px;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  struct sockaddr_in6 {  
2:          sa_family_t   sin6_family;  /* AF_INET6 */  
3:          in_port_t    sin6_port;   /* port number */  
4:          uint32_t    sin6_flowinfo; /* IPv6 flow information */  
5:          struct in6_addr sin6_addr;   /* IPv6 address */  
6:          uint32_t    sin6_scope_id; /* Scope ID (new in 2.4) */  
7:        };  
8:        struct in6_addr {  
9:          unsigned char  s6_addr[16];  /* IPv6 address */  
10:        };  &lt;/code&gt;&lt;/pre&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;u can even get this struct info using konsole command :-&lt;/div&gt;&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background-origin: initial; border-bottom-color: rgb(204, 204, 204); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: dashed; border-top-width: 1px; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 450px;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;$ man ipv6   &lt;/code&gt;&lt;/pre&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;similarly struct sockaddr_in for IPv4 cab b viewed .&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;First, let&#39;s say you have a&amp;nbsp;&lt;nobr&gt;&lt;tt class=&quot;type&quot;&gt;struct sockaddr_in ina&lt;/tt&gt;&lt;/nobr&gt;, and you have an IP address &quot;&lt;tt class=&quot;tt&quot;&gt;192.168.0.48&lt;/tt&gt;&quot; or &quot;&lt;tt class=&quot;tt&quot;&gt;2001:db8:63b3:1::3490&lt;/tt&gt;&quot; that you want to store into it. The function you want to use,&amp;nbsp;&lt;a href=&quot;&quot; name=&quot;indexId434909-77&quot;&gt;&lt;/a&gt;&lt;b&gt;&lt;tt class=&quot;func&quot;&gt;inet_pton()&lt;/tt&gt;&lt;/b&gt;, converts an IP address in numbers-and-dots notation into either a&amp;nbsp;&lt;nobr&gt;&lt;tt class=&quot;type&quot;&gt;struct in_addr&lt;/tt&gt;&lt;/nobr&gt;&amp;nbsp;or a&lt;nobr&gt;&lt;tt class=&quot;type&quot;&gt;struct in6_addr&lt;/tt&gt;&lt;/nobr&gt;&amp;nbsp;depending on whether you specify&amp;nbsp;&lt;tt class=&quot;const&quot;&gt;AF_INET&lt;/tt&gt;&amp;nbsp;or&amp;nbsp;&lt;tt class=&quot;const&quot;&gt;AF_INET6&lt;/tt&gt;. (&quot;pton&quot; stands for &quot;presentation to network&quot;—you can call it &quot;printable to network&quot; if that&#39;s easier to remember.) The conversion can be made as follows:&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background-origin: initial; border-bottom-color: rgb(204, 204, 204); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: dashed; border-top-width: 1px; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 450px;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  inet_pton(AF_INET, &quot;192.168.0.48&quot;, &amp;amp;(sa.sin_addr)); // IPv4  
2:  inet_pton(AF_INET6, &quot;2001:db8:63b3:1::3490&quot;, &amp;amp;(sa6.sin6_addr)); // IPv6 &lt;/code&gt;&lt;/pre&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;u can get infomation about&amp;nbsp;&lt;i&gt;inet_pton()&amp;nbsp;&lt;/i&gt;using following command in konsole:-&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background-origin: initial; border-bottom-color: rgb(204, 204, 204); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: dashed; border-top-width: 1px; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 450px;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;$ man inet_pton  &lt;/code&gt;&lt;/pre&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 19px; font-weight: bold;&quot;&gt;&lt;b&gt;&lt;tt class=&quot;titlefunc&quot;&gt;getaddrinfo()&lt;/tt&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;It used to be that you would use a function called&amp;nbsp;&lt;b&gt;&lt;tt class=&quot;func&quot;&gt;gethostbyname()&lt;/tt&gt;&lt;/b&gt;&amp;nbsp;to do DNS lookups. Then you&#39;d load that information by hand into a&amp;nbsp;&lt;nobr&gt;&lt;tt class=&quot;type&quot;&gt;struct sockaddr_in&lt;/tt&gt;&lt;/nobr&gt;, and use that in your calls.&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;In these modern times, you now have the function&amp;nbsp;&lt;b&gt;&lt;tt class=&quot;func&quot;&gt;getaddrinfo()&lt;/tt&gt;&lt;/b&gt;&amp;nbsp;that does all kinds of good stuff for you, including DNS and service name lookups, and fills out the&amp;nbsp;&lt;nobr&gt;&lt;tt class=&quot;type&quot;&gt;struct&lt;/tt&gt;&lt;/nobr&gt;s you need, besides!&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background-origin: initial; border-bottom-color: rgb(204, 204, 204); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: dashed; border-top-width: 1px; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 450px;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:   #include &amp;lt;sys/types.h&amp;gt;  
2:   #include &amp;lt;sys/socket.h&amp;gt;  
3:   #include &amp;lt;netdb.h&amp;gt;  
4:   int getaddrinfo(const char *node, const char *service,  
5:              const struct addrinfo *hints,  
6:              struct addrinfo **res);  
7:   void freeaddrinfo(struct addrinfo *res);  
8:   const char *gai_strerror(int errcode);  &lt;/code&gt;&lt;/pre&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;U can get hell lot of information about this function using konsole command:&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #333333; font-family: Verdana, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre style=&quot;background-attachment: initial; background-clip: initial; background-color: #f0f0f0; background-image: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background-origin: initial; border-bottom-color: rgb(204, 204, 204); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: dashed; border-top-width: 1px; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 450px;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;$ man getaddrinfo  &lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Enjoy Rest in peace&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ananyamallik.blogspot.com/feeds/3742522226586200309/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ananyamallik.blogspot.com/2010/10/how-to-program-for-ip-resolver-against.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/3742522226586200309'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/3742522226586200309'/><link rel='alternate' type='text/html' href='http://ananyamallik.blogspot.com/2010/10/how-to-program-for-ip-resolver-against.html' title='How to program for IP - resolver against a host-name'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04197657759022166885</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1270065828866707992.post-68325088782154175</id><published>2010-10-25T15:20:00.000-07:00</published><updated>2011-02-06T04:13:32.388-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="8-Queen Solution Backtacking Branch and Bound"/><title type='text'>Solution of 8-Queen Problem</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Definition of problem :- Here&amp;nbsp;is&amp;nbsp;a&amp;nbsp;very&amp;nbsp;famous&amp;nbsp;problem.&amp;nbsp;How&amp;nbsp;many&amp;nbsp;ways&amp;nbsp;are&amp;nbsp;there&amp;nbsp;to&amp;nbsp;place&amp;nbsp;8&amp;nbsp;queens&amp;nbsp;on&amp;nbsp;a&amp;nbsp;chess&amp;nbsp;board so&amp;nbsp;that&lt;br /&gt;
no&amp;nbsp;two&amp;nbsp;queens&amp;nbsp;attack&amp;nbsp;each&amp;nbsp;other?&amp;nbsp;A&amp;nbsp;chess&amp;nbsp;board&amp;nbsp;is&amp;nbsp;an&amp;nbsp;8x8&amp;nbsp;grid.&amp;nbsp;Queens&amp;nbsp;can&amp;nbsp;be&amp;nbsp;placed&amp;nbsp;in&amp;nbsp;the&amp;nbsp;cells&amp;nbsp;f&lt;br /&gt;
the&amp;nbsp;grid.&amp;nbsp;Two&amp;nbsp;queens&amp;nbsp;are&amp;nbsp;under&amp;nbsp;mutual&amp;nbsp;attack&amp;nbsp;if&amp;nbsp;they&amp;nbsp;share&amp;nbsp;a&amp;nbsp;row,&amp;nbsp;a&amp;nbsp;column&amp;nbsp;or&amp;nbsp;a&amp;nbsp;diagonal.&amp;nbsp;Here&amp;nbsp;is&amp;nbsp;one&lt;br /&gt;
possible&amp;nbsp;solution:&lt;br /&gt;
We have to endure 4-things&lt;br /&gt;
1)No 2 Queens share same Column&lt;br /&gt;
2)No 2 Queens share same Row&lt;br /&gt;
3)No 2 Queens share / diagonal&lt;br /&gt;
4)No 2 Queens share \ diagonal&lt;br /&gt;
No. 1 is automatic because the way we store solution&lt;br /&gt;
No. 2 is done with used array&lt;br /&gt;
for 3 and 4 we do same thing we keep two array of size 15 to keep track which diagonals are occupied.,Consider the following trick.If we take a cell with coordinate (r,c) what are the values of (r+c) and (r+c-7) (indexing is from 0-7).&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i52.tinypic.com/2vbtq3s.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;272&quot; src=&quot;http://i52.tinypic.com/2vbtq3s.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Let&#39;s call (r+c) the &quot;Slash Code&quot; of cell and (r-c+7) the &quot;Backslash Code&quot; .Then two queen which share a / diagonal has same &quot;Slash code&quot; and those who share a \ diagonal has same &quot;Backslash Code&quot; .&lt;br /&gt;
&lt;br /&gt;
Solution O/P :-&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/AVvXsEg4BZL792W690utoT75j0NqteEldxkZhIPiszGHfain-ml52OhU0v_XHau1gOWAil40YPQsq8HcwQEYFCysArjb19c_qMgdKppvgJua_0tIDP7hQHna2VQaPfbXIE2gFidmeE1WV-FWbDg/s1600/nqueen.jpeg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;443&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4BZL792W690utoT75j0NqteEldxkZhIPiszGHfain-ml52OhU0v_XHau1gOWAil40YPQsq8HcwQEYFCysArjb19c_qMgdKppvgJua_0tIDP7hQHna2VQaPfbXIE2gFidmeE1WV-FWbDg/s640/nqueen.jpeg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
For more info goto : http://securityresearch.in/beta&lt;br /&gt;
Code :- &lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  //   8_queen.cpp  
2:  //     
3:  //   Copyright 2010 ananya &amp;lt;ananya@ananya-laptop&amp;gt;  
4:  //     
5:  //   This program is free software; you can redistribute it and/or modify  
6:  //   it under the terms of the GNU General Public License as published by  
7:  //   the Free Software Foundation; either version 2 of the License, or  
8:  //   (at your option) any later version.  
9:  //     
10:  //   This program is distributed in the hope that it will be useful,  
11:  //   but WITHOUT ANY WARRANTY; without even the implied warranty of  
12:  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
13:  //   GNU General Public License for more details.  
14:  //     
15:  //   You should have received a copy of the GNU General Public License  
16:  //   along with this program; if not, write to the Free Software  
17:  //   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,  
18:  //   MA 02110-1301, USA.  
19:  #include &amp;lt;iostream&amp;gt;  
20:  #include &amp;lt;vector&amp;gt;  
21:  using namespace std;  
22:  vector&amp;lt;int&amp;gt; row(8),used(8),slash(15),backSlash(15);  
23:  int total;  
24:  int queen(int i)  
25:  {  
26:       if(i==8)  
27:       {  
28:            return 1;  
29:       }  
30:       for(row[i]=0;row[i]&amp;lt;8;row[i]++)  
31:       {  
32:            if(used[row[i]]==1 || slash[row[i]+i]==1 || backSlash[row[i]-i+7]==1)  
33:                 continue;  
34:            used[row[i]]=1;  
35:            slash[row[i]+i]=1 ;  
36:            backSlash[row[i]-i+7]=1;  
37:            total=queen(i+1);  
38:            if (total==1)  
39:              return 1;  
40:            used[row[i]]=0;  
41:            slash[row[i]+i]=0 ;  
42:            backSlash[row[i]-i+7]=0;  
43:       }  
44:       return total;  
45:  }   
46:  int main(int argc, char** argv)  
47:  {  
48:       for(int i=0;i&amp;lt;8;i++)  
49:       {  
50:            row[i]=0;  
51:            used[i]=0;  
52:       }  
53:       for(int i=0;i&amp;lt;15;i++)  
54:       {  
55:            slash[i]=0;  
56:            backSlash[i]=0;  
57:       }  
58:       int k=queen(0);  
59:       k++;  
60:       /*for(int i=0;i&amp;lt;8;i++)  
61:       {  
62:            cout&amp;lt;&amp;lt;row[i]&amp;lt;&amp;lt;endl;  
63:       }*/  
64:    for(k=0;k&amp;lt;8;k++)  
65:        {  
66:        for(int l=0;l&amp;lt;8;l++)  
67:            cout&amp;lt;&amp;lt;&quot; ----&quot;;  
68:        cout&amp;lt;&amp;lt;endl;  
69:        for(int j=0;j&amp;lt;9;j++)  
70:        {  
71:            cout&amp;lt;&amp;lt;&quot;|  &quot;;  
72:            if(row[k]==j)  
73:            cout&amp;lt;&amp;lt;&quot;\b\bQ&quot;&amp;lt;&amp;lt;k;  
74:        }  
75:        cout&amp;lt;&amp;lt;endl;  
76:     }  
77:       for(int l=0;l&amp;lt;8;l++)  
78:            cout&amp;lt;&amp;lt;&quot; ----&quot;;       
79:       return 0;  
80:  }  
&lt;/code&gt;&lt;/pre&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&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; &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; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;Rest in Peace&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ananyamallik.blogspot.com/feeds/68325088782154175/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ananyamallik.blogspot.com/2010/10/solution-of-8-queen-problem.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/68325088782154175'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/68325088782154175'/><link rel='alternate' type='text/html' href='http://ananyamallik.blogspot.com/2010/10/solution-of-8-queen-problem.html' title='Solution of 8-Queen Problem'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04197657759022166885</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://i52.tinypic.com/2vbtq3s_th.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1270065828866707992.post-7517943804587529290</id><published>2010-10-24T09:55:00.000-07:00</published><updated>2010-10-24T09:55:51.466-07:00</updated><title type='text'>Just Because Google Exists Doesn’t Mean You Should Stop Asking People Things</title><content type='html'>&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/AVvXsEiJ42iXAIsUXLybfx3qs1fv3vUDiMhSqRrUie9c_JdmTlz1L2gMWGvwWcPO6EFKv2-j9VDF7PdprZRVrnkHZm7iNXbEeSXLds80IY94BKiNVR7JRgw34UAL9ztKE_XjKuVQ5YnOhd4N6bg/s1600/google.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJ42iXAIsUXLybfx3qs1fv3vUDiMhSqRrUie9c_JdmTlz1L2gMWGvwWcPO6EFKv2-j9VDF7PdprZRVrnkHZm7iNXbEeSXLds80IY94BKiNVR7JRgw34UAL9ztKE_XjKuVQ5YnOhd4N6bg/s1600/google.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #272727; font-family: &#39;Lucida Grande&#39;, Verdana, &#39;Lucida Sans Regular&#39;, &#39;Lucida Sans Unicode&#39;, Arial, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&amp;nbsp;I found a pretty interesting thing :- If you spend any amount of time online you’re probably very familiar with the above website,&lt;a href=&quot;http://lmgtfy.com/&quot;&gt;Let Me Google That For You&lt;/a&gt;&amp;nbsp;LMGTFY is a super smug and hilarious site built for those sick of&amp;nbsp;&lt;em&gt;“all those people that find it more convenient to bother you with their question rather than google it for themselves.&lt;/em&gt;“&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #272727; font-family: &#39;Lucida Grande&#39;, Verdana, &#39;Lucida Sans Regular&#39;, &#39;Lucida Sans Unicode&#39;, Arial, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #272727; font-family: &#39;Lucida Grande&#39;, Verdana, &#39;Lucida Sans Regular&#39;, &#39;Lucida Sans Unicode&#39;, Arial, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;Also&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #5d5d5d; font-family: &#39;Lucida Grande&#39;, Verdana, &#39;Lucida Sans Regular&#39;, &#39;Lucida Sans Unicode&#39;, Arial, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;em&gt;“Because of Google,” Mecurio said. “Everyone would call their friend and the friend would start Googling to get the answer. The contestant would be like, ‘Hey Joe, aspirin. A-S-P-I-R-I-N.’ We could hear them typing on their keyboard&lt;/em&gt;!”&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #5d5d5d; font-family: &#39;Lucida Grande&#39;, Verdana, &#39;Lucida Sans Regular&#39;, &#39;Lucida Sans Unicode&#39;, Arial, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #5d5d5d; font-family: &#39;Lucida Grande&#39;, Verdana, &#39;Lucida Sans Regular&#39;, &#39;Lucida Sans Unicode&#39;, Arial, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #272727;&quot;&gt;Google has basically become an extension of our brain, as of Mr. Steve Jobs’&amp;nbsp;&lt;a href=&quot;http://www.youtube.com/watch?v=ob_GX50Za6c&quot;&gt;Bicycle for Our Mind&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #5d5d5d; font-family: &#39;Lucida Grande&#39;, Verdana, &#39;Lucida Sans Regular&#39;, &#39;Lucida Sans Unicode&#39;, Arial, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #272727;&quot;&gt;Twice this week I have asked questions that would be better suited to a human rather than an search engine algorithm and both times I’ve been met with a&amp;nbsp;&lt;em&gt;“just Google it”- &lt;/em&gt;&amp;nbsp;Clumsy response [:x].&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #5d5d5d; font-family: &#39;Lucida Grande&#39;, Verdana, &#39;Lucida Sans Regular&#39;, &#39;Lucida Sans Unicode&#39;, Arial, sans-serif; font-size: 13px; line-height: 19px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #272727;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ananyamallik.blogspot.com/feeds/7517943804587529290/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ananyamallik.blogspot.com/2010/10/just-because-google-exists-doesnt-mean.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/7517943804587529290'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/7517943804587529290'/><link rel='alternate' type='text/html' href='http://ananyamallik.blogspot.com/2010/10/just-because-google-exists-doesnt-mean.html' title='Just Because Google Exists Doesn’t Mean You Should Stop Asking People Things'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04197657759022166885</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJ42iXAIsUXLybfx3qs1fv3vUDiMhSqRrUie9c_JdmTlz1L2gMWGvwWcPO6EFKv2-j9VDF7PdprZRVrnkHZm7iNXbEeSXLds80IY94BKiNVR7JRgw34UAL9ztKE_XjKuVQ5YnOhd4N6bg/s72-c/google.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1270065828866707992.post-8847204397018318603</id><published>2010-10-21T07:32:00.001-07:00</published><updated>2011-02-06T04:15:56.449-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Bellman Ford Cpp STL implementation"/><title type='text'>Implementation of Bellman_Ford in C++ Using STL</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;For further info goto : &lt;a href=&quot;http://securityresearch.in/beta/&quot;&gt;http://securityresearch.in/beta/&lt;/a&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  //   Bellman_Ford.cpp  
2:  //     
3:  //   Copyright 2010 ananya &amp;lt;ananya@ananya-laptop&amp;gt;  
4:  //     
5:  //   This program is free software; you can redistribute it and/or modify  
6:  //   it under the terms of the GNU General Public License as published by  
7:  //   the Free Software Foundation; either version 2 of the License, or  
8:  //   (at your option) any later version.  
9:  //     
10:  //   This program is distributed in the hope that it will be useful,  
11:  //   but WITHOUT ANY WARRANTY; without even the implied warranty of  
12:  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
13:  //   GNU General Public License for more details.  
14:  //     
15:  //   You should have received a copy of the GNU General Public License  
16:  //   along with this program; if not, write to the Free Software  
17:  //   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,  
18:  //   MA 02110-1301, USA.  
19:  #include &amp;lt;iostream&amp;gt;  
20:  #include &amp;lt;stdio.h&amp;gt;  
21:  #include &amp;lt;limits.h&amp;gt;  
22:  #include &amp;lt;map&amp;gt;  
23:  #include &amp;lt;vector&amp;gt;  
24:  #include &amp;lt;string&amp;gt;  
25:  #include &amp;lt;list&amp;gt;  
26:  #include &amp;lt;functional&amp;gt;  
27:  using namespace std;  
28:  struct Vertex;  
29:  struct Edge  
30:  {  
31:       Vertex *dest;  
32:       double cost;  
33:       Edge(Vertex *d=0,double c=0.0)  
34:        : dest(d),cost(c){}  
35:  };  
36:  struct Vertex  
37:  {   
38:       string name;  
39:       vector&amp;lt;Edge&amp;gt; adj;  
40:       double dist;  
41:       Vertex *prev;  
42:       unsigned int scratch;  
43:       Vertex(const string &amp;amp;nam):name(nam)  
44:       {reset();}  
45:       void reset()  
46:       {  
47:            dist=3000000;  
48:            prev=0;  
49:            scratch=0;  
50:    }       
51:  };  
52:  class Graph  
53:  {  
54:       public:  
55:            Graph(){};  
56:         ~Graph();  
57:         void addEdge(const string &amp;amp; sourceName,const string &amp;amp; destName,double cost);  
58:         void printPath(const string &amp;amp; destName) const;  
59:         bool bellmanFord(const string &amp;amp; startName);  
60:         void printbellmanFord();  
61:       private:  
62:         Vertex * getVertex(const string &amp;amp; vertexName);  
63:         void printPath(const Vertex &amp;amp; dest) const;  
64:         void clearAll();  
65:         typedef map&amp;lt;string,Vertex *,less&amp;lt;string&amp;gt; &amp;gt; vmap;  
66:         vmap vertexMap;  
67:  };  
68:  Graph::~Graph()  
69:  {  
70:       for(vmap::iterator itr=vertexMap.begin();itr!=vertexMap.end();++itr)  
71:            delete (*itr).second;  
72:  }  
73:  Vertex * Graph::getVertex(const string &amp;amp; vertexName)  
74:  {  
75:       vmap::iterator itr=vertexMap.find(vertexName);  
76:       if(itr==vertexMap.end())  
77:       {  
78:            Vertex *newv=new Vertex(vertexName);  
79:            vertexMap[vertexName]=newv;  
80:            return newv;  
81:       }  
82:       return (*itr).second;  
83:  }  
84:  void Graph::addEdge(const string &amp;amp; sourceName,  
85:            const string &amp;amp; destName,double cost)  
86:  {  
87:       Vertex *v=getVertex(sourceName);  
88:       Vertex *w=getVertex(destName);  
89:       v-&amp;gt;adj.push_back(Edge(w,cost));  
90:  }  
91:  void Graph::clearAll()  
92:  {  
93:       for(vmap::iterator itr=vertexMap.begin();itr!=vertexMap.end();++itr)  
94:            (*itr).second-&amp;gt;reset();  
95:  }  
96:  void Graph::printPath(const Vertex &amp;amp; dest) const  
97:  {  
98:       if(dest.prev!=0)  
99:       {  
100:            printPath(*dest.prev);  
101:            cout&amp;lt;&amp;lt;&quot; --&amp;gt;&quot;;  
102:       }  
103:       cout&amp;lt;&amp;lt;dest.name;  
104:  }  
105:  void Graph::printPath(const string &amp;amp;destName) const  
106:  {  
107:       vmap::const_iterator itr=vertexMap.find(destName);  
108:       if(itr==vertexMap.end())  
109:       {  
110:            cout&amp;lt;&amp;lt;destName&amp;lt;&amp;lt;&quot; not Found in Graph&quot;&amp;lt;&amp;lt;endl;  
111:            return;  
112:       }  
113:       Vertex &amp;amp; w =*(*itr).second;  
114:       if(w.dist==3000000)  
115:            cout&amp;lt;&amp;lt;destName&amp;lt;&amp;lt;&quot; is not rechable&quot;&amp;lt;&amp;lt;endl;  
116:       else  
117:       {  
118:            cout&amp;lt;&amp;lt;&quot;(Cost is: &quot;&amp;lt;&amp;lt;w.dist&amp;lt;&amp;lt; &quot;)&quot;;  
119:            printPath(w);  
120:       }  
121:       cout&amp;lt;&amp;lt;endl;  
122:  }  
123:  void Graph::printbellmanFord()  
124:  {  
125:       for(vmap::iterator itr =vertexMap.begin();itr!=vertexMap.end();++itr)  
126:        {  
127:            cout&amp;lt;&amp;lt;(*itr).first;  
128:            printPath((*itr).first);  
129:        }  
130:  }  
131:  bool Graph::bellmanFord(const string &amp;amp; startName)  
132:  {  
133:       vmap::iterator itr=vertexMap.find(startName);  
134:       if(itr==vertexMap.end())  
135:         {  
136:          cout&amp;lt;&amp;lt;&quot;Specified node not found in graph&quot;&amp;lt;&amp;lt;endl;  
137:          return 0;  
138:         }  
139:       clearAll();  
140:       Vertex *start=(*itr).second;  
141:       list&amp;lt;Vertex *&amp;gt; q;  
142:       q.push_back(start);  
143:       start-&amp;gt;dist=0;  
144:       start-&amp;gt;scratch++;  
145:       while(!q.empty())  
146:       {  
147:            Vertex *v=q.front();  
148:            q.pop_front();  
149:            if(v-&amp;gt;scratch++&amp;gt;2*vertexMap.size())  
150:            {  
151:                 cout&amp;lt;&amp;lt;&quot;Negative Cycle detected&quot;&amp;lt;&amp;lt;endl;  
152:                 return false ;  
153:            }  
154:            for(unsigned int i=0;i&amp;lt;v-&amp;gt;adj.size();i++)  
155:            {  
156:                 Edge e=v-&amp;gt;adj[i];  
157:                 Vertex *w=e.dest;  
158:                 double cvw=e.cost;  
159:                 if(w-&amp;gt;dist&amp;gt;v-&amp;gt;dist+cvw)  
160:                 {  
161:                      w-&amp;gt;dist=v-&amp;gt;dist+cvw;  
162:                      w-&amp;gt;prev=v;  
163:                      if(w-&amp;gt;scratch++ % 2==0)  
164:                           q.push_back(w);  
165:                      else  
166:                           w-&amp;gt;scratch++;  
167:                 }  
168:            }  
169:       }  
170:       return true ;  
171:  }  
172:  int main(int argc, char** argv)  
173:  {  
174:       Graph g;  
175:       cout&amp;lt;&amp;lt;&quot;Enter the Graph description in following format:-&amp;gt;&quot;&amp;lt;&amp;lt;endl;  
176:       cout&amp;lt;&amp;lt;&quot;Edge_sourceName Edge_destName cost_of_Edge&quot;&amp;lt;&amp;lt;endl;  
177:       cout&amp;lt;&amp;lt;&quot;Enter the detail:-&quot;&amp;lt;&amp;lt;endl;  
178:       int a,cost;  
179:       a=1;  
180:       string sName,dName;  
181:       while(a==1)  
182:       {   
183:        cin&amp;gt;&amp;gt;sName&amp;gt;&amp;gt;dName&amp;gt;&amp;gt;cost;  
184:        g.addEdge(sName,dName,cost);  
185:        cout&amp;lt;&amp;lt;&quot;Wanna Continue(press 1/0):&quot;;  
186:        cin&amp;gt;&amp;gt;a;   
187:    }  
188:    cout&amp;lt;&amp;lt;&quot;Enter the source node:&quot;;  
189:    cin&amp;gt;&amp;gt;sName;  
190:    if(g.bellmanFord(sName)==true)  
191:    {  
192:       cout&amp;lt;&amp;lt;&quot;Shortest path to Distinct nodes are :--&amp;gt;&quot;&amp;lt;&amp;lt;endl;  
193:       g.printbellmanFord();  
194:    }  
195:    else  
196:    {  
197:    }   
198:    return 0;  
199:  }  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ananyamallik.blogspot.com/feeds/8847204397018318603/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ananyamallik.blogspot.com/2010/10/implementation-of-bellmanford-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/8847204397018318603'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/8847204397018318603'/><link rel='alternate' type='text/html' href='http://ananyamallik.blogspot.com/2010/10/implementation-of-bellmanford-in-c.html' title='Implementation of Bellman_Ford in C++ Using STL'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04197657759022166885</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1270065828866707992.post-2656825286545004514</id><published>2010-10-21T07:29:00.001-07:00</published><updated>2011-02-06T04:16:57.208-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Floyd Warshall CPP STL  implementaion"/><title type='text'>Implementation of Floyd Warshall in C++ Using STL</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  //   Floyd_Warshall.cpp  
2:  //     
3:  //   Copyright 2010 ananya &amp;lt;ananya@ananya-laptop&amp;gt;  
4:  //     
5:  //   This program is free software; you can redistribute it and/or modify  
6:  //   it under the terms of the GNU General Public License as published by  
7:  //   the Free Software Foundation; either version 2 of the License, or  
8:  //   (at your option) any later version.  
9:  //     
10:  //   This program is distributed in the hope that it will be useful,  
11:  //   but WITHOUT ANY WARRANTY; without even the implied warranty of  
12:  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
13:  //   GNU General Public License for more details.  
14:  //     
15:  //   You should have received a copy of the GNU General Public License  
16:  //   along with this program; if not, write to the Free Software  
17:  //   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,  
18:  //   MA 02110-1301, USA.  
19:  #include &amp;lt;iostream&amp;gt;  
20:  #include &amp;lt;vector&amp;gt;  
21:  #include &amp;lt;stdio.h&amp;gt;  
22:  using namespace std;  
23:  int path(int x,int y,vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt; &amp;amp; par)  
24:  {  
25:       if(x!=y)  
26:       {  
27:            path(x,par[x][y],par);  
28:            cout&amp;lt;&amp;lt;&quot;--&amp;gt;&quot;&amp;lt;&amp;lt;y;  
29:       }  
30:       return 0;  
31:  }  
32:  int main(int argc, char** argv)  
33:  {  
34:       int n;  
35:       cout&amp;lt;&amp;lt;&quot;Enter the Number of nodes : &quot;;  
36:       cin&amp;gt;&amp;gt;n;  
37:       vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt; g(n+1,vector&amp;lt;int&amp;gt; (n+1));  
38:       vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt; d(n+1,vector&amp;lt;int&amp;gt; (n+1));  
39:       vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt; p(n+1,vector&amp;lt;int&amp;gt; (n+1));  
40:  /*     vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt; Temp(n,vector&amp;lt;int&amp;gt; (n));  
41:       vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt; pTemp((n,vecor&amp;lt;int&amp;gt; (n));  
42:  */       
43:       cout&amp;lt;&amp;lt;&quot;use 3000 for INFINITY&quot;&amp;lt;&amp;lt;endl;  
44:       cout&amp;lt;&amp;lt;&quot;Enter the graph discription in row-major fashion:&quot;&amp;lt;&amp;lt;endl;  
45:       for(int i=1;i&amp;lt;n+1;i++)  
46:            {  
47:                 for(int j=1;j&amp;lt;n+1;j++)  
48:                      {  
49:                           cin&amp;gt;&amp;gt;g[i][j];  
50:                      }  
51:            }  
52:       for(int i=1;i&amp;lt;n+1;i++)  
53:            {  
54:                 for(int j=1;j&amp;lt;n+1;j++)  
55:                      {  
56:                           d[i][j]=g[i][j];  
57:                           if(g[i][j]==0 || g[i][j]==3000)  
58:                                p[i][j]=0;  
59:                           else   
60:                                p[i][j]=i;  
61:                      }  
62:            }  
63:       for(int k=1;k&amp;lt;n+1;k++)  
64:       {  
65:            for(int i=1;i&amp;lt;n+1;i++)  
66:                 {  
67:                      for(int j=1;j&amp;lt;n+1;j++)  
68:                      {  
69:                           if(d[i][j] &amp;gt; d[i][k]+d[k][j])  
70:                           {  
71:                                d[i][j]=d[i][k]+d[k][j];  
72:                                p[i][j]=p[k][j];  
73:                           }  
74:                      }  
75:                 }  
76:       }  
77:       cout&amp;lt;&amp;lt;&quot;Modified ASSP MATRIX is:-&amp;gt;&quot;;  
78:       for(int i=1;i&amp;lt;n+1;i++)  
79:    {  
80:            std::cout&amp;lt;&amp;lt;endl;  
81:            for(int j=1;j&amp;lt;n+1;j++)  
82:            {  
83:                printf(&quot;%5d&quot;,d[i][j]);  
84:            }  
85:    }  
86:    cout&amp;lt;&amp;lt;endl&amp;lt;&amp;lt;&quot;Parent MATRIX is:-&amp;gt;&quot;;  
87:    for(int i=1;i&amp;lt;n+1;i++)  
88:    {  
89:            std::cout&amp;lt;&amp;lt;endl;  
90:            for(int j=1;j&amp;lt;n+1;j++)  
91:            {  
92:                printf(&quot;%5d&quot;,p[i][j]);  
93:            }  
94:    }  
95:    cout&amp;lt;&amp;lt;endl&amp;lt;&amp;lt;endl;  
96:    for(int i=1;i&amp;lt;n+1;i++)  
97:    {  
98:            for(int j=1;j&amp;lt;n+1;j++)  
99:            {  
100:                 if(i!=j)  
101:                 {  
102:                      cout&amp;lt;&amp;lt;&quot;Shortes Path from node &quot;  
103:                        &amp;lt;&amp;lt;i &amp;lt;&amp;lt;&quot; to node &quot;&amp;lt;&amp;lt;j  
104:                        &amp;lt;&amp;lt;&quot; :- cost= &quot;&amp;lt;&amp;lt;d[i][j];  
105:                      cout&amp;lt;&amp;lt;&quot;::path is &quot;&amp;lt;&amp;lt;i;  
106:                      path(i,j,p);  
107:                 }  
108:                 cout&amp;lt;&amp;lt;endl;  
109:            }  
110:       }  
111:       /*cout&amp;lt;&amp;lt;endl;  
112:       cout&amp;lt;&amp;lt;&quot;1&quot;;  
113:    path(1,2,p);*/  
114:       return 0;  
115:  }  
&lt;/code&gt;&lt;/pre&gt;&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;For Further info goto :- &lt;a href=&quot;http://securityresearch.in/beta/&quot;&gt;http://securityresearch.in/beta/&lt;/a&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ananyamallik.blogspot.com/feeds/2656825286545004514/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ananyamallik.blogspot.com/2010/10/implementation-of-floyd-warshall-in-c_21.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/2656825286545004514'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/2656825286545004514'/><link rel='alternate' type='text/html' href='http://ananyamallik.blogspot.com/2010/10/implementation-of-floyd-warshall-in-c_21.html' title='Implementation of Floyd Warshall in C++ Using STL'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04197657759022166885</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1270065828866707992.post-6503651460061185512</id><published>2010-10-21T07:26:00.001-07:00</published><updated>2010-10-21T07:26:05.584-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Jhonson APSP Impmentation CPP STL"/><title type='text'>Implementation of Jhonson&#39;s APSP in C++ Using STL</title><content type='html'>&lt;pre  style=&quot;font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;&quot;&gt;&lt;code style=&quot;color:#000000;word-wrap:normal;&quot;&gt;1:  //   Johnson_mod.cpp  
2:  //     
3:  //   Copyright 2010 ananya &amp;lt;ananya@ananya-laptop&amp;gt;  
4:  //     
5:  //   This program is free software; you can redistribute it and/or modify  
6:  //   it under the terms of the GNU General Public License as published by  
7:  //   the Free Software Foundation; either version 2 of the License, or  
8:  //   (at your option) any later version.  
9:  //     
10:  //   This program is distributed in the hope that it will be useful,  
11:  //   but WITHOUT ANY WARRANTY; without even the implied warranty of  
12:  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
13:  //   GNU General Public License for more details.  
14:  //     
15:  //   You should have received a copy of the GNU General Public License  
16:  //   along with this program; if not, write to the Free Software  
17:  //   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,  
18:  //   MA 02110-1301, USA.  
19:  #include &amp;lt;iostream&amp;gt;  
20:  #include &amp;lt;stdio.h&amp;gt;  
21:  #include &amp;lt;limits.h&amp;gt;  
22:  #include &amp;lt;map&amp;gt;  
23:  #include &amp;lt;vector&amp;gt;  
24:  #include &amp;lt;string&amp;gt;  
25:  #include &amp;lt;list&amp;gt;  
26:  #include &amp;lt;functional&amp;gt;  
27:  #include &amp;lt;queue&amp;gt;  
28:  using namespace std;  
29:  struct Path;  
30:  struct Vertex;  
31:  struct Edge  
32:  {  
33:       Vertex *dest;      
34:       double cost;      
35:       Edge(Vertex *d=0,double c =0.0)  
36:        : dest(d),cost(c) {}  
37:  };  
38:  struct Vertex  
39:  {  
40:       string name;      
41:       vector&amp;lt;Edge&amp;gt; adj;    
42:       double dist;      
43:       Vertex *prev;      
44:    unsigned int scratch;  
45:    double h;  
46:    unsigned int hash;    
47:    Vertex(const string &amp;amp; nam):name(nam)  
48:      {reset();}  
49:    void reset()  
50:     {  
51:             dist=3000000;  
52:             prev=0;  
53:             scratch=0;  
54:        }  
55:  };  
56:  struct Path  
57:  {  
58:       Vertex *dest;  
59:       double cost;  
60:       Path(Vertex *d=0 ,double c=0)  
61:        : dest(d),cost(c){}  
62:       bool operator&amp;gt;(const Path &amp;amp;rhs) const  
63:       {return (cost &amp;gt; rhs.cost);}  
64:       bool operator&amp;lt;(const Path &amp;amp;rhs) const  
65:       {return (cost &amp;lt; rhs.cost);}  
66:  };  
67:  class Graph  
68:  {  
69:       public:  
70:         Graph(){};  
71:        ~Graph();  
72:         void addEdge(const string &amp;amp; sourceName,const string &amp;amp; destName,double cost);  
73:         void printPath(const string &amp;amp; destName) const;  
74:         void dijkastra(const string &amp;amp; startName);  
75:         bool bellmanFord(const string &amp;amp; startName);  
76:         bool jhonson();  
77:         void printDijkastra();  
78:         int getNodeCount();  
79:         void calcHash();  
80:    private:  
81:      Vertex * getVertex(const string &amp;amp; vertexName);  
82:      void printPath(const Vertex &amp;amp; dest) const;  
83:      void clearAll();  
84:      typedef map&amp;lt;string,Vertex *,less&amp;lt;string&amp;gt; &amp;gt; vmap;  
85:      vmap vertexMap;     
86:  };  
87:  Graph g,g1;  
88:  Graph::~Graph()  
89:  {  
90:       for(vmap::iterator itr =vertexMap.begin();itr!=vertexMap.end();++itr)  
91:           delete (*itr).second;  
92:  }  
93:  Vertex * Graph::getVertex(const string &amp;amp; vertexName)  
94:  {  
95:       vmap::iterator itr= vertexMap.find(vertexName);  
96:       if(itr==vertexMap.end())  
97:       {  
98:            Vertex *newv=new Vertex(vertexName);  
99:            vertexMap[vertexName]=newv;  
100:            return newv;  
101:       }  
102:       return (*itr).second;  
103:  }  
104:  void Graph::addEdge(const string &amp;amp; sourceName,  
105:            const string &amp;amp; destName,double cost)  
106:  {  
107:       Vertex * v =getVertex(sourceName);  
108:       Vertex * w =getVertex(destName);  
109:       v-&amp;gt;adj.push_back(Edge(w,cost));  
110:  }  
111:  void Graph::clearAll()  
112:  {  
113:       for(vmap::iterator itr= vertexMap.begin();  
114:         itr!=vertexMap.end();++itr)  
115:         (*itr).second-&amp;gt;reset();  
116:  }  
117:  void Graph::printPath(const Vertex &amp;amp; dest) const  
118:  {  
119:       if(dest.prev !=0)  
120:       {  
121:            printPath(*dest.prev);  
122:            cout&amp;lt;&amp;lt;&quot; --&amp;gt; &quot;;  
123:       }  
124:       cout&amp;lt;&amp;lt;dest.name;  
125:  }  
126:  void Graph::printPath(const string &amp;amp; destName) const  
127:  {  
128:       vmap::const_iterator itr= vertexMap.find(destName);  
129:       if(itr==vertexMap.end())  
130:       {  
131:            cout&amp;lt;&amp;lt;&quot;Destination not found &quot;&amp;lt;&amp;lt;endl;  
132:            return ;  
133:       }       
134:       const Vertex &amp;amp; w =*(*itr).second;  
135:       if(w.dist==3000000)  
136:         cout&amp;lt;&amp;lt;destName&amp;lt;&amp;lt;&quot; not reachable &quot;&amp;lt;&amp;lt;endl;  
137:       else  
138:       {  
139:            cout&amp;lt;&amp;lt;&quot;(Cost is: &quot;&amp;lt;&amp;lt; w.dist &amp;lt;&amp;lt; &quot;)&quot;;  
140:            printPath(w);  
141:       }  
142:       cout&amp;lt;&amp;lt;endl;  
143:  }  
144:  void Graph::printDijkastra()  
145:  {  
146:       for(vmap::iterator itr =vertexMap.begin();itr!=vertexMap.end();++itr)  
147:        {  
148:            cout&amp;lt;&amp;lt;(*itr).first;  
149:            printPath((*itr).first);  
150:        }  
151:  }  
152:  int Graph::getNodeCount()  
153:  {  
154:       return vertexMap.size();  
155:  }  
156:  void Graph::calcHash()  
157:  {  
158:       unsigned int i =1;  
159:       for(vmap::iterator itr=vertexMap.begin();itr!=vertexMap.end();++itr)  
160:       {  
161:            (*itr).second-&amp;gt;hash=i++;  
162:       }  
163:  }  
164:  void Graph::dijkastra(const string &amp;amp; startName)  
165:  {  
166:       priority_queue&amp;lt; Path,vector&amp;lt;Path&amp;gt;,greater&amp;lt;Path&amp;gt; &amp;gt; pq;  
167:       Path vrec;  
168:       vmap::iterator itr=vertexMap.find(startName);  
169:       if(itr==vertexMap.end())  
170:         {  
171:          cout&amp;lt;&amp;lt;&quot;Specified node not found in graph&quot;&amp;lt;&amp;lt;endl;  
172:          return ;  
173:         }  
174:       clearAll();  
175:       Vertex *start= (*itr).second;  
176:       pq.push(Path(start,0));  
177:       start-&amp;gt;dist=0;  
178:       unsigned int nodesSeen=0;  
179:       for(;nodesSeen&amp;lt;vertexMap.size();nodesSeen++)  
180:       {  
181:            do  
182:            {  
183:                 if(pq.empty())  
184:                   return;  
185:                 vrec=pq.top();  
186:                 pq.pop();  
187:            }while(vrec.dest-&amp;gt;scratch!=0);  
188:            Vertex *v =vrec.dest;  
189:            v-&amp;gt;scratch=1;  
190:            for(unsigned int i=0;i&amp;lt;v-&amp;gt;adj.size();i++)  
191:            {  
192:                 Edge e=v-&amp;gt;adj[i];  
193:                 Vertex *w=e.dest;  
194:                 double cvw=e.cost;  
195:                 if(cvw&amp;lt;0)  
196:                 {  
197:                  cout&amp;lt;&amp;lt;&quot;Negative Weight Edge seen&quot;&amp;lt;&amp;lt;endl;  
198:                  return;  
199:                 }  
200:                  if(w-&amp;gt;dist&amp;gt;v-&amp;gt;dist+cvw)  
201:                  {  
202:                       w-&amp;gt;dist=v-&amp;gt;dist+cvw;  
203:                       w-&amp;gt;prev=v;  
204:                       pq.push(Path(w,w-&amp;gt;dist));  
205:                  }  
206:             }  
207:        }  
208:  }  
209:  bool Graph::bellmanFord(const string &amp;amp; startName)  
210:  {  
211:       vmap::iterator itr=vertexMap.find(startName);  
212:       if(itr==vertexMap.end())  
213:         {  
214:          cout&amp;lt;&amp;lt;&quot;Specified node not found in graph&quot;&amp;lt;&amp;lt;endl;  
215:          return 0;  
216:         }  
217:       clearAll();  
218:       Vertex *start=(*itr).second;  
219:       list&amp;lt;Vertex *&amp;gt; q;  
220:       q.push_back(start);  
221:       start-&amp;gt;dist=0;  
222:       start-&amp;gt;scratch++;  
223:       while(!q.empty())  
224:       {  
225:            Vertex *v=q.front();  
226:            q.pop_front();  
227:            if(v-&amp;gt;scratch++&amp;gt;2*vertexMap.size())  
228:            {  
229:                 cout&amp;lt;&amp;lt;&quot;Negative Cycle detected&quot;&amp;lt;&amp;lt;endl;  
230:                 return false ;  
231:            }  
232:            for(unsigned int i=0;i&amp;lt;v-&amp;gt;adj.size();i++)  
233:            {  
234:                 Edge e=v-&amp;gt;adj[i];  
235:                 Vertex *w=e.dest;  
236:                 double cvw=e.cost;  
237:                 if(w-&amp;gt;dist&amp;gt;v-&amp;gt;dist+cvw)  
238:                 {  
239:                      w-&amp;gt;dist=v-&amp;gt;dist+cvw;  
240:                      w-&amp;gt;prev=v;  
241:                      if(w-&amp;gt;scratch++ % 2==0)  
242:                           q.push_back(w);  
243:                      else  
244:                           w-&amp;gt;scratch++;  
245:                 }  
246:            }  
247:       }  
248:       return true ;  
249:  }  
250:  bool Graph::jhonson()  
251:  {  
252:       g.calcHash();  
253:       int n=g.getNodeCount();  
254:       vector&amp;lt;vector&amp;lt;int&amp;gt; &amp;gt; d(n+1,vector&amp;lt;int&amp;gt; (n+1));  
255:       for(int i=0;i&amp;lt;n+1;i++)  
256:            for(int j=0;j&amp;lt;n+1;j++)  
257:                 d[i][j]=0;  
258:       string str;  
259:    g.getVertex(&quot;S&quot;);  
260:       for(vmap::iterator itr=vertexMap.begin();itr!=vertexMap.end();++itr)  
261:       {  
262:            str=(*itr).first;  
263:            g.addEdge(&quot;S&quot;,str,0);  
264:       }  
265:       bool t=g.bellmanFord(&quot;S&quot;);  
266:       if(t==false)  
267:       {  
268:            cout&amp;lt;&amp;lt;&quot;Negative Cycle is there in Graph !!Exiting!!&quot;&amp;lt;&amp;lt;endl;  
269:            return false;  
270:       }  
271:       else  
272:       {  
273:            cout&amp;lt;&amp;lt;endl&amp;lt;&amp;lt;&quot;h-value of each node using Bellman_Ford is :-&amp;gt;&quot;&amp;lt;&amp;lt;endl;  
274:            for(vmap::iterator itr=vertexMap.begin();itr!=vertexMap.end();++itr)  
275:            {  
276:                 (*itr).second-&amp;gt;h=(*itr).second-&amp;gt;dist;  
277:                 cout&amp;lt;&amp;lt;(*itr).first&amp;lt;&amp;lt;&quot;  :  &quot;&amp;lt;&amp;lt;(*itr).second-&amp;gt;h&amp;lt;&amp;lt;endl;  
278:            }  
279:            cout&amp;lt;&amp;lt;endl&amp;lt;&amp;lt;&quot;Reweighted edges are :-&amp;gt;&quot;&amp;lt;&amp;lt;endl;            
280:         for(vmap::iterator itr=vertexMap.begin();itr!=vertexMap.end();++itr)  
281:            {  
282:                 Vertex *w=(*itr).second;  
283:                 for(unsigned int i=0;i&amp;lt;w-&amp;gt;adj.size();i++)  
284:                 {  
285:                      w-&amp;gt;adj[i].cost=w-&amp;gt;adj[i].cost + w-&amp;gt;h -w-&amp;gt;adj[i].dest-&amp;gt;h;  
286:                      cout&amp;lt;&amp;lt;w-&amp;gt;name&amp;lt;&amp;lt;&quot; to &quot;&amp;lt;&amp;lt;w-&amp;gt;adj[i].dest-&amp;gt;name&amp;lt;&amp;lt;&quot; = &quot;&amp;lt;&amp;lt;w-&amp;gt;adj[i].cost&amp;lt;&amp;lt;endl;  
287:                 }  
288:                 cout&amp;lt;&amp;lt;endl;  
289:            }       
290:            for(vmap::iterator itr=vertexMap.begin();itr!=vertexMap.end();++itr)  
291:            {  
292:                 if((*itr).first!=&quot;S&quot;)  
293:                 {  
294:                      g.dijkastra((*itr).first);  
295:                      for(vmap::iterator itr1=vertexMap.begin();itr1!=vertexMap.end();++itr1)  
296:                      {  
297:                           if((*itr1).first!=&quot;S&quot;);  
298:                           {  
299:                                d[(*itr).second-&amp;gt;hash][(*itr1).second-&amp;gt;hash]= (*itr1).second-&amp;gt;dist + (*itr1).second-&amp;gt;h - (*itr).second-&amp;gt;h;  
300:                           }  
301:                      }  
302:                 }  
303:            }  
304:        cout&amp;lt;&amp;lt;endl&amp;lt;&amp;lt;&quot;All pair Shortest Path Matrix is --&amp;gt;&quot;&amp;lt;&amp;lt;endl;  
305:        printf(&quot;   A  B  C  D  E&quot;);  
306:        for(int i=1;i&amp;lt;n+1;i++)  
307:            {  
308:       cout&amp;lt;&amp;lt;endl;  
309:       if(i==1)  
310:                 cout&amp;lt;&amp;lt;&quot;A&quot;;  
311:             if(i==2)  
312:                 cout&amp;lt;&amp;lt;&quot;B&quot;;  
313:             if(i==3)  
314:                 cout&amp;lt;&amp;lt;&quot;C&quot;;  
315:             if(i==4)  
316:                 cout&amp;lt;&amp;lt;&quot;D&quot;;  
317:             if(i==5)  
318:                 cout&amp;lt;&amp;lt;&quot;E&quot;;  
319:             if(i==6)  
320:                 cout&amp;lt;&amp;lt;&quot;F&quot;;  
321:       for(int j=1;j&amp;lt;n+1;j++)  
322:        {  
323:         printf(&quot;%5d&quot;,d[i][j]);  
324:        }  
325:            }  
326:       return true;  
327:       }  
328:  }  
329:  int main(int argc, char** argv)  
330:  {  
331:       cout&amp;lt;&amp;lt;&quot;Enter the Graph description in following format:-&amp;gt;&quot;&amp;lt;&amp;lt;endl;  
332:       cout&amp;lt;&amp;lt;&quot;Edge_sourceName Edge_destName cost_of_Edge&quot;&amp;lt;&amp;lt;endl;  
333:       cout&amp;lt;&amp;lt;&quot;Enter the detail:-&quot;&amp;lt;&amp;lt;endl;  
334:       int a,cost;  
335:       a=1;  
336:       string sName,dName;  
337:       while(a==1)  
338:       {   
339:        cin&amp;gt;&amp;gt;sName&amp;gt;&amp;gt;dName&amp;gt;&amp;gt;cost;  
340:        g.addEdge(sName,dName,cost);  
341:        g1.addEdge(sName,dName,cost);  
342:        cout&amp;lt;&amp;lt;&quot;Wanna Continue(press 1/0):&quot;;  
343:        cin&amp;gt;&amp;gt;a;   
344:    }  
345:    g.jhonson();  
346:    return 0;  
347:  }  
&lt;/code&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://ananyamallik.blogspot.com/feeds/6503651460061185512/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ananyamallik.blogspot.com/2010/10/implementation-of-jhonsons-apsp-in-c_21.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/6503651460061185512'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/6503651460061185512'/><link rel='alternate' type='text/html' href='http://ananyamallik.blogspot.com/2010/10/implementation-of-jhonsons-apsp-in-c_21.html' title='Implementation of Jhonson&#39;s APSP in C++ Using STL'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04197657759022166885</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1270065828866707992.post-3045171088679874562</id><published>2010-10-21T07:23:00.001-07:00</published><updated>2011-02-06T04:18:08.990-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++ STL dijkstra implementaion"/><title type='text'>Implementation of Dijkastra in C++ Using STL</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  //   Dykstra.cpp  
2:  //     
3:  //   Copyright 2010 Ananya &amp;lt;Ananya@Ananya-laptop&amp;gt;  
4:  //     
5:  //   This program is free software; you can redistribute it and/or modify  
6:  //   it under the terms of the GNU General Public License as published by  
7:  //   the Free Software Foundation; either version 2 of the License, or  
8:  //   (at your option) any later version.  
9:  //     
10:  //   This program is distributed in the hope that it will be useful,  
11:  //   but WITHOUT ANY WARRANTY; without even the implied warranty of  
12:  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
13:  //   GNU General Public License for more details.  
14:  //     
15:  //   You should have received a copy of the GNU General Public License  
16:  //   along with this program; if not, write to the Free Software  
17:  //   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,  
18:  //   MA 02110-1301, USA.  
19:  #include &amp;lt;iostream&amp;gt;  
20:  #include &amp;lt;stdio.h&amp;gt;  
21:  #include &amp;lt;limits.h&amp;gt;  
22:  #include &amp;lt;map&amp;gt;  
23:  #include &amp;lt;vector&amp;gt;  
24:  #include &amp;lt;string&amp;gt;  
25:  #include &amp;lt;queue&amp;gt;  
26:  #include &amp;lt;functional&amp;gt;  
27:  using namespace std;  
28:  struct Path;  
29:  struct Vertex;  
30:  struct Edge  
31:  {  
32:                 //First is implicit   
33:       Vertex *dest;    //second vertex of Edge  
34:       double cost;    //Edge cost  
35:       Edge(Vertex *d=0,double c =0.0)  
36:        : dest(d),cost(c) {}  
37:  };  
38:  struct Vertex  
39:  {  
40:       string name;    //Vertex name   
41:       vector&amp;lt;Edge&amp;gt; adj;  //Adjacent vertices (and cost)  
42:       double dist;    //cost  
43:       Vertex *prev;    //Previoius vertex on shortest path   
44:    int scratch;    //Extra variable used in algorithm  
45:    Vertex(const string &amp;amp; nm):name(nm)  
46:      {reset();}  
47:    void reset()  
48:     {  
49:             dist=3000000;  
50:             prev=0;  
51:             scratch=0;  
52:        }  
53:  };  
54:  struct Path  
55:  {  
56:       Vertex *dest;  
57:       double cost;  
58:       Path(Vertex *d=0 ,double c=0)  
59:        : dest(d),cost(c){}  
60:       bool operator&amp;gt;(const Path &amp;amp;rhs) const  
61:       {return (cost &amp;gt; rhs.cost);}  
62:       bool operator&amp;lt;(const Path &amp;amp;rhs) const  
63:       {return (cost &amp;lt; rhs.cost);}  
64:  };  
65:  class Graph  
66:  {  
67:       public:  
68:         Graph(){};  
69:        ~Graph();  
70:         void addEdge(const string &amp;amp; sourceName,const string &amp;amp; destName,double cost);  
71:         void printPath(const string &amp;amp; destName) const;  
72:         void dijkastra(const string &amp;amp; startName);  
73:         void printDijkastra();  
74:    private:  
75:      Vertex * getVertex(const string &amp;amp; vertexName);  
76:      void printPath(const Vertex &amp;amp; dest) const;  
77:      void clearAll();  
78:      typedef map&amp;lt;string,Vertex *,less&amp;lt;string&amp;gt; &amp;gt; vmap;  
79:      /*Graph( const Graph &amp;amp; rhs) {}  
80:      const Graph &amp;amp; operator= ( const Graph &amp;amp; rhs)  
81:      {return *this;}*/   
82:      vmap vertexMap;     
83:  };  
84:  //Destructor :clean up the Vertex Object  
85:  Graph::~Graph()  
86:  {  
87:       for(vmap::iterator itr =vertexMap.begin();itr!=vertexMap.end();++itr)  
88:           delete (*itr).second;  
89:  }  
90:  //If vertexName is not present ,add it to the vertexMap  
91:  //return a pointer to the vertex .  
92:  Vertex * Graph::getVertex(const string &amp;amp; vertexName)  
93:  {  
94:       vmap::iterator itr= vertexMap.find(vertexName);  
95:       if(itr==vertexMap.end())  
96:       {  
97:            Vertex *newv=new Vertex(vertexName);  
98:            vertexMap[vertexName]=newv;  
99:            return newv;  
100:       }  
101:       return (*itr).second;  
102:  }  
103:  //Add a new edge to the graph  
104:  void Graph::addEdge(const string &amp;amp; sourceName,  
105:            const string &amp;amp; destName,double cost)  
106:  {  
107:       Vertex * v =getVertex(sourceName);  
108:       Vertex * w =getVertex(destName);  
109:       v-&amp;gt;adj.push_back(Edge(w,cost));  
110:  }  
111:  //Initialize the vertex output prior to running dijkastra  
112:  //Initialize  
113:  void Graph::clearAll()  
114:  {  
115:       for(vmap::iterator itr= vertexMap.begin();  
116:         itr!=vertexMap.end();++itr)  
117:         (*itr).second-&amp;gt;reset();  
118:  }  
119:  //Recursive algo to print shortest path to dest after Dijkastra  
120:  void Graph::printPath(const Vertex &amp;amp; dest) const  
121:  {  
122:       if(dest.prev !=0)  
123:       {  
124:            printPath(*dest.prev);  
125:            cout&amp;lt;&amp;lt;&quot; --&amp;gt; &quot;;  
126:       }  
127:       cout&amp;lt;&amp;lt;dest.name;  
128:  }  
129:  //algo to print the cost if node is reachable else print not rechable  
130:  void Graph::printPath(const string &amp;amp; destName) const  
131:  {  
132:       vmap::const_iterator itr= vertexMap.find(destName);  
133:       if(itr==vertexMap.end())  
134:       {  
135:            cout&amp;lt;&amp;lt;&quot;Destination not found &quot;&amp;lt;&amp;lt;endl;  
136:            return ;  
137:       }       
138:       const Vertex &amp;amp; w =*(*itr).second;  
139:       if(w.dist==3000000)  
140:         cout&amp;lt;&amp;lt;destName&amp;lt;&amp;lt;&quot; not reachable &quot;&amp;lt;&amp;lt;endl;  
141:       else  
142:       {  
143:            cout&amp;lt;&amp;lt;&quot;(Cost is: &quot;&amp;lt;&amp;lt; w.dist &amp;lt;&amp;lt; &quot;)&quot;;  
144:            printPath(w);  
145:       }  
146:       cout&amp;lt;&amp;lt;endl;  
147:  }  
148:  void Graph::printDijkastra()  
149:  {  
150:       for(vmap::iterator itr =vertexMap.begin();itr!=vertexMap.end();++itr)  
151:        {  
152:            cout&amp;lt;&amp;lt;(*itr).first;  
153:            printPath((*itr).first);  
154:        }  
155:  }  
156:  void Graph::dijkastra(const string &amp;amp; startName)  
157:  {  
158:       priority_queue&amp;lt; Path,vector&amp;lt;Path&amp;gt;,greater&amp;lt;Path&amp;gt; &amp;gt; pq;  
159:       Path vrec;  
160:       vmap::iterator itr=vertexMap.find(startName);  
161:       if(itr==vertexMap.end())  
162:         {  
163:          cout&amp;lt;&amp;lt;&quot;Specified node not found in graph&quot;&amp;lt;&amp;lt;endl;  
164:          return ;  
165:         }  
166:       clearAll();  
167:       Vertex *start= (*itr).second;  
168:       pq.push(Path(start,0));  
169:       start-&amp;gt;dist=0;  
170:       unsigned int nodesSeen=0;  
171:       for(;nodesSeen&amp;lt;vertexMap.size();nodesSeen++)  
172:       {  
173:            do  
174:            {  
175:                 if(pq.empty())  
176:                   return;  
177:                 vrec=pq.top();  
178:                 pq.pop();  
179:            }while(vrec.dest-&amp;gt;scratch!=0);  
180:            Vertex *v =vrec.dest;  
181:            v-&amp;gt;scratch=1;  
182:            for(unsigned int i=0;i&amp;lt;v-&amp;gt;adj.size();i++)  
183:            {  
184:                 Edge e=v-&amp;gt;adj[i];  
185:                 Vertex *w=e.dest;  
186:                 double cvw=e.cost;  
187:                 if(cvw&amp;lt;0)  
188:                 {  
189:                  cout&amp;lt;&amp;lt;&quot;Negative Weight Edge seen&quot;&amp;lt;&amp;lt;endl;  
190:                  return;  
191:                  }  
192:                  if(w-&amp;gt;dist&amp;gt;v-&amp;gt;dist+cvw)  
193:                  {  
194:                       w-&amp;gt;dist=v-&amp;gt;dist+cvw;  
195:                       w-&amp;gt;prev=v;  
196:                       pq.push(Path(w,w-&amp;gt;dist));  
197:                 }  
198:             }  
199:        }  
200:  }  
201:  int main(int argc, char** argv)  
202:  {  
203:       Graph g;  
204:       cout&amp;lt;&amp;lt;&quot;Enter the Graph description in following format:-&amp;gt;&quot;&amp;lt;&amp;lt;endl;  
205:       cout&amp;lt;&amp;lt;&quot;sourceName destName cost_of_Edge&quot;&amp;lt;&amp;lt;endl;  
206:       cout&amp;lt;&amp;lt;&quot;Enter the detail&quot;&amp;lt;&amp;lt;endl;  
207:       int a,cost;  
208:       a=1;  
209:       string sName,dName;  
210:       while(a==1)  
211:       {   
212:        cin&amp;gt;&amp;gt;sName&amp;gt;&amp;gt;dName&amp;gt;&amp;gt;cost;  
213:        if(cost&amp;lt;0)  
214:             cout&amp;lt;&amp;lt;&quot;Pls enter Non-Negative Edge wieght for Dijkastra&quot;&amp;lt;&amp;lt;endl;  
215:        else  
216:             g.addEdge(sName,dName,cost);  
217:        cout&amp;lt;&amp;lt;&quot;Wanna Continue(press 1/0):&quot;;  
218:        cin&amp;gt;&amp;gt;a;   
219:    }  
220:    cout&amp;lt;&amp;lt;&quot;Enter the source node:&quot;;  
221:    cin&amp;gt;&amp;gt;sName;  
222:    g.dijkastra(sName);  
223:    cout&amp;lt;&amp;lt;&quot;Shortest path to Distinct nodes are :--&amp;gt;&quot;&amp;lt;&amp;lt;endl;  
224:    g.printDijkastra();  
225:    return 0;  
226:  }  
&lt;/code&gt;&lt;/pre&gt;&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;For more info goto : &lt;/code&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-size: small; line-height: normal; white-space: normal;&quot;&gt;&lt;a href=&quot;http://securityresearch.in/beta/&quot;&gt;http://securityresearch.in/beta/&lt;/a&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ananyamallik.blogspot.com/feeds/3045171088679874562/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ananyamallik.blogspot.com/2010/10/implementation-of-dijkastra-in-c-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/3045171088679874562'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/3045171088679874562'/><link rel='alternate' type='text/html' href='http://ananyamallik.blogspot.com/2010/10/implementation-of-dijkastra-in-c-using.html' title='Implementation of Dijkastra in C++ Using STL'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04197657759022166885</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1270065828866707992.post-4935774651327895617</id><published>2010-10-21T07:17:00.000-07:00</published><updated>2010-10-21T07:31:00.675-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DAG CPP STL implementation"/><title type='text'>Implementation of Directed Acyclic Graph(DAG) in C++ using STL</title><content type='html'>&lt;pre  style=&quot;font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLNZ6kc4TgikP39S7UWlgzl4KZZ2nYHuX0diIOQs-W-IwMdXBYXDAPaSBtQIquA_rjtMqAjTMKv7AW5pOwV1bf5cVwI1ofN1MbEeKgQGoDc6cUxtcGSM_PLeRftCLylv974Eaxnh_O0geE/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;&quot;&gt;&lt;code style=&quot;color:#000000;word-wrap:normal;&quot;&gt;1:  //   DAG.cpp  
2:  //     
3:  //   Copyright 2010 ananya &amp;lt;ananya@ananya-laptop&amp;gt;  
4:  //     
5:  //   This program is free software; you can redistribute it and/or modify  
6:  //   it under the terms of the GNU General Public License as published by  
7:  //   the Free Software Foundation; either version 2 of the License, or  
8:  //   (at your option) any later version.  
9:  //     
10:  //   This program is distributed in the hope that it will be useful,  
11:  //   but WITHOUT ANY WARRANTY; without even the implied warranty of  
12:  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
13:  //   GNU General Public License for more details.  
14:  //     
15:  //   You should have received a copy of the GNU General Public License  
16:  //   along with this program; if not, write to the Free Software  
17:  //   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,  
18:  //   MA 02110-1301, USA.  
19:  #include &amp;lt;iostream&amp;gt;  
20:  #include &amp;lt;stdio.h&amp;gt;  
21:  #include &amp;lt;limits.h&amp;gt;  
22:  #include &amp;lt;map&amp;gt;  
23:  #include &amp;lt;vector&amp;gt;  
24:  #include &amp;lt;string&amp;gt;  
25:  #include &amp;lt;list&amp;gt;  
26:  #include &amp;lt;functional&amp;gt;  
27:  using namespace std;  
28:  struct Vertex;  
29:  struct Edge  
30:  {  
31:       Vertex *dest;  
32:       double cost;  
33:       Edge(Vertex *d=0,double c=0.0)  
34:        : dest(d),cost(c){}  
35:  };  
36:  struct Vertex  
37:  {   
38:       string name;  
39:       vector&amp;lt;Edge&amp;gt; adj;  
40:       double dist;  
41:       Vertex *prev;  
42:       unsigned int scratch;  
43:       Vertex(const string &amp;amp;nam):name(nam)  
44:       {reset();}  
45:       void reset()  
46:       {  
47:            dist=3000000;  
48:            prev=0;  
49:            scratch=0;  
50:    }       
51:  };  
52:  class Graph  
53:  {  
54:       public:  
55:            Graph(){};  
56:         ~Graph();  
57:         void addEdge(const string &amp;amp; sourceName,const string &amp;amp; destName,double cost);  
58:         void printPath(const string &amp;amp; destName) const;  
59:         bool dag(const string &amp;amp; startName);  
60:         void printdag();  
61:       private:  
62:         Vertex * getVertex(const string &amp;amp; vertexName);  
63:         void printPath(const Vertex &amp;amp; dest) const;  
64:         void clearAll();  
65:         typedef map&amp;lt;string,Vertex *,less&amp;lt;string&amp;gt; &amp;gt; vmap;  
66:         vmap vertexMap;  
67:  };  
68:  Graph::~Graph()  
69:  {  
70:       for(vmap::iterator itr=vertexMap.begin();itr!=vertexMap.end();++itr)  
71:            delete (*itr).second;  
72:  }  
73:  Vertex * Graph::getVertex(const string &amp;amp; vertexName)  
74:  {  
75:       vmap::iterator itr=vertexMap.find(vertexName);  
76:       if(itr==vertexMap.end())  
77:       {  
78:            Vertex *newv=new Vertex(vertexName);  
79:            vertexMap[vertexName]=newv;  
80:            return newv;  
81:       }  
82:       return (*itr).second;  
83:  }  
84:  void Graph::addEdge(const string &amp;amp; sourceName,  
85:            const string &amp;amp; destName,double cost)  
86:  {  
87:       Vertex *v=getVertex(sourceName);  
88:       Vertex *w=getVertex(destName);  
89:       v-&amp;gt;adj.push_back(Edge(w,cost));  
90:  }  
91:  void Graph::clearAll()  
92:  {  
93:       for(vmap::iterator itr=vertexMap.begin();itr!=vertexMap.end();++itr)  
94:            (*itr).second-&amp;gt;reset();  
95:  }  
96:  void Graph::printPath(const Vertex &amp;amp; dest) const  
97:  {  
98:       if(dest.prev!=0)  
99:       {  
100:            printPath(*dest.prev);  
101:            cout&amp;lt;&amp;lt;&quot; --&amp;gt;&quot;;  
102:       }  
103:       cout&amp;lt;&amp;lt;dest.name;  
104:  }  
105:  void Graph::printPath(const string &amp;amp;destName) const  
106:  {  
107:       vmap::const_iterator itr=vertexMap.find(destName);  
108:       if(itr==vertexMap.end())  
109:       {  
110:            cout&amp;lt;&amp;lt;destName&amp;lt;&amp;lt;&quot; not Found in Graph&quot;&amp;lt;&amp;lt;endl;  
111:            return;  
112:       }  
113:       Vertex &amp;amp; w =*(*itr).second;  
114:       if(w.dist==3000000)  
115:            cout&amp;lt;&amp;lt;destName&amp;lt;&amp;lt;&quot; is not rechable&quot;&amp;lt;&amp;lt;endl;  
116:       else  
117:       {  
118:            cout&amp;lt;&amp;lt;&quot;(Cost is: &quot;&amp;lt;&amp;lt;w.dist&amp;lt;&amp;lt; &quot;)&quot;;  
119:            printPath(w);  
120:       }  
121:       cout&amp;lt;&amp;lt;endl;  
122:  }  
123:  void Graph::printdag()  
124:  {  
125:       for(vmap::iterator itr =vertexMap.begin();itr!=vertexMap.end();++itr)  
126:        {  
127:            cout&amp;lt;&amp;lt;(*itr).first;  
128:            printPath((*itr).first);  
129:        }  
130:  }  
131:  bool Graph::dag(const string &amp;amp; startName)  
132:  {  
133:       vmap::iterator itr=vertexMap.find(startName);  
134:       if(itr==vertexMap.end())  
135:       {  
136:            cout&amp;lt;&amp;lt;&quot;Vertex not found&quot;&amp;lt;&amp;lt;endl;  
137:            return false;  
138:    }  
139:    clearAll();  
140:    Vertex *start=(*itr).second;  
141:    start-&amp;gt;dist=0;  
142:    list&amp;lt;Vertex *&amp;gt; q;  
143:    for(itr=vertexMap.begin();itr!=vertexMap.end();++itr)  //Computation of
144:    {                                                       //Indegree of each vertices
145:            Vertex *v =(*itr).second;                      // from line no.143 to 150
146:            for(unsigned int i=0;i&amp;lt;v-&amp;gt;adj.size();i++)  
147:            {  
148:                 v-&amp;gt;adj[i].dest-&amp;gt;scratch++;  
149:            }  
150:       }  
151:       for(itr=vertexMap.begin();itr!=vertexMap.end();++itr)  
152:       {  
153:            Vertex *v=(*itr).second;                 //Pushing the vertices in queue
154:            if(v-&amp;gt;scratch==0) 
155:            {                                       //Vertices wid indegree 0 are pushed 1st
156:                 q.push_back(v);  
157:            }  
158:       }  
159:       unsigned int y;  
160:       for(y=0;!q.empty();y++)  
161:       {  
162:            Vertex *v=q.front();                
163:            q.pop_front();  
164:            for(unsigned int i =0;i&amp;lt;v-&amp;gt;adj.size();i++)  
165:            {  
166:                 Edge e=v-&amp;gt;adj[i];  
167:                 Vertex *w=e.dest;  
168:                 double cvw=e.cost;  
169:                 if(--w-&amp;gt;scratch==0)  
170:                      q.push_back(w);          
171:                 if(v-&amp;gt;dist==3000000)  
172:                      continue;  
173:                 if(w-&amp;gt;dist&amp;gt;v-&amp;gt;dist+cvw)  
174:                 {  
175:                      w-&amp;gt;dist=v-&amp;gt;dist+cvw;  
176:                      w-&amp;gt;prev=v;  
177:                 }  
178:            }  
179:       }  
180:       if(y!=vertexMap.size())  
181:            {  
182:                 cout&amp;lt;&amp;lt;&quot;Cycle is there in the graph&quot;&amp;lt;&amp;lt;endl;  
183:                 return false;  
184:            }  
185:       else  
186:              return true;  
187:  }            
188:  int main(int argc, char** argv)  
189:  {  
190:       Graph g;  
191:       cout&amp;lt;&amp;lt;&quot;Enter the Graph description in following format:-&amp;gt;&quot;&amp;lt;&amp;lt;endl;  
192:       cout&amp;lt;&amp;lt;&quot;sourceName destName cost_of_Edge&quot;&amp;lt;&amp;lt;endl;  
193:       cout&amp;lt;&amp;lt;&quot;Enter the detail&quot;&amp;lt;&amp;lt;endl;  
194:       int a,cost;  
195:       a=1;  
196:       string sName,dName;  
197:       while(a==1)  
198:       {   
199:        cin&amp;gt;&amp;gt;sName&amp;gt;&amp;gt;dName&amp;gt;&amp;gt;cost;  
200:        g.addEdge(sName,dName,cost);  
201:        cout&amp;lt;&amp;lt;&quot;Wanna Continue(press 1/0):&quot;;  
202:        cin&amp;gt;&amp;gt;a;   
203:    }  
204:    cout&amp;lt;&amp;lt;&quot;Enter the source node:&quot;;  
205:    cin&amp;gt;&amp;gt;sName;  
206:    bool flag;  
207:    flag=g.dag(sName);  
208:    if(flag==true)  
209:    {  
210:       cout&amp;lt;&amp;lt;&quot;Shortest path to Distinct nodes are :--&amp;gt;&quot;&amp;lt;&amp;lt;endl;  
211:       g.printdag();  
212:       return 0;  
213:    }  
214:    else   
215:       return 0;  
216:  }  
&lt;/code&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://ananyamallik.blogspot.com/feeds/4935774651327895617/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ananyamallik.blogspot.com/2010/10/implementation-of-directed-acyclic.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/4935774651327895617'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/4935774651327895617'/><link rel='alternate' type='text/html' href='http://ananyamallik.blogspot.com/2010/10/implementation-of-directed-acyclic.html' title='Implementation of Directed Acyclic Graph(DAG) in C++ using STL'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04197657759022166885</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1270065828866707992.post-4424370153218454652</id><published>2010-09-23T09:36:00.001-07:00</published><updated>2010-09-23T09:36:48.487-07:00</updated><title type='text'>Politics Explained</title><content type='html'>During final semester of my engineering one of my friend was quite impressed with &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;COMMUNISM. &lt;/span&gt;I think right now he is drowning a considerable amount of effort for achieving communism in the society.He use to give us fair idea about current political system and social values.Initially i thought all of them as bull shit ,but gradually as time passed i started taking interest in different political system defined due date by&amp;nbsp;intellectual&amp;nbsp;human being or whatsoever is/was followed anywhere in world.&lt;br /&gt;
&lt;br /&gt;
Few of them i am going to quote in this article in simple generic sense :--&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;FEUDALISM&lt;/b&gt;&lt;/span&gt;: You have two cows. Your lord takes some of the milk.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;PURE SOCIALISM&lt;/span&gt;&lt;/b&gt;: You have two cows. The government takes them and puts them in a barn with everyone else&#39;s cows. You have to take care of all of the cows. The government gives you as much milk as you need.&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;BUREAUCRATIC SOCIALISM&lt;/span&gt;&lt;/b&gt;: You have two cows. The government takes them and put them in a barn with everyone else&#39;s cows. They are cared for by ex-chicken farmers. You have to take care of the chickens the government took from the chicken farmers. The government gives you as much milk and eggs as the regulations say you need.&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;FASCISM&lt;/span&gt;&lt;/b&gt;: You have two cows. The government takes both, hires you to take care of them and sells you the milk.&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;PURE COMMUNISM&lt;/span&gt;&lt;/b&gt;: You have two cows. Your neighbors help you take care of them, and you all share the milk.&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;RUSSIAN COMMUNISM&lt;/span&gt;&lt;/b&gt;: You have two cows. You have to take care of them, but the government takes all the milk.&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;CAMBODIAN COMMUNISM&lt;/span&gt;&lt;/b&gt;: You have two cows. The government takes both of them and shoots you.&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;DICTATORSHIP&lt;/span&gt;&lt;/b&gt;: You have two cows. The government takes both and drafts you.&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;PURE DEMOCRACY&lt;/span&gt;&lt;/b&gt;: You have two cows. Your neighbors decide who gets the milk.&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;REPRESENTATIVE DEMOCRACY&lt;/span&gt;&lt;/b&gt;: You have two cows. Your neighbors pick someone to tell you who gets the milk.&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;BUREAUCRACY&lt;/span&gt;&lt;/b&gt;: You have two cows. At first the government regulates what you can feed them and when you can milk them. Then it pays you not to milk them. Then it takes both, shoots one, milks the other and pours the milk down the drain. Then it requires you to fill out forms accounting for the missing cows.&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;PURE ANARCHY&lt;/span&gt;&lt;/b&gt;: You have two cows. Either you sell the milk at a fair price or your neighbors try to take the cows and kill you.&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;LIBERTARIAN/ANARCHO-CAPITALISM&lt;/span&gt;&lt;/b&gt;: You have two cows. You sell one and buy a bull.&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;SURREALISM&lt;/span&gt;&lt;/b&gt;: You have two giraffes. The government requires you to take harmonica lessons.&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ------------होप-------- रेअदेरस------- विल------ एन्जॉय-----------&lt;br /&gt;
&lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://ananyamallik.blogspot.com/feeds/4424370153218454652/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ananyamallik.blogspot.com/2010/09/politics-explained.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/4424370153218454652'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/4424370153218454652'/><link rel='alternate' type='text/html' href='http://ananyamallik.blogspot.com/2010/09/politics-explained.html' title='Politics Explained'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04197657759022166885</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1270065828866707992.post-7546221085726668034</id><published>2010-09-11T10:50:00.000-07:00</published><updated>2010-11-09T14:28:26.200-08:00</updated><title type='text'>How to Read Mathematics contd..</title><content type='html'>&lt;h2 style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: Arial; font-size: 12pt;&quot;&gt;An Example of Mathematical Writing&lt;/span&gt;&lt;/h2&gt;To allow an opportunity to experiment with the guidelines presented here, I am including a small piece of mathematics often called the birthday paradox.&amp;nbsp; The first part is a concise mathematical article explaining the problem and solving it.&amp;nbsp; The second is an imaginary Reader&#39;s attempt to understand the article by using the appropriate reading protocol.&amp;nbsp; This article’s topic is probability and is accessible to a bright and motivated reader with no background at all. &lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;The Birthday Paradox&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;A professor in a class of 30 random students offers to bet that there are at least two people in the class with the same birthday (month and day, but not necessarily year).&amp;nbsp; Do you accept the bet?&amp;nbsp; What if there were fewer people in the class?&amp;nbsp; Would you bet then? &lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Assume that the birthdays of &lt;i&gt;n&lt;/i&gt; people are uniformly distributed among 365 days of the year (assume no leap years for simplicity).&amp;nbsp; We prove that,&lt;/span&gt; &lt;span style=&quot;font-size: small;&quot;&gt;the probability that at least two of them have the same birthday (month and day) is equal to:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i53.tinypic.com/23le5bd.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://i53.tinypic.com/23le5bd.gif&quot; /&gt;&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;div style=&quot;text-align: right;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;span style=&quot;font-size: small;&quot;&gt;What is the chance that among 30 random people in a room, there are at least two or more with the same birthday?&amp;nbsp;&amp;nbsp; For &lt;i&gt;n &lt;/i&gt;= 30, the probability of at least one matching birthday is about 71%. This means that with 30 people in your class, the professor should win the bet 71 times out of 100 in the long run. It turns out that with 23 people, she should win about 50% of the time. &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Here is the proof: Let P(&lt;i&gt;n&lt;/i&gt;) be the probability in question.&amp;nbsp; Let Q(&lt;i&gt;n&lt;/i&gt;)&lt;i&gt; = &lt;/i&gt;1&lt;i&gt; – &lt;/i&gt;P(&lt;i&gt;n&lt;/i&gt;) be the probability that no two people have a common birthday.&amp;nbsp; Now calculate Q(&lt;i&gt;n&lt;/i&gt;) by calculating the number of &lt;i&gt;n&lt;/i&gt; birthdays without any duplicates and divide by the total number of &lt;i&gt;n&lt;/i&gt; possible birthdays.&amp;nbsp; Then solve for P(&lt;i&gt;n&lt;/i&gt;). &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;The total number of &lt;i&gt;n&lt;/i&gt; birthdays without duplicates is:&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;365 × 364 × 363 × ... × (365 – &lt;i&gt;n &lt;/i&gt;+ 1)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;This is because there are 365 choices for the first birthday, 364 for the next and so on for &lt;i&gt;n&lt;/i&gt; birthdays. The total number of &lt;i&gt;n&lt;/i&gt; birthdays without any restriction is just 365&lt;i&gt;&lt;sup&gt;n&lt;/sup&gt;&lt;/i&gt; because there are 365 choices for each of &lt;i&gt;n&lt;/i&gt; birthdays.&amp;nbsp; Therefore, Q(&lt;i&gt;n&lt;/i&gt;) equals&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt; &lt;b&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://i55.tinypic.com/15o797m.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://i55.tinypic.com/15o797m.gif&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Solving for P(&lt;i&gt;n&lt;/i&gt;) gives P(&lt;i&gt;n&lt;/i&gt;)&lt;i&gt; = &lt;/i&gt;1&lt;i&gt; – &lt;/i&gt;Q(&lt;i&gt;n&lt;/i&gt;) and hence our result.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;h3&gt;&lt;span style=&quot;font-family: Arial; font-size: 12pt;&quot;&gt;Reader Attempts to Understand the Birthday Paradox&lt;/span&gt;&lt;span style=&quot;font-family: Arial; font-size: 12pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;In this section, a naive Reader tries to make sense out of the last few paragraphs.&amp;nbsp; The Reader’s part is a metaphor for the Reader thinking out loud, and the Professional’s comments represent research on the Reader’s part.&amp;nbsp; The appropriate protocols are centered and bold at various points in the narrative. &lt;br /&gt;
My Reader may seem to catch on to things relatively quickly.&amp;nbsp; However, be assured that in reality a great deal of time passes between each of my Reader’s comments, and that I have left out many of the Reader’s remarks that explore dead-end ideas.&amp;nbsp; To experience what the Reader experiences requires much more than just reading through his/her lines. Think of his/her part as an outline for your own efforts. &lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;h3 align=&quot;center&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;Know urself&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;b&gt;Reader (R)&lt;/b&gt;: I don’t know anything about probability, can I still make it through? &lt;br /&gt;
&lt;b&gt;Professional (P)&lt;/b&gt;: Let’s give it a try. We may have to backtrack a lot at each step. &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: What does the phrase “30 random students” mean?&lt;br /&gt;
&lt;br /&gt;
&lt;h3 align=&quot;center&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;color: black; font-size: 12pt;&quot;&gt;&quot;When I use a word, it means just what I choose it to mean&quot;&lt;/span&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;b&gt;P&lt;/b&gt;: Good question.&amp;nbsp; It doesn’t mean that we have 30 spacy or scatter-brained people.&amp;nbsp; It means we should assume that the birthdays of these 30 people are independent of one another and that every birthday is equally likely for each person. The author writes this more technically a little further on:&amp;nbsp; “Assume that the birthdays of &lt;i&gt;n&lt;/i&gt; people are uniformly distributed among 365 days of the year.”&lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;:&amp;nbsp; Isn&#39;t that obvious?&amp;nbsp; Why bother saying that? &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Yes the assumption is kind of obvious.&amp;nbsp; The author is just setting the groundwork.&amp;nbsp; The sentence guarantees that everything is normal and the solution does not involve some imaginitive fanciful science-fiction.&amp;nbsp; &lt;br /&gt;
&lt;b&gt;R:&lt;/b&gt;&amp;nbsp; What do you mean?&lt;br /&gt;
&lt;b&gt;P:&lt;/b&gt;&amp;nbsp; For example, the author is &lt;i&gt;not &lt;/i&gt;looking for a solution like this:&amp;nbsp; everyone lives in &lt;st1:place w:st=&quot;on&quot;&gt;&lt;st1:placename w:st=&quot;on&quot;&gt;Independence&lt;/st1:placename&gt; &lt;st1:placetype w:st=&quot;on&quot;&gt;Land&lt;/st1:placetype&gt;&lt;/st1:place&gt; and is born on the 4&lt;sup&gt;th&lt;/sup&gt; of July, so the chance of two or more people with the same birthday is 100%.&amp;nbsp; That is not the kind of solution mathematicians enjoy.&amp;nbsp; Incidentally, the assumption also implies that we do not count leap years.&amp;nbsp; In particular, &lt;i&gt;nobody&lt;/i&gt; in this problem is born on February 29.&amp;nbsp; Continue reading. &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;:&amp;nbsp; I don’t understand that long formula, what’s &lt;i&gt;n&lt;/i&gt;? &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;:&amp;nbsp; The author is solving the problem for any number of people, not just for 30. The author, from now on, is going to call the number of people &lt;i&gt;n&lt;/i&gt;. &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;:&amp;nbsp; I still don&#39;t get it. So what&#39;s the answer? &lt;br /&gt;
&lt;h3 align=&quot;center&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;Don&#39;t Be a Passive Reader&amp;nbsp; -&amp;nbsp; Try Some Examples&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;b&gt;P&lt;/b&gt;:&amp;nbsp; Well, if you want the answer for 30, just set &lt;i&gt;n&lt;/i&gt; = 30. &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;:&amp;nbsp; Ok, but that looks complicated to compute.&amp;nbsp; Where’s my calculator?&amp;nbsp; Let’s see: 365 × 364 × 363 × ... × 336.&amp;nbsp; That’s tedious, and the final exact value won’t even fit on my calculator.&amp;nbsp; It reads:&lt;br /&gt;
&lt;div align=&quot;center&quot; style=&quot;text-align: center;&quot;&gt;2.1710301835085570660575334772481e+76&lt;/div&gt;If I can’t even calculate the answer once I know the formula, how can I possibly understand where the formula comes from? &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: You are right that this answer is inexact, but if you actually go on and do the division, your answer won’t be too far off.&amp;nbsp; &lt;br /&gt;
&lt;b&gt;R:&amp;nbsp; &lt;/b&gt;The whole thing makes me uncomfortable.&amp;nbsp; I would prefer to be able to calculate it more exactly.&amp;nbsp; Is there another way to do the calculation?&amp;nbsp; &lt;br /&gt;
&lt;b&gt;P:&amp;nbsp; &lt;/b&gt;How many terms in your product? How many terms in the product on the bottom? &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: You mean 365 is the first term and 364 is the second?&amp;nbsp; Then there are 30 terms. There are also 30 terms on the bottom, (30 copies of 365). &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Can you calculate the answer now? &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: Oh, I see.&amp;nbsp; I can pair up each top term with each bottom term, and do 365/365 as the first term, then multiply by 364/365, and so on for 30 terms.&amp;nbsp; This way the product never gets too big for my calculator. (After a few minutes)... Okay, I got 0.29368, rounded to 5 places. &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: What does this number mean? &lt;br /&gt;
&lt;h3 align=&quot;center&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;Don&#39;t Miss the Big Picture&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;b&gt;R&lt;/b&gt;: I forgot what I was doing. Let’s see. I was calculating the answer for &lt;i&gt;n &lt;/i&gt;= 30.&amp;nbsp; The 0.29368 is everything except for subtracting from 1.&amp;nbsp; If I keep going I get 0.70632. Now what does that mean? &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Knowing more about probability would help, but this simply means that the chance that two or more out of the 30 people have the same birthday is 70,632 out of 100,000 or about 71%. &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: That’s interesting. I wouldn’t have guessed that.&amp;nbsp; You mean that in my class with 30 students, there’s a pretty good chance that at least two students have the same birthday? &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;:&amp;nbsp; Yes that’s right.&amp;nbsp; You might want to take bets before you ask everyone their birthday. Many people don’t think that a duplicate will occur.&amp;nbsp; That’s why some authors call this the birthday &lt;i&gt;paradox.&lt;/i&gt; &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: So that’s why I should read mathematics, to make a few extra bucks? &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: I see how that might give you some incentive, but I hope the mathematics also inspires you without the monetary prospects. &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: I wonder what the answer is for other values of &lt;i&gt;n&lt;/i&gt;.&amp;nbsp; I will try some more calculations. &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: That’s a good idea. We can even make a picture out of all your calculations. We could plot a graph of the number of people versus the chance that a duplicate birthday occurs, but maybe this can be left for another time. &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: Oh look, the author did some calculations for me. He says that for &lt;i&gt;n&lt;/i&gt; = 30 the answer is about 71%;&amp;nbsp; that’s what I calculated too.&amp;nbsp; And, for &lt;i&gt;n&lt;/i&gt; = 23 it’s about 50%.&amp;nbsp; Does that make sense?&amp;nbsp; I guess it does.&amp;nbsp; The more people there are, the greater the chance of a common birthday.&amp;nbsp; Hey, I am anticipating the author. &amp;nbsp;Pretty good.&amp;nbsp; Okay, let’s go on. &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Good, now you’re telling &lt;i&gt;me&lt;/i&gt; when to continue. &lt;br /&gt;
&lt;h3 align=&quot;center&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;Don’t Read Too Fast&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;b&gt;R&lt;/b&gt;: It seems that we are up to the proof.&amp;nbsp; This must explain why that formula works.&amp;nbsp; What’s this Q(&lt;i&gt;n&lt;/i&gt;)?&amp;nbsp; I guess that P stands for probability but what does Q stand for? &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: The author is defining something new.&amp;nbsp; He is using Q just because it’s the next letter after P, but Q(&lt;i&gt;n&lt;/i&gt;) is also a probability, and closely related to P(&lt;i&gt;n&lt;/i&gt;).&amp;nbsp; It’s time to take a minute to think. What is Q(&lt;i&gt;n&lt;/i&gt;) and why is it equal to 1&lt;i&gt; – &lt;/i&gt;P(&lt;i&gt;n&lt;/i&gt;)? &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: Q(&lt;i&gt;n&lt;/i&gt;) is the probability that no two people have the same birthday.&amp;nbsp; Why does the author care about that?&amp;nbsp; Don’t we want the probability that at least two have the same birthday? &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Good point.&amp;nbsp; The author doesn’t tell you this explicitly, but between the lines, you can infer that he has no clue how to calculate P(&lt;i&gt;n&lt;/i&gt;) directly.&amp;nbsp; Instead, he introduces Q(&lt;i&gt;n&lt;/i&gt;) which supposedly equals 1&lt;i&gt; – &lt;/i&gt;P(&lt;i&gt;n&lt;/i&gt;).&amp;nbsp; Presumably, the author will proceed next to tell us how to compute Q(&lt;i&gt;n&lt;/i&gt;).&amp;nbsp; By the way, when you finish this article, you may want to deal with the problem of calculating P(&lt;i&gt;n&lt;/i&gt;) directly.&amp;nbsp; That’s a perfect follow up to the ideas presented here. &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: First things first. &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Ok. So once we know Q(&lt;i&gt;n&lt;/i&gt;), then what? &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: Then we can get P(&lt;i&gt;n&lt;/i&gt;).&amp;nbsp; Because if Q(&lt;i&gt;n&lt;/i&gt;)&lt;i&gt; = &lt;/i&gt;1&lt;i&gt; – &lt;/i&gt;P(&lt;i&gt;n&lt;/i&gt;), then P(&lt;i&gt;n&lt;/i&gt;)&lt;i&gt; = &lt;/i&gt;1&lt;i&gt; – &lt;/i&gt;Q(&lt;i&gt;n&lt;/i&gt;).&amp;nbsp; Fine, but why is Q(&lt;i&gt;n&lt;/i&gt;)&lt;i&gt; = &lt;/i&gt;1&lt;i&gt; – &lt;/i&gt;P(&lt;i&gt;n&lt;/i&gt;)?&amp;nbsp; Does the author assume this is obvious? &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Yes, he does, but what’s worse, he doesn’t even tell us that it is obvious.&amp;nbsp; Here’s a rule of thumb: when an author says &lt;i&gt;clearly this is true&lt;/i&gt; or &lt;i&gt;this is obvious&lt;/i&gt;, then take 15 minutes to convince yourself it is true.&amp;nbsp; If an author doesn’t even bother to say this, but just implies it, take a little longer. &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: How will I know when I should stop and think? &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Just be honest with yourself. When in doubt, stop and think. When too tired, go watch television. &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: So why is Q(&lt;i&gt;n&lt;/i&gt;) &lt;i&gt;= &lt;/i&gt;1&lt;i&gt; – &lt;/i&gt;P(&lt;i&gt;n&lt;/i&gt;)?&lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Let’s imagine a special case. If the chance of getting two or more of the same birthdays is 1/3, then what&#39;s the chance of not getting two or more? &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: It’s 2/3, because the chance of something not happening is the opposite of the chance of it happening. &lt;br /&gt;
&lt;h3 align=&quot;center&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;Make the Idea Your Own&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;b&gt;P&lt;/b&gt;: Well, you should be careful when you say things like &lt;i&gt;opposite&lt;/i&gt;, but you are right.&amp;nbsp; In fact, you have discovered one of the first rules taught in a course on probability.&amp;nbsp; Namely, that the probability that something will not occur is 1 minus the probability that it will occur.&amp;nbsp; Now go on to the next paragraph. &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: It seems to be explaining why Q(&lt;i&gt;n&lt;/i&gt;) is equal to long complex-looking formula shown.&amp;nbsp; I will never understand this. &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: The formula for Q(&lt;i&gt;n&lt;/i&gt;) is tough to understand and the author is counting on your diligence, persistence, and/or background here to get you through. &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: He seems to be counting all possibilities of something and dividing by the total possibilities, whatever that means.&amp;nbsp; I have no idea why. &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Maybe I can fill you in here on some background before you try to check out any more details.&amp;nbsp; The probability of the occurrence of a particular type of outcome is defined in mathematics to be: the total number of possible ways that type of outcome can occur divided by the total number of possible outcomes.&amp;nbsp; For example, the probability that you throw a four when throwing a die is 1/6. Because there is one possible 4, and there are six possible outcomes. What&#39;s the probability you throw a four or a three? &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: Well I guess 2/6 (or 1/3) because the total number of outcomes is still six but I have two possible outcomes that work. &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Good. Here’s a harder example. What about the chance of throwing a sum of four when you roll two dice?&amp;nbsp; There are three ways to get a four (1-3, 2-2, 3-1) while the total number of possible outcomes is 36.&amp;nbsp; That is 3/36 or 1/12.&amp;nbsp; Look at the following 6 by 6 table and convince yourself. &lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: 0.5in; margin-right: 0.5in;&quot;&gt;1-1, 1-2, 1-3, 1-4, 1-5, 1-6 &lt;/div&gt;&lt;div style=&quot;margin: 5pt 0.5in;&quot;&gt;2-1, 2-2, 2-3, 2-4, 2-5, 2-6 &lt;/div&gt;&lt;div style=&quot;margin: 5pt 0.5in;&quot;&gt;3-1, 3-2, 3-3, 3-4, 3-5, 3-6 &lt;/div&gt;&lt;div style=&quot;margin: 5pt 0.5in;&quot;&gt;4-1, 4-2, 4-3, 4-4, 4-5, 4-6&lt;/div&gt;&lt;div style=&quot;margin: 5pt 0.5in;&quot;&gt;5-1, 5-2, 5-3, 5-4, 5-5, 5-6&lt;/div&gt;&lt;div style=&quot;margin: 5pt 0.5in;&quot;&gt;6-1, 6-2, 6-3, 6-4, 6-5, 6-6&lt;/div&gt;&lt;br /&gt;
What about the probability of throwing a 7? &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;:&amp;nbsp; Wait.&amp;nbsp; What does 1-1 mean?&amp;nbsp; Doesn’t that equal 0?&lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;:&amp;nbsp; Sorry, my bad.&amp;nbsp; I was using the minus sign as a dash, just to mean a pair of numbers, so 1-1 means a roll of one on each die - snake eyes.&amp;nbsp; &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;:&amp;nbsp; Couldn’t you have come up with a better notation?&amp;nbsp; &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;:&amp;nbsp; Well maybe I could/should have, but commas would look worse, a slash would look like division, and anything else might be just as confusing.&amp;nbsp; We aren’t going to publish this transcript anyway.&lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;:&lt;b&gt;&amp;nbsp; &lt;/b&gt;That’s a relief.&lt;b&gt;&amp;nbsp; &lt;/b&gt;Well, I know what you mean now.&amp;nbsp; To answer your question, I can get a seven in six ways via 1-6, 2-5, 3-4, 4-3, 5-2, or 6-1.&amp;nbsp; The total number of outcomes is still 36, so I get 6/36 or 1/6.&amp;nbsp; That’s weird, why isn’t the chance of rolling a 4 the same as for rolling a 7?&amp;nbsp; &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Because not every sum is equally likely.&amp;nbsp; The situation would be very different if we were simply spinning a wheel with the sums 2 through 12 listed in equally spaced intervals.&amp;nbsp; In that case, each one of the 11 sums would have probability 1/11.&lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: Okay, now I am an expert. Is probability just about counting? &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Sometimes, yes.&amp;nbsp; But counting things is not always so easy. &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: I see, let’s go on.&amp;nbsp; By the way, did the author really expect me to know all this?&amp;nbsp; My friend took Probability and Statistics and I am not sure he knows all this stuff. &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: There’s a lot of information implied in a small bit of mathematics. Yes, the author expected you to know all this, or to discover it yourself just as we have done.&amp;nbsp; If I hadn’t been here, you would have had to ask yourself these questions and answer them by thinking, looking in a reference book, or consulting a friend. &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: So the chance that there are no two people with the same birthday is the number of possible sets of &lt;i&gt;n&lt;/i&gt; birthdays without a duplicate divided by the total number of possible sets of &lt;i&gt;n&lt;/i&gt; birthdays.&amp;nbsp; &lt;br /&gt;
&lt;b&gt;P:&amp;nbsp; &lt;/b&gt;Excellent summary.&lt;br /&gt;
&lt;b&gt;R: &lt;/b&gt;I don’t like using &lt;i&gt;n&lt;/i&gt;, so let me use 30. Perhaps the generalization to &lt;i&gt;n&lt;/i&gt; will be easy to see. &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Great idea.&amp;nbsp; It is often helpful to look at a special case before understanding the general case. &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: So how many sets of 30 birthdays are there total?&amp;nbsp; I can’t do it. I guess I need to restrict my view even more. Let’s pretend there are only two people. &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Fine. Now you’re thinking like a mathematician.&amp;nbsp; Let’s try &lt;i&gt;n&lt;/i&gt; = 2.&amp;nbsp; How many sets of two birthdays are there total? &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: I number the birthdays from 1 to 365 and forget about leap years. Then these are the all the possibilities: &lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: 0.5in; margin-right: 0.5in;&quot;&gt;1-1, 1-2, 1-3, ... , 1-365, &lt;/div&gt;&lt;div style=&quot;margin: 5pt 0.5in;&quot;&gt;2-1, 2-2, 2-3, ... , 2-365, &lt;/div&gt;&lt;div style=&quot;margin: 5pt 0.5in;&quot;&gt;... &lt;/div&gt;&lt;div style=&quot;margin: 5pt 0.5in;&quot;&gt;365-1, 365-2, 365-3, ... , 365-365.&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: When you write 1-1, do you mean 1-1 = 0, as in subtraction?&lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;:&lt;b&gt; &lt;/b&gt;Stop teasing me.&amp;nbsp; You know exactly what I mean.&lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: &lt;b&gt;&amp;nbsp;&lt;/b&gt;Yes I do, and nice choice of notation I might add.&amp;nbsp; Now how many pairs of birthdays are there? &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: There are 365 × 365 total possibilities for two people. &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: And how many are there when there are no duplicate birthdays? &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: I can’t use 1-1, or 2-2, or 3-3 or ... 365-365, so I get &lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: 0.5in; margin-right: 0.5in;&quot;&gt;1-2, 1-3, ... , 1-365, &lt;/div&gt;&lt;div style=&quot;margin: 5pt 0.5in;&quot;&gt;2-1, 2-3, ... , 2-365, &lt;/div&gt;&lt;div style=&quot;margin: 5pt 0.5in;&quot;&gt;... &lt;/div&gt;&lt;div style=&quot;margin: 5pt 0.5in;&quot;&gt;365-1, 365-2, ... , 365-364&lt;/div&gt;The total number here is 365 × 364 since each row now has 364 pairs instead of 365. &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Good. You are going a little quickly here, but you’re 100% right. Can you generalize now to 30?&amp;nbsp; What is the total number of possible sets of 30 birthdays?&amp;nbsp; Take a guess. You’re getting good at this. &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: Well if I had to guess, (it’s not really a guess, after all, I already know the formula), I would say that for 30 people you get 365 × 365 ×... × 365, 30 times, for the total number of possible sets of birthdays. &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Exactly. Mathematicians write 365&lt;sup&gt;30&lt;/sup&gt;.&amp;nbsp; And what is the number of possible sets of 30 birthdays without any duplicates? &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: I know the answer &lt;i&gt;should&lt;/i&gt; be 365 × 364 × 363 × 362 × ... × 336, (that is, start at 365 and multiply by one less for 30 times), but I am not sure I really see why this is true. Perhaps I should do the case with three people first, and work my way up to 30? &lt;br /&gt;
&lt;b&gt;P&lt;/b&gt;: Splendid idea.&amp;nbsp; Let’s quit for today.&amp;nbsp; The whole picture is there for you. When you are rested and you have more time, you can come back and fill in that last bit of understanding. &lt;br /&gt;
&lt;b&gt;R&lt;/b&gt;: Thanks a lot; it’s been an experience. Later.&lt;/div&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ananyamallik.blogspot.com/feeds/7546221085726668034/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ananyamallik.blogspot.com/2010/09/how-to-read-mathematics-contd.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/7546221085726668034'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/7546221085726668034'/><link rel='alternate' type='text/html' href='http://ananyamallik.blogspot.com/2010/09/how-to-read-mathematics-contd.html' title='How to Read Mathematics contd..'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04197657759022166885</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://i53.tinypic.com/23le5bd_th.gif" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1270065828866707992.post-7840789146552459347</id><published>2010-09-10T03:37:00.000-07:00</published><updated>2010-09-10T03:48:03.314-07:00</updated><title type='text'>How to Read Mathematics</title><content type='html'>&lt;h4 style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 12pt; font-weight: bold; margin-bottom: 0.0001pt; margin-left: 0.5in; margin-right: 0in; margin-top: 0in; page-break-after: avoid; text-align: center;&quot;&gt;&lt;i&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&quot;Mathematics is “a language that can neither be read nor understood without initiation.”&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/h4&gt;&lt;div&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 12pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 12pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: justify;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;A&amp;nbsp;&lt;i&gt;reading protocol&amp;nbsp;&lt;/i&gt;is a set of strategies that a reader must use in order to benefit fully from reading the text. Poetry calls for a different set of strategies than fiction, and fiction a different set than non-fiction. It would be ridiculous to&amp;nbsp;&lt;i&gt;read&lt;/i&gt;&amp;nbsp;fiction and ask oneself what is the author&#39;s source for the assertion that the hero is blond and tanned; it would be wrong to&amp;nbsp;&lt;i&gt;read&lt;/i&gt;&amp;nbsp;non-fiction and not ask such a question.&amp;nbsp; This reading protocol extends to a&amp;nbsp;&lt;i&gt;viewing&lt;/i&gt;&amp;nbsp;or&amp;nbsp;&lt;i&gt;listening&lt;/i&gt;&amp;nbsp;protocol in art and music. Indeed, much of the introductory course material in literature, music and art is spent teaching these protocols.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 12pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: justify;&quot;&gt;&amp;nbsp;&amp;nbsp;Mathematics has a reading protocol all its own, and just as we learn to read literature, we should learn to read mathematics.&amp;nbsp;&amp;nbsp;Students need to learn how to read mathematics, in the same way they learn how to read a novel or a poem, listen to music, or view a painting.&amp;nbsp;&amp;nbsp;Ed Rothstein’s book,&amp;nbsp;&lt;i&gt;Emblems of Mind&lt;/i&gt;, a fascinating book emphasizing the relationship between mathematics and music, touches implicitly on the reading protocols for mathematics.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 12pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: justify;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;When we read a novel we become absorbed in the plot and characters.&amp;nbsp;&amp;nbsp;We try to follow the various plot lines and how each affects the development of the characters.&amp;nbsp;&amp;nbsp;We make sure that the characters become real people to us, both those we admire and those we despise.&amp;nbsp;&amp;nbsp;We do not stop at every word, but imagine the words as brushstrokes in a painting.&amp;nbsp;&amp;nbsp;Even if we are not familiar with a particular word, we can still see the whole picture.&amp;nbsp;&amp;nbsp;We rarely stop to think about individual phrases and sentences. Instead, we let the novel sweep us along with its flow and carry us swiftly to the end.&amp;nbsp;&amp;nbsp;The experience is rewarding, relaxing and thought provoking.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 12pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: justify;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Mathematical ideas are by nature precise and well defined, so that a precise description is possible in a very short space.&amp;nbsp;&amp;nbsp;Both a mathematics article and a novel are telling a story and developing complex ideas, but a math article does the job with a tiny fraction of the words and symbols of those used in a novel.&amp;nbsp;&amp;nbsp;The beauty in a novel is in the aesthetic way it uses language to evoke emotions and present themes which defy precise definition.&amp;nbsp;&amp;nbsp;The beauty in a mathematics article is in the elegant efficient way it concisely describes precise ideas of great complexity.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 12pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 12pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 12pt; margin-left: 0in; margin-right: 0in;&quot;&gt;What are the common mistakes people make in trying to read mathematics?&amp;nbsp;&amp;nbsp;How can these mistakes be corrected?&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 12pt; margin-left: 0in; margin-right: 0in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 12pt; margin-left: 0in; margin-right: 0in; text-align: center;&quot;&gt;&lt;i&gt;“Reading Mathematics is not at all a linear experience ...Understanding the text requires cross references, scanning, pausing and revisiting”&amp;nbsp;&lt;/i&gt;&lt;/div&gt;&amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 12pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; text-align: justify;&quot;&gt;&lt;/div&gt;&lt;h3 style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 13.5pt; font-weight: bold; margin-left: 0in; margin-right: 0in;&quot;&gt;&lt;span style=&quot;font-family: Arial; font-size: 12pt;&quot;&gt;Don’t be a Passive Reader&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 12pt; margin-left: 0.5in; margin-right: 0in; text-align: center;&quot;&gt;&lt;i&gt;“A three-line proof of a subtle theorem is the distillation of years of activity.&amp;nbsp;&amp;nbsp;&lt;st1:city w:st=&quot;on&quot;&gt;&lt;st1:place w:st=&quot;on&quot;&gt;Reading&lt;/st1:place&gt;&lt;/st1:city&gt;&amp;nbsp;mathematics… involves a return to the thinking that went into the writing”&lt;/i&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 12pt; margin-left: 0.5in; margin-right: 0in; text-align: center;&quot;&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 12pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;Mathematics says a lot with a little.&amp;nbsp;&amp;nbsp;The reader must participate.&amp;nbsp;&amp;nbsp;At every stage, he/she must decide whether or not the idea being presented is clear.&amp;nbsp;&amp;nbsp;Ask yourself these questions:&lt;/div&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;margin-left: 40px;&quot;&gt;Why is this idea true?&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;Do I really believe it?&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;Could I convince someone else that it is true?&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;Why didn&#39;t the author use a different argument?&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;Do I have a better argument or method of explaining the idea?&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;Why didn&#39;t the author explain it the way that I understand it?&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;Is my way wrong?&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;Do I really get the idea?&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;Am I missing some subtlety?&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;Did this author miss a subtlety?&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;If I can&#39;t understand the point, perhaps I can understand a similar but simpler idea?&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;Which simpler idea?&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;Is it really necessary to understand this idea?&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;Can I accept this point without understanding the details of why it is true?&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;Will my understanding of the whole story suffer from not understanding why the point is true?&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 12pt; margin-left: 0in; margin-right: 0in;&quot;&gt;Putting too little effort into this participation is like reading a novel without concentrating.&amp;nbsp;&amp;nbsp;After half an hour, you wake up to realize the pages have turned, but you have been daydreaming and don’t remember a thing you read.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;h3 style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 13.5pt; font-weight: bold; margin-left: 0in; margin-right: 0in;&quot;&gt;&lt;span style=&quot;font-family: Arial; font-size: 12pt;&quot;&gt;Don’t Read Too Fast&lt;/span&gt;&lt;/h3&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;h3 style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 13.5pt; font-weight: bold; margin-left: 0in; margin-right: 0in;&quot;&gt;&lt;span style=&quot;font-family: Arial; font-size: 12pt;&quot;&gt;Make the Idea your Own&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span style=&quot;font-family: Arial; font-size: 12pt;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Arial; font-size: 12pt;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Arial; font-size: 12pt;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Arial; font-size: 12pt;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial; font-size: 12pt;&quot;&gt;&lt;h2 style=&quot;font-family: &#39;Times New Roman&#39;; font-size: 18pt; font-weight: bold; margin-left: 0in; margin-right: 0in;&quot;&gt;&lt;span style=&quot;font-family: Arial; font-size: 12pt;&quot;&gt;An Example of Mathematical Writing&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;span style=&quot;font-family: Arial; font-size: 12pt;&quot;&gt;&amp;nbsp;&amp;nbsp;---example will be presented in the next article &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial; font-size: 12pt;&quot;&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; &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; &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; &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; --Shai Simpson&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ananyamallik.blogspot.com/feeds/7840789146552459347/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ananyamallik.blogspot.com/2010/09/how-to-read-mathematics.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/7840789146552459347'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1270065828866707992/posts/default/7840789146552459347'/><link rel='alternate' type='text/html' href='http://ananyamallik.blogspot.com/2010/09/how-to-read-mathematics.html' title='How to Read Mathematics'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/04197657759022166885</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>