<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Priyanka Yadav</title>
    <description>The latest articles on DEV Community by Priyanka Yadav (@priyanka__488).</description>
    <link>https://dev.to/priyanka__488</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F329672%2Fa430cc0c-2f0d-42b6-b28f-d7b8f64a272c.jpg</url>
      <title>DEV Community: Priyanka Yadav</title>
      <link>https://dev.to/priyanka__488</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/priyanka__488"/>
    <language>en</language>
    <item>
      <title>Number Theory: Primality Test in O(sqrt(n))</title>
      <dc:creator>Priyanka Yadav</dc:creator>
      <pubDate>Wed, 25 Mar 2020 03:48:23 +0000</pubDate>
      <link>https://dev.to/priyanka__488/number-theory-primality-test-in-o-sqrt-n-dde</link>
      <guid>https://dev.to/priyanka__488/number-theory-primality-test-in-o-sqrt-n-dde</guid>
      <description>&lt;p&gt;A number is said to be prime if it is divisible by a number other than 1 and itself.&lt;br&gt;
&lt;b&gt; 1 is not considered to be a prime number.&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Primality Test&lt;/code&gt; is to determine whether the input integer is a prime number or not.&lt;/p&gt;

&lt;p&gt;For instance,&lt;/p&gt;

&lt;p&gt;5: Prime Number&lt;br&gt;
12: Not a prime number&lt;br&gt;
7: Prime Number&lt;br&gt;
14: Not a prime number&lt;/p&gt;

&lt;p&gt;For instance, 12 is prime because it is divisible by 2,3 and 6.&lt;/p&gt;
&lt;h2&gt;
  
  
  Approach 1
&lt;/h2&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bool isPrime(int n) {

  if (n == 1) {
    return false;
  }

  for (int i = 2; i &amp;lt; n; i++) {
    if (n % i == 0) return false;
  }

  return true;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;In this method, we traverse from 1 to n, hence the time complexity, in this case, is: &lt;code&gt;O(n)&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Approach 2: The Better One
&lt;/h2&gt;

&lt;p&gt;Now, consider a pair &lt;code&gt;a*b = n&lt;/code&gt;. Here, a and b are the factors of n.&lt;br&gt;
For instance,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;n = 12
(a,b) can be (1,12),(2,6),(3,4)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;On observing the equation, we can infer that the maximum value of a and b can be the square root of n.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sqrt(n)*sqrt(n) = n&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Since, if both of the values go beyond &lt;code&gt;sqrt(n)&lt;/code&gt;, then &lt;code&gt;a*b&lt;/code&gt; would be greater than n.&lt;/p&gt;

&lt;p&gt;Also, If a is less than &lt;code&gt;sqrt(n)&lt;/code&gt;, then b will be greater then &lt;code&gt;sqrt(n)&lt;/code&gt;.&lt;br&gt;
Similarly, if a is greater than &lt;code&gt;sqrt(n)&lt;/code&gt;, b will be smaller than &lt;code&gt;sqrt(n)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We can conclude that one of the numbers is &lt;code&gt;&amp;lt;= sqrt(n)&lt;/code&gt;, and the other one is &lt;code&gt;&amp;gt;= sqrt(n)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And to prove that n is prime, we just need to find one of the numbers - a or b.&lt;br&gt;
If no such number exists, it means that n is not prime.&lt;/p&gt;

&lt;p&gt;Hence, to do the primality test, we need not run loop till n, this can be done by running the loop till &lt;code&gt;sqrt(n)&lt;/code&gt; itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bool isPrime(int n) {

  if (n == 1) {
    return false;
  }

  for (int i = 2; i*i &amp;lt; n; i++) {
    if (n % i == 0) return false;
  }

  return true;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; Using the libraries such as &lt;code&gt;sqrt()&lt;/code&gt; can sometimes give unexpected values. Hence, instead of checking for &lt;code&gt;i &amp;lt; sqrt(n)&lt;/code&gt; in the for loop, we check for &lt;code&gt;i*i&amp;lt; n&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The loop runs from 2 to &lt;code&gt;sqrt(n)&lt;/code&gt;, hence the time complexity would be &lt;code&gt;O(sqrt(n))&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Keep Coding! :)&lt;/p&gt;

</description>
      <category>numbertheory</category>
      <category>datastructures</category>
    </item>
    <item>
      <title>Internet vs World Wide Web vs Intranet</title>
      <dc:creator>Priyanka Yadav</dc:creator>
      <pubDate>Thu, 06 Feb 2020 13:46:56 +0000</pubDate>
      <link>https://dev.to/priyanka__488/internet-vs-world-wide-web-vs-intranet-3kfh</link>
      <guid>https://dev.to/priyanka__488/internet-vs-world-wide-web-vs-intranet-3kfh</guid>
      <description>&lt;p&gt;If you consider Internet as a highway system, you can consider www as a package delivery system that uses that highway.&lt;/p&gt;

&lt;h3&gt;
  
  
  Internet
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;global network of networks or&lt;/li&gt;
&lt;li&gt;global data communication system&lt;/li&gt;
&lt;li&gt;provides an infrastructure&lt;/li&gt;
&lt;li&gt;refers mostly to hardware, networks, computer etc.&lt;/li&gt;
&lt;li&gt;can be accessed by anyone, is public&lt;/li&gt;
&lt;li&gt;provides unlimited information&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  World Wide Web (www)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;collection of information that is accessed via Internet&lt;/li&gt;
&lt;li&gt;repository of common resources that can be accessed via the internet.&lt;/li&gt;
&lt;li&gt;a service that operates on top of the Internet ( infrastructure )&lt;/li&gt;
&lt;li&gt;can be referred as a software&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Internet is a public network, while Intranet is a private network.&lt;/p&gt;

&lt;h3&gt;
  
  
  Intranet
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;a private network for information management and sharing among only the members or employees&lt;/li&gt;
&lt;li&gt;cannot be accessed by everyone&lt;/li&gt;
&lt;li&gt;limited number of users with limited information&lt;/li&gt;
&lt;li&gt;owned by private firms&lt;/li&gt;
&lt;li&gt;is safe as compared to Internet&lt;/li&gt;
&lt;li&gt;Example : IT Department intranet, HR Intranet.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>internet</category>
      <category>www</category>
      <category>intranet</category>
    </item>
  </channel>
</rss>
