1.

Given a sorted matrix where the number below and right of you will always be bigger, write an algorithm to find if a particular number exist in the matrix. What is the running time of your algorithm\

Answer»

Given a sorted MATRIX mat[N][m] and an element ‘x’. Find POSITION of x in the matrix if it is present, else print -1. Matrix is sorted in a way such that all elements in a row are sorted in increasing order and for row ‘i’, where 1 INPUT : mat[][] = { {1, 5, 9}, {14, 20, 21}, {30, 34, 43} } x = 14 Output : Found at (1, 0) Input : mat[][] = { {1, 5, 9, 11}, {14, 20, 21, 26}, {30, 34, 43, 50} } x = 42 Output : -1..



Discussion

No Comment Found