Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
/pythonPublic archive

inserting a 2d matrix search algo in searches folder under algorithms#133

Open
HimadriPathak wants to merge1 commit intoAllAlgorithms:master
base:master
Choose a base branch
Loading
fromHimadriPathak:master
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletionsalgorithms/searches/2D_array_search.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -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<n) and (j<m)):
if(arr[i][j] == k):
flag = True
break
elif(arr[i][j]> k):
j-=1
else:
i+=1

if(flag):
print("element found")
else:
print("element not found")

[8]ページ先頭

©2009-2025 Movatter.jp