<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Himal's Blog]]></title><description><![CDATA[Himal's Blog]]></description><link>https://www.himal-acharya.com.np</link><generator>RSS for Node</generator><lastBuildDate>Thu, 30 Apr 2026 06:26:18 GMT</lastBuildDate><atom:link href="https://www.himal-acharya.com.np/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA["Big O, Big Impact: A Simple Guide to Time Complexity and base of DSA"]]></title><description><![CDATA[Sending high storage game to a Friend: The 5KM, 60GB Challenge!
Final exams are done. Your buddy lives just 5 km away, and you want to gift him a copy of GTA V — all 60 GB of it.
Both of you have “awesome” 4G connections... but there’s a catch:👉 1 G...]]></description><link>https://www.himal-acharya.com.np/big-o-big-impact-a-simple-guide-to-time-complexity-and-base-of-dsa</link><guid isPermaLink="true">https://www.himal-acharya.com.np/big-o-big-impact-a-simple-guide-to-time-complexity-and-base-of-dsa</guid><category><![CDATA[Computer Science]]></category><dc:creator><![CDATA[HIMAL]]></dc:creator><pubDate>Sat, 21 Jun 2025 16:36:52 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/Jztmx9yqjBw/upload/bc5a53ed83a47c3549fecc4e9b1dd2d3.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>Sending high storage game to a Friend: The 5KM, 60GB Challenge!</strong></p>
<p>Final exams are done. Your buddy lives just 5 km away, and you want to gift him a copy of GTA V — all <strong>60 GB</strong> of it.</p>
<p>Both of you have <em>“awesome”</em> 4G connections... but there’s a catch:<br />👉 <strong>1 GB/day data limit!</strong></p>
<p>So... how on earth do you send that massive game over?<br />💡 Will you:</p>
<ul>
<li><p>Burn it to a USB stick and bike it over?</p>
</li>
<li><p>Wait two months using your data plan?</p>
</li>
<li><p>Find a clever offline or local network hack?</p>
</li>
</ul>
<p>Let’s break it down!</p>
<p>The best way to send him the game is by copying the game to a Hard disk and send it, Will yo do the same thing for Sending a game like minesweeper which is in kb of size ? No because you can send it via internet. As the file size grows, time taken by online Sending increases linearly f(n’). As the file size grows, time taken by physical sending remains Constant. For example if your friend is 10 min away it will always take 10 min whether it is 5gb, 50gb or 100gb but may be more efficient in case of low end game like minesweeper which takes mins. Same goes in case of designing algorithm. If you don’t know what is algorithm, It is a process of implementing you logic in program which can differ from person to person since one problem can have multiple solution.</p>
<h2 id="heading-why-it-matters">Why it matters?</h2>
<p>Similar to above example, In real world, Computer’s memory usage and processor usage is precious. For this efficient data structure and algorithm has to be used. For example, You want to check whether number is prime or not for example 8 in this case. The first algo that comes in mind is dividing number from 2 to 8, if any number divides or gives remainder ‘0’ from 2 to 8 then its not prime excluding 8. You can easily implement this logic in your code but if i said you should generate best possible logic which takes minimum operation then it can hinder you sometime. <strong>This is where algorithm comes to play and every problem has it best solutions and worst too. In this case of prime number, you can divide 8 from 2 to 4, since there is no any number 8 can be divided greater than 4 except itself. You may say why it matters it only saves 4 operation but in case of ‘8164427721659987003’ it saves ‘4082213860829993501’ many operation using this logic. <em>Similarly, there is best possible way to do it in this case nut it not the best but isn’t the worst.</em></strong></p>
<h2 id="heading-time-complexity"><strong>Time complexity</strong></h2>
<p>This type of algorithm can be measured in mathematical equation. The best Algorithm is measured in worst case scenario which called time complexity and space complexity. Most people think ‘Time Complexity” is a amount of time it takes to give output given problem but it is not. The same Algorithm might perform fast depending upon system and specification. In Reality, It doesn’t measure actual seconds, but instead shows <strong>how the number of operations increases</strong> when the input gets bigger.</p>
<p>It is measured in mathematical equation like linear, quadratic, exponential and so on using Big O notation “O”. The diagram below contains detail explanation.</p>
<p><img src="https://jaro-website.s3.ap-south-1.amazonaws.com/2024/06/0_ouBkTMgA_yg_Etfz.png" alt="Time Complexity And Why Is It Essential? | Jaro Education" /></p>
<h3 id="heading-what-is-big-o"><strong>What is Big O?</strong></h3>
<p>👉<strong>Big O notation</strong> is a way to describe <strong>how the runtime or space used by an algorithm grows</strong> as the size of the input (usually called <code>n</code>) increases.</p>
<p>It tells us:</p>
<ul>
<li><p>The <strong>upper bound</strong> (worst-case scenario) of an algorithm’s performance.</p>
</li>
<li><p>How the algorithm <strong>scales</strong> when the input gets really big.</p>
</li>
</ul>
<hr />
<h3 id="heading-example-of-big-o-types">Example of Big O Types</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Big O</td><td>Meaning</td><td>Example</td></tr>
</thead>
<tbody>
<tr>
<td><strong>O(1)</strong></td><td>Constant time → time doesn’t change as input grows</td><td>Accessing an array element by index</td></tr>
<tr>
<td><strong>O(log n)</strong></td><td>Logarithmic time → input size shrinks each step</td><td>Binary search</td></tr>
<tr>
<td><strong>O(n)</strong></td><td>Linear time → time grows directly with input</td><td>Looping through a list</td></tr>
<tr>
<td><strong>O(n log n)</strong></td><td>Linearithmic → faster than O(n²), used in efficient sorts</td><td>Merge sort</td></tr>
<tr>
<td><strong>O(n²)</strong></td><td>Quadratic → time grows fast (nested loops)</td><td>Checking all pairs</td></tr>
<tr>
<td><strong>O(2ⁿ)</strong></td><td>Exponential → time doubles with each extra input</td><td>Solving the traveling salesman brute-force</td></tr>
<tr>
<td><strong>O(n!)</strong></td><td>Factorial → extremely slow for large n</td><td>Generating all permutations</td></tr>
</tbody>
</table>
</div><hr />
<h3 id="heading-key-idea">Key Idea</h3>
<p>Big O <strong>hides constants</strong> and focuses on the part that grows fastest as <code>n</code> increases.<br />Example: <code>5n + 100</code> → Big O = <strong>O(n)</strong> (because <code>n</code> is the dominant term)</p>
]]></content:encoded></item><item><title><![CDATA[What Is an API?]]></title><description><![CDATA[In today’s digital world, apps and websites often talk to each other. This communication happens through something called an API — short for Application Programming Interface.
What Does an API Do?
An API is like a messenger.

It sends your request to...]]></description><link>https://www.himal-acharya.com.np/what-is-an-api</link><guid isPermaLink="true">https://www.himal-acharya.com.np/what-is-an-api</guid><category><![CDATA[Programming Blogs]]></category><dc:creator><![CDATA[HIMAL]]></dc:creator><pubDate>Wed, 11 Jun 2025 18:15:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/HFALfcK9jsw/upload/5766b8f44bd8b4786821c8728228b9c7.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In today’s digital world, apps and websites often <strong>talk to each other</strong>. This communication happens through something called an <strong>API</strong> — short for <strong>Application Programming Interface</strong>.</p>
<h3 id="heading-what-does-an-api-do">What Does an API Do?</h3>
<p>An API is like a <strong>messenger</strong>.</p>
<ul>
<li><p>It <strong>sends your request</strong> to another system.</p>
</li>
<li><p>It <strong>brings back the answer</strong> so your app can show it.</p>
</li>
</ul>
<p>Imagine you open a food delivery app and want to see pizza shops nearby.</p>
<ul>
<li><p>Your app sends a request through an API to a server.</p>
</li>
<li><p>The server sends back a list of shops.</p>
</li>
<li><p>The app shows it to you.</p>
</li>
</ul>
<h2 id="heading-how-does-an-api-work">How Does an API Work?</h2>
<p>You (the user or app) <strong>send a request</strong> → “Give me data!”<br />The API <strong>takes the request</strong> → Goes to the server.<br />The server <strong>processes it</strong> → Finds the data.<br />The API <strong>returns the result</strong> → App displays it.</p>
<h3 id="heading-common-api-terms">Common API Terms</h3>
<table><tbody><tr><td><p><strong>Request</strong></p></td><td><p>The data your app sends to the API</p></td></tr></tbody></table>

<table><tbody><tr><td><p><strong>Response</strong></p></td><td><p>The data the API sends back</p></td></tr></tbody></table>

<table><tbody><tr><td><p><strong>Endpoint</strong></p></td><td><p>The specific URL where the API listens</p></td></tr></tbody></table>

<table><tbody><tr><td><p><strong>JSON</strong></p></td><td><p>A common format for API data (looks like <code>{ "name": "Nepal" }</code>)</p></td></tr></tbody></table>

<h2 id="heading-why-do-we-need-the-api">Why do we need the API</h2>
<p>Imagine you’re building a food delivery app.</p>
<ul>
<li><p>You want to <strong>show the user’s location on a map</strong>.</p>
</li>
<li><p>You want to <strong>find nearby pizza shops</strong>.</p>
</li>
<li><p>You want to <strong>draw the delivery route</strong>.</p>
</li>
</ul>
<p>Could you build your own map system?<br />That would take years, cost millions, and need constant updates.</p>
<p>Instead, you use <strong>Google Maps API</strong></p>
<ul>
<li><p>Your app asks Google Maps: <em>“Where is this address?”</em></p>
</li>
<li><p>Google Maps API responds with the location, shops, route, etc.</p>
</li>
<li><p>Your app shows the map, markers, and route — easy!</p>
</li>
</ul>
<p>This is one example of API call:</p>
<pre><code class="lang-plaintext">GET https://api.weather.com/v3/weather/forecast?location=Kathmandu
</code></pre>
<p>This is how it’s response can look which we use as how we want to use in our case:</p>
<pre><code class="lang-plaintext">{
  "location": "Kathmandu",
  "forecasts": [
    {
      "day": "Monday",
      "high_temp_c": 28,
      "low_temp_c": 18,
      "description": "Partly cloudy"
    }
  ]
}
</code></pre>
<p>Moreover, An API is secured by using <strong>API keys</strong> so only authorized apps can access it. To prevent overuse, <strong>throttling (rate limiting)</strong> controls how many requests are allowed in a time period, like 100 requests per minute. Common throttling methods include <strong>fixed window</strong> and <strong>token bucket</strong>.</p>
<p><em>This keeps the API safe, reliable, and fair.</em></p>
]]></content:encoded></item><item><title><![CDATA[“How AI APIs Work: Response Types, Hallucination, and How to Handle Them”]]></title><description><![CDATA[What Are AI APIs?
AI APIs are cloud-based interfaces that allow us to access and use artificial intelligence models — like language, vision, or speech models — without needing to train or host them on their own servers.
Think of AI APIs as a teacher ...]]></description><link>https://www.himal-acharya.com.np/how-ai-apis-work-response-types-hallucination-and-how-to-handle-them</link><guid isPermaLink="true">https://www.himal-acharya.com.np/how-ai-apis-work-response-types-hallucination-and-how-to-handle-them</guid><category><![CDATA[AI]]></category><category><![CDATA[Programming Blogs]]></category><dc:creator><![CDATA[HIMAL]]></dc:creator><pubDate>Sat, 31 May 2025 15:41:12 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/16IN3v0V12M/upload/4827ca16303c1f8eb939c6e98d234e2a.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-what-are-ai-apis">What Are AI APIs?</h1>
<p>AI APIs are <strong>cloud-based interfaces</strong> that allow us to <strong>access and use artificial intelligence models</strong> — like language, vision, or speech models — without needing to train or host them on their own servers.</p>
<p>Think of AI APIs as a teacher who knows it all and can reply with text, images, voice, and much more — all instantly. And the best part? We don’t need to know how they do it; we just ask and get the answer.</p>
<h2 id="heading-where-theyre-used">Where they’re used</h2>
<p>AI APIs are everywhere! From chatbots that talk like humans, to tools that write your blogs or ads for you. They power virtual assistants, create stunning images and lifelike voices, tutor students with personalized lessons, and even help developers write and fix code — all in the blink of an eye.</p>
<p>Nowadays, almost every web or mobile app is evolving by integrating AI APIs to stay ahead with today’s technology. Developers use AI APIs to add smart features like chatbots that understand natural language, content generators that write automatically, image and voice creators, personalized learning assistants, and code helpers. These APIs let apps offer powerful AI capabilities without building complex models from scratch.</p>
<h2 id="heading-types-of-responses-from-ai-apis">Types of Responses from AI APIs</h2>
<h3 id="heading-1-text-completion">1. <strong>Text Completion</strong></h3>
<p>This is the classic mode, where you send a prompt and get a plain text reply.</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> google <span class="hljs-keyword">import</span> genai

