nav
BAN USER
Life in algorithms..
- 0of 0 votes
AnswersGiven is a matrix arr[n][n], find a submatrix sub[m][m] such summation of all the elements in submatrix is maximum.
- nav in India
Given condition,
1. m <= n
2. m >= 2
3. consider positive, negavive and zero integers in arr[n][n]
4. User provide n.| Report Duplicate | Flag | PURGE
Software Engineer / Developer Matrix
Recurssion can be used,
Int getLongestPalindromeLength(char inputString[], int start, int end)
{
If(start == stop) return 1;
Int i = start, j = stop;
for(; i< j; i++ ){
If(inputString[i] != inputString[j])
Break;
i++; j--;
}
If(i == j) return (Start - stop + 1);
getLongestPalindromeLength(inputString[], start-1, stop);
getLongestPalindromeLength(inputString[], start, stop -1);
getLongestPalindromeLength(inputString[], start-1, stop -1);
}
Critical section is a segment of code which can be executed by one process at a time and other processes should wait at that time. Example is writing database or file, which are read by other processes or using a shared resourse.
MUTEX is a variable used as a token to execute the critical section.
We cant store duplicate data, as it will lead to waste lot of memory. Instead we can have arrays, one for each key.
1. FirstName[0..length], lastName[0..length], number[0..length], designation[0..length]
2. Search value in respective array, which return the index of item.
3. Fetch data from other arrays from same index. This will return complete details of person.
Why not use a simple array..following is pseudocode..
1. Sort array A[0..length-1] and get sum of all elements as totalSum.
2. Set start counter to 0 and end counter at lenght - 1.
3. Get sum currentSum = A[start] + A[end].
4. Get sum restElementSum = totalSum - currentSum.
5. If restElementSum == currentSum then print A[start] and A[end] return
6. Else start-- and end--
7. Goto 3.
Recurssion can be used,
- nav July 13, 2014Int getLongestPalindromeLength(char inputString[], int start, int end)
{
If(start == stop) return 1;
Int i = start, j = stop;
for(; i< j; i++ ){
If(inputString[i] != inputString[j])
Break;
i++; j--;
}
If(i == j) return (Start - stop + 1);
getLongestPalindromeLength(inputString[], start-1, stop);
getLongestPalindromeLength(inputString[], start, stop -1);
getLongestPalindromeLength(inputString[], start-1, stop -1);
}