<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Searching programs | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/searching-programs/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Sat, 10 Dec 2022 04:29:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>Binary Search</title>
		<link>https://studentprojects.in/software-development/c-tutorials/c/c-advanced/binary-search/</link>
					<comments>https://studentprojects.in/software-development/c-tutorials/c/c-advanced/binary-search/#comments</comments>
		
		<dc:creator><![CDATA[Chitra]]></dc:creator>
		<pubDate>Mon, 15 Aug 2011 17:43:26 +0000</pubDate>
				<category><![CDATA[Advanced programs]]></category>
		<category><![CDATA[c program]]></category>
		<category><![CDATA[binary search]]></category>
		<category><![CDATA[Searching programs]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1591</guid>

					<description><![CDATA[<p>A binarysearch program locates the position of an item in a sorted array. Logic: The Binary search starts by testing the element at the middle of the array. Let us consider an array ‘a’ with all elements arranged in ascending order. Let low and high are the lower and upper indices of the array ‘a’, respectively. We want to search an item</p>
<p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/c-advanced/binary-search/">Binary Search</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>A binarysearch program locates the position of an item in a sorted array.</p>
<p>Logic: The Binary search starts by testing the element at the middle of the array. Let us consider an array ‘a’ with all elements arranged in ascending order. Let low and high are the lower and upper indices of the array ‘a’, respectively. We want to search an item K in it. To do this, we calculate a middle index with the values of low and high, let it be mid. Then we compare if K=a[mid] or not.</p>
<p>If it is true, then search is done. Otherwise, the search is to be repeated on left or right half depending on the K&lt;a[mid] or K&gt;a[mid], respectively. In case of low =high and K a[mid], the search terminates unsuccessfully.</p>
<p><img decoding="async" loading="lazy" class="aligncenter wp-image-1641 size-full" title="Binary Search flow" src="https://studentprojects.in/wp-content/uploads/2011/08/BinarySearch.png" alt="Binary Search flow" width="583" height="207" /></p>
<p>Example 1:</p>
<p>Consider the following elements stored in an array,</p>
<p><img decoding="async" loading="lazy" class="aligncenter wp-image-1642 size-full" title="Binary Search example" src="https://studentprojects.in/wp-content/uploads/2011/08/BinarySearch_Ex1.png" alt="Binary Search example" width="581" height="402" /></p>
<p>Example 2:</p>
<p>Consider the following elements stored in an array,</p>
<p><img decoding="async" loading="lazy" class="aligncenter wp-image-1643 size-full" title="Binary Search example" src="https://studentprojects.in/wp-content/uploads/2011/08/BinarySearch_Ex2.png" alt="Binary Search example" width="584" height="430" /></p>
<p>Program:</p>
<pre lang="c" line="1" escaped="true">#include"stdio.h"
#include"conio.h"
void main()
{
	int a[25], i, n, K, flag = 0, low, high, mid;
	clrscr();
	printf("Enter the number of elementsn");
	scanf("%d", &amp;n);
	printf("Enter the elementsn");
	for(i = 0; i&lt;n; i++)
	{
		scanf("%d",&amp;a[i]);
	}
	printf("Enter the key to be searchedn");
	scanf("%d",&amp;K);
	low = 0;
	high = n - 1;
	while(low &lt;= high)
	{
		mid = (low+high)/2;
		if(a[mid] == K)
		{
			flag = 1;
			break;
		}
		else if(K&lt;a[mid])
			high = mid-1;
		else
			low = mid + 1;
	}
	if(flag == 1)
	{
		printf("Key element is found");
	}
	else
	{
		printf("Key element not found");
	}
	getch();
}
</pre><p>The post <a href="https://studentprojects.in/software-development/c-tutorials/c/c-advanced/binary-search/">Binary Search</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/c-tutorials/c/c-advanced/binary-search/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
