Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
27 views
2 pages
Preern210008439 117 2023 02 10
Uploaded by
Anshika thakur
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save PREERN210008439_117_2023_02_10 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
27 views
2 pages
Preern210008439 117 2023 02 10
Uploaded by
Anshika thakur
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save PREERN210008439_117_2023_02_10 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 2
Search
Fullscreen
‘S.No:2 Exp. Name: Write the code to implement Binary Search Date:2022-09-25 ‘Aim: Write a program to implement Binary Search Theory: In computer science, binary search, also known as half-interval search, logarithmic search, or binary g chop, is @ search algorithm that finds the position of a target value within a sorted array. Binary search é Compares the target value to the middle element of the array. 3 3 Algorithm: 3 1. Find the midpoint of the array; this will be the element at arrfsize/2]. The midpoint divides the array 5 into two smaller arrays: the lower half of the array consisting of elements 0 to midpoint - 1, and the Z upper half of the array consisting of elements midpoint to size-1 a = 2. Compare key to arrlmidpoint] by calling the user function cmp_proc. 3. If the key is a match, return arrlmidpoint| otherwise 4, Ifthe array consists of only one element return NULL indicating that there is no match; otherwise 5. If the key is less than the value extracted from arrlmidpoint] search the lower half of the array by recursively calling search; otherwise 6. Search the upper half of the array by recursively calling search. Source Code: [ woven #include
int main() 4 g seater: 5 printf("Enter the total number of elements: a scanf ("Xd 8a); B int num(a}: 8 printf("Enter the element in sorted form: "); iS for (int i=O;i
8 printf("Enter the element which you want to search: 2 scanf("%d", &key); 5 int low=0,high=a-1, flag: S while (low <= high) a { @ Low+high)/2; um mid] ) printf("The number %d is found in the list at the position %d\n",num [mid] ,mid+1); flag = 1;high = mid - 1 } else{ low = mide1; } if(flag==0) printf("Element not found\ return 0; Execution Results - alrtest cases have succeeded! Test Case-1 jser Output Enter the total number of elements: 7 Enter the element in sorted form: 11 22 33 44 55 66 77 Enter the element which you want to search: 55, [The nunber 55 is found in the list at the position 5 Test Case-2 jser Output Enter the total number of elements: 5 Enter the element in sorted form: 56 98 118 245 3337 Enter the element which you want to search: 69 Element not found Page No: 2 : : £ '2021-3628-CSE Ad ITS Engineering College
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6453)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2289)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (233)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (836)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1267)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (643)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (78)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
4/5 (278)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (919)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (298)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (244)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (1022)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (280)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (650)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (2016)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (943)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (582)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (628)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4.5/5 (1856)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4.5/5 (1139)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2546)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brene Brown
4/5 (1175)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4.5/5 (4102)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (1005)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4372)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (144)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (2033)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1090)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (2884)
Little Women
From Everand
Little Women
Louisa May Alcott
4.5/5 (2369)