<span class="hljs-comment"># Initialize Gemini model</span>
model = genai.GenerativeModel(<span class="hljs-string">"gemini-1.5-pro"</span>)

<span class="hljs-comment"># Send prompt</span>
response = model.generate_content(<span class="hljs-string">"Write a short poem about the moon."</span>)

<span class="hljs-comment"># Print plain text reply</span>
print(<span class="hljs-string">"Plain text reply:"</span>)
print(response.text.strip())
</code></pre>
<h3 id="heading-2-function-calling-tool-use">2. <strong>Function Calling / Tool Use</strong></h3>
<p>Some AI APIs support structured responses where the AI can return JSON objects to trigger actions or call functions in your app.</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> google <span class="hljs-keyword">import</span> genai
<span class="hljs-keyword">import</span> json

<span class="hljs-comment"># Initialize Gemini model</span>
model = genai.GenerativeModel(<span class="hljs-string">"gemini-1.5-pro"</span>)

<span class="hljs-comment"># Send prompt requesting structured response</span>
response = model.generate_content(
    <span class="hljs-string">"Return JSON to call a function named 'add_numbers' with arguments a=5 and b=7. No explanation."</span>
)

<span class="hljs-comment"># Parse text as JSON</span>
result_json = json.loads(response.text.strip())

