Advertisements
Advertisements
Question
A matrix M[- 6, ... 10, 4 ... 15] is stored in the memory with each element requiring 4 bytes of storage. If the base address is 1025, find the address of M [4] [8] when the matrix is stored in Column Major wise.
Solution
M [-6.....10, 4.....15]
Element size: 4 Bytes
Base address: 1025
Order: Column Major
Address to be found for: M [4] [8]
Formula to find the address in column-major order :
A [I] [J] = Base + Width (I - Lr) + nr(J - Lc))
M [4] [8] = 1025 + 4 × ((4 - (- 6)) + 17 × (8-4))
= 1025 + 4 × (10 + 68)
= 1025 + 312
= 1337
APPEARS IN
RELATED QUESTIONS
Write the statement in Java to extract the word “MISS” from the word “SUBMISSION”.
What is the output of the statement given below?
System.out.print("FAN" + ("AUTOMATIC".charAt(5) ) );
A class Sort Alpha has been defined to sort the words in the sentence in alphabetical order.
Example: Input: THE SKY IS BLUE
Output: BLUE IS SKY THE
Some of the members of the class are given below:
Class name | Short Alpha |
Data members/instance variables: |
|
sent |
to store a sentence |
n | integer to store the number of words in a sentence |
Methods/Member functions: |
|
ShortAlpha( ) |
default constructor to initialise data members with legal initial values |
void acceptsent( ) | to accept a sentence in UPPERCASE |
void short(SortAlpha P) | sorts the words of the sentence of object P in alphabetical order and stores the sorted sentence in the current object |
void display( ) | display the original sentence along with the sorted sentence by invoking the method sort( ) |
Specify the class Sort Alpha giving details of the constructor (), void acceptsent(), void sort (Sort Alpha) and void display(). Define a main()function to create an object and call the functions accordingly to enable the task.
A matrix M[-6….10, 4…15] is stored in the memory, with each element requiring 4 bytes of storage. If the base address is 1025, find the address of M[4][8] when the matrix is stored in column major-wise.
The following function getIt() is a part of some class. Assume x is a positive integer, f is the lower bound of arr[ ] and l is the upper bound of the arr[ ].
Answer the questions given below along with dry run/working.
public int getIt(int x,intarr[],int f,int l)
{
if(f>l)
return-1;
int m=(f+l)/2;
if(arr[m]<x)
return getIt(x,m+1,l);
else if(arr[m]>x)
return getIt(x,f,m-1);
else
return m;
}
- What will the function getIt( ) return if arr[ ] = {10,20,30,40,50} and x = 40?
-
What is function getIt( ) performing apart from recursion?