forked from KISHOREMUTHU/Data-Structures-And-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix_binary_search_version2.c
More file actions
52 lines (30 loc) · 840 Bytes
/
Copy pathmatrix_binary_search_version2.c
File metadata and controls
52 lines (30 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Data-Structures-And-Algorithms
Here I will post my regular DSA problems
// Matrix Binary search II
// In this case , the matrix is in sorted form when we see columnwise
#include <stdio.h>
#include<string.h>
int main (){
int a[3][3]={1,2,3,2,4,6,3,6,9}; // input sample array
int x;
scanf("%d",&x);
int l = 0;
int r = 2;
int mid_el;
// Binary search takes place in a condition that l must be less than number of rows and r must be greater than 0
while( l < 3 && r > = 0 ){
if(a[l][r]==x){
printf("%d",x);
break;
}
else{
if(a[l][r]>x){
r--;
}
else{
l++;
}
}
}
return 0 ;
}