<span class="hljs-comment"># Print the structured result</span>
print(<span class="hljs-string">"Simulated function call JSON:"</span>)
print(json.dumps(result_json, indent=<span class="hljs-number">2</span>))

<span class="hljs-comment"># Example: You could then trigger your add_numbers function with this data.</span>
</code></pre>
<h3 id="heading-3-structured-output">3. <strong>Structured Output</strong></h3>
<p>You ask the model to return structured data (usually JSON) based on pattern or schema-but its just data no action</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">generate_content</span>(<span class="hljs-params">prompt: str</span>):</span>
    load_dotenv()
    api_key = os.getenv(<span class="hljs-string">"GEMINI_API_KEY"</span>)
    client = genai.Client(api_key=api_key)
    response = client.models.generate_content(
    model=<span class="hljs-string">"gemini-2.0-flash"</span>,
    contents=prompt,
    config={
        <span class="hljs-string">"response_mime_type"</span>: <span class="hljs-string">"application/json"</span>,
        <span class="hljs-string">"response_schema"</span>: CourseResponse, <span class="hljs-comment">#Here CourseResponse pydantic model</span>
    },)
    <span class="hljs-keyword">try</span>:
        parsed = json.loads(response.text)
        <span class="hljs-keyword">return</span> CourseResponse(**parsed)
