From ac6f39e88436a82139174120ae1f852d66b635af Mon Sep 17 00:00:00 2001 From: HimadriPathak Date: Fri, 1 Oct 2021 15:02:49 +0530 Subject: [PATCH] inserting a 2d matrix search algo in searches file --- algorithms/searches/2D_array_search.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 algorithms/searches/2D_array_search.py diff --git a/algorithms/searches/2D_array_search.py b/algorithms/searches/2D_array_search.py new file mode 100644 index 0000000..eda747d --- /dev/null +++ b/algorithms/searches/2D_array_search.py @@ -0,0 +1,23 @@ + +#it's a searching algorithm for sorted 2D matrix and complexity O(n+m) where n is number of rows and m is number of columns +n,m= map(int,input().split()) #taking row and column input +arr = [[int(input()) for x in range (m)] for y in range(n)] #entering elements into the matrix + +k = int(input("enter the search element: ")) +flag = False + +i,j = 0, m-1 +#main algorithm +while((i>=0) and (j>=0) and (i k): + j-=1 + else: + i+=1 + +if(flag): + print("element found") +else: + print("element not found")