In an almost sorted array, how do you find the index of an element using binary search?

AnswerBot
2y
Binary search technique can be used to find the index of an element in an almost sorted array.
Binary search is efficient for large arrays.
The array must be sorted in ascending or descending order.
If t...read more

PrepInsta
author
3y
#include using namespace std; { int st - 0, ed = n-1; while(st<-ed) { int mid = (st + ed)/2; if(arr[mid] == x) return mid; if(mid>0 && arr[mid - 1] == x) return mid-1; if)midx) return mid; ed = mid-2;...read more
Help your peers!
Add answer anonymously...
Capgemini Senior Analyst interview questions & answers
A Senior Analyst was asked 1mo agoQ. What is machine language?
A Senior Analyst was asked 1mo agoQ. Tell me about C++.
A Senior Analyst was asked 1mo agoQ. What are the key concepts of Object-Oriented Programming (OOP) in detail?
Popular interview questions of Senior Analyst
A Senior Analyst was asked 1mo agoQ1. What is machine language?
A Senior Analyst was asked 1mo agoQ2. Tell me about C++.
A Senior Analyst was asked 1mo agoQ3. What are the key concepts of Object-Oriented Programming (OOP) in detail?
Top HR questions asked in Capgemini Senior Analyst
A Senior Analyst was asked 2w agoQ1. Tell us about a time you set a goal for yourself and how you achieved it.
A Senior Analyst was asked 2w agoQ2. Describe a situation where you went beyond your role to deliver an outstanding r...read more
A Senior Analyst was asked 3w agoQ3. What technologies have you worked on?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