</code></pre>
<h2 id="heading-why-do-hallucinations-happen-in-ai-apis">Why Do Hallucinations Happen in AI APIs?</h2>
<p><strong>Hallucination</strong> refers to when an AI confidently produces <strong>false, misleading, or completely made-up responses</strong>. This can be a major issue in real-world applications.</p>
<h3 id="heading-examples-of-hallucination">Examples of Hallucination</h3>
<ol>
<li><strong>Fake Citations</strong></li>
</ol>
<blockquote>
<p>“According to Smith 2022 in <em>The AI Guidebook</em>…” (book doesn’t exist)</p>
</blockquote>
<ol start="2">
<li><strong>Bad Code</strong></li>
</ol>
<blockquote>
<p>Returns Python code that imports a nonexistent module</p>
</blockquote>
<ol start="3">
<li><strong>Wrong Math</strong></li>
</ol>
<blockquote>
<p>Calculates <code>23 × 5 = 135</code> (because it "sounded right")</p>
</blockquote>
<h3 id="heading-why-do-ai-models-hallucinate">Why Do AI Models Hallucinate?</h3>
<p>AI models sometimes produce false or made-up information, which is known as hallucination. This happens for several reasons:</p>
<ol>
<li><p><strong>They predict text, not facts.</strong><br /> Language models are trained to predict the next word based on patterns, not verify truth.</p>
</li>
<li><p><strong>Vague or unclear prompts.</strong><br /> If your input is too short or missing detail, the model fills in the blanks with guesses.</p>
</li>
<li><p><strong>Outdated or limited knowledge.</strong><br /> Many models don’t have real-time access to the internet, so their knowledge may be outdated.</p>
</li>
<li><p><strong>No access to tools.</strong><br /> Without plugins or API access, the model can't look up facts, calculate, or fetch real data.</p>
</li>
<li><p><strong>High temperature settings.</strong><br /> A higher temperature makes responses more creative, but also increases the chance of hallucination.</p>
</li>
</ol>
<h3 id="heading-what-is-temperature-in-ai">What is Temperature in AI?</h3>
<p><strong>Temperature</strong> is a setting that controls how creative or random the AI’s responses are.</p>
<ul>
<li><p><strong>Low temperature (e.g., 0–0.3):</strong><br />  The AI gives more focused, predictable, and accurate answers. Good for facts and code.</p>
</li>
<li><p><strong>High temperature (e.g., 0.7–1.0):</strong><br />  The AI becomes more creative, diverse, and expressive. Good for storytelling or brainstorming — but more likely to make things up (hallucinate).</p>
</li>
</ul>
<h3 id="heading-how-to-handle-and-reduce-hallucination">How to Handle and Reduce Hallucination</h3>
<ol>
<li><p><strong>Write clear prompts</strong><br /> Be specific. The more detail you give, the less the model needs to guess.</p>
</li>
<li><p><strong>Use system messages</strong><br /> Set the model’s role, like: “You are a helpful assistant. Only respond with facts.”</p>
</li>
<li><p><strong>Validate responses</strong><br /> Check outputs before using them — especially for structured data. Use tools like <code>json.loads()</code> or Pydantic.</p>
</li>
<li><p><strong>Post-process results</strong><br /> Add logic to catch and filter out fake data, bad links, or unsupported answers.</p>
</li>
<li><p><strong>Use function calling or structured output</strong><br /> Instead of asking for text, have the model return specific arguments that your system understands.</p>
</li>
<li><p><strong>Lower the temperature</strong><br /> Set <code>temperature=0</code> for more accurate, fact-based responses.</p>
</li>
<li><p><strong>Use real-time tools or APIs</strong><br /> Connect the AI to your own tools, databases, or search functions to avoid guesses.</p>
</li>
<li><p><strong>Have a human in the loop</strong><br /> For critical use cases, let a human review the AI’s response before it’s published or used.</p>
</li>
</ol>
]]></content:encoded></item></channel></rss>