0% found this document useful (0 votes)
52 views3 pages

Problem No.1 Problem Name: Problem Description: Algorithm

This document describes a binary search algorithm to find an item in a sorted array. The algorithm has 7 steps: 1) Set beginning, end, and middle pointers, 2) Repeat search while pointers not equal and item not found, 3) Check if item less than middle, adjust pointers, 4) Recompute middle, 5) Check if item equals middle, set location, 6) Insert item at location, 7) Exit. Pseudocode and C source code are provided to implement the binary search.

Uploaded by

Afrina Dipti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views3 pages

Problem No.1 Problem Name: Problem Description: Algorithm

This document describes a binary search algorithm to find an item in a sorted array. The algorithm has 7 steps: 1) Set beginning, end, and middle pointers, 2) Repeat search while pointers not equal and item not found, 3) Check if item less than middle, adjust pointers, 4) Recompute middle, 5) Check if item equals middle, set location, 6) Insert item at location, 7) Exit. Pseudocode and C source code are provided to implement the binary search.

Uploaded by

Afrina Dipti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Problem No.

Problem Name:

Problem Description:

Algorithm:
Step 1: Set BEG=LB, END=UB and MID=INT((BEG+END)/2).

Step 2: Repeat steps 3 and 4 while BEG<=END and DATA [MID]≠ITEM.

Step 3: If ITEM<DATA[MID], then

Set END=MID-1.

Else: set BEG=MID+1.

Step 4: Set MID=INT((BEG+END)/2).

Step 5: If ITEM<DATA[MID], then:

Set LOC=MID.

Else: set LOC=MID+1.

Step 6: Insert ITEM into DATA[LOC].

Step 7: Exit.

Flow Chart:

Source Code:
#include<stdio.h>

int main(){

int n,DATA[50],i,BEG,END,MID,ITEM,LOC;

printf("enter number of elements\n");


scanf("%d",&n);

printf("enter %d elements of an array\n",n);

for(i=1;i<=n;i++)

scanf("%d",&DATA[i]);

printf("enter a value to check\n");

scanf("%d",&ITEM);

BEG=1;

END=n;

MID=((BEG+END)/2);

while(BEG<=END && DATA[MID]!=ITEM){

if(ITEM<DATA[MID]){

END=MID-1;}

else{

BEG=MID+1;

MID=((BEG+END)/2);

if(DATA[MID]==ITEM){

LOC=MID;

printf("%d is found in the LOC=%d\n",ITEM,LOC);

else{
printf("not found\n");

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy