Binary Search in Matrix | Data Structures & Algorithms

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

I like these types of Tutorial, I mean when I learn something I would easily fall asleep as of the boredom but this video entertains me. I laughed 2 times and it really helped me improve my mood which then helped me to focus on the explanation. I hope you will make more videos like this ;)

dxykhang
Автор

Your way of teaching is extremely good great

Stupeeylife
Автор

Very easy to understand. Thanks a lot!

LeucAnhprofessional
Автор

why do you convert high to ( mid and not mid - 1 ) while value's greater than target

amritsubramanian
Автор

I went through the first 3 minutes of the video thinking: “hmm, this man sounds like Joma”. And then I looked the channel name

pyserialkiller
Автор

wait wait, why can't just find witch row it's by comparing the input to the first value of each row, then do the binary search on just that row, I think that way you'll be taking more advantage of this super sorted matrix especially if the rows are super long???


Edit: I love your content
Edit 2: I gave my comment and your video a like

hadahda
Автор

Hi Joma, this just only solved with accending or descending matrix, so i really have a question that which is the fastest way for searching the number that had existed or not on a random numbers matrix. So glad if u can answer my comment or solve it on next video. Peace!

hoanglongpham
Автор

Broooo please start a course on Udemy please man 🙏

syedirfan
Автор

I want to engage in computer science. bit my doubt is what should I take in that like(animator or game designer or computer engineer, reply to me Joma sensei.

steverogers
Автор

def get2D(pos, arrayLength):
X = pos % arrayLength
Y = (pos - X) // arrayLength
return (Y, X)


def getPos(coord, arrayLength):
Y = coord[0]
X = coord[1]
return Y * arrayLength + X


# assume everything is sorted in this matrice
def binary_search_matrix(matrice, value):
arrayLength = len(matrice[0])
arrayHeight = len(matrice)
low = 0
high = getPos((arrayHeight - 1, arrayLength - 1), arrayLength) - 1


if matrice[arrayHeight - 1][arrayLength - 1] == value:
return (arrayHeight - 1, arrayLength - 1)


while low <= high:
mid = (low + high) // 2
coordMid = get2D(mid, arrayLength)
Ymid = coordMid[0]
Xmid = coordMid[1]
if matrice[Ymid][Xmid] == value:
return coordMid
elif matrice[Ymid][Xmid] > value:
high = mid - 1
else:
low = mid + 1
return None


matrix = [
[1, 3, 5, 8],
[10, 11, 15, 16],
[24, 27, 30, 31],
[34, 39, 233, 2122]
]


print(binary_search_matrix(matrix, 28))


# for i in range(len(matrix)):
# for j in range(len(matrix[0])):
# print(binary_search_matrix(matrix, matrix[i][j]))

JackHeTech
Автор

@jomatech dude you seriously start a python series on Udemy or youtube anyone of the either and I would love to buy it, your python codes are sexy as fuck I really enjoy watch watch and so easy to understand

RehanKhan-nicr
Автор

Joma, do a day in the life of a software engineer

anam
Автор

Can joma do talking videos like the video "he got a Google offer of 277k by lying". Or " coding is hard". Ly, been watching since the internship vids. Btw im 14 ( in like 2 months ).

anam