There may be, depending on the processor and number of columns and size of elements. Some processors give fast access to separate bytes of a register (or in the first place form a larger register by adjoining several smaller registers), then perhaps you can form an address almost for free by creating y in the low byte and x in the high byte of the address (likely with an offset otherwise the matrix has to start at 0). This applies to z80 and 8086 and probably some other old CISC architectures (not modern x86 though - it's still possible but no longer actually fast). On a RISC architecture that sort of trick usually doesn't exist. It also typically wastes a lot of memory (you can use the gaps of course but they're fragmented).
Before using such micro-optimisations, I would ensure that we have used all higher-level optimisations, first. For example:
How are the data received?
Are they stored in memory in order of reception, or does some processing (e.g. address calculation) need to be performed?
How are the data processed?
Is the access pattern sequential? random?
If a single pass through the data is performed, is it possible to store the data (see question 1 above) in the order of processing, and thereby avoid all indexing?
You may be able to think of other optimisations, based on your knowledge of the hardware and the problem.
So it is the BCC compiler. According to the __finally (C++) - RAD Studio[^] it should be __try and __finally. When omitting the leading underscores the code should not even compile because try requires a catch and __try requires an __except or __finally.
The first uses the expression list of the constructor to initialise a member by passing to the member's constructor. See Constructors and member initializer lists - cppreference.com[^] for the various possible methods about member initialisation besides assigning in the compound statement (the final block enclosed by braces).
Problem statement: You are given Q queries. Each query consists of a single number N. You can perform any of the 2 operations on in each move:
1: If we take 2 integers a and b where N=aXb(a!=1,b!=1) then we can change N=max(a,b).
2: Decrease the value of N by 1. Determine the minimum number of moves required to reduce the value of N to 0
The first line contains the integer Q.
The next Q lines each contain an integer,N .
Output Q lines. Each line containing the minimum number of moves required to reduce the value of N to 0.
For test case 1, We only have one option that gives the minimum number of moves. Follow 3->2 -> 1->0 .
Hence, 3 moves.
For the case 2, we can either go 4->3 ->2 ->1 ->0 or4 -> 2-> 1->0 . The 2nd option is more optimal. Hence, 3 moves.
if a number is N then
I do looping until sqrt(N) to find if it is a prime or not.
if it is a prime number then N=N-1
if it not a prime number,one of the largest factor(say a) is <=sqrt(N) then other will be b=N/a now b>a then put N=b;
increment count(pass by value).
then next iteration for N ,until it is greater than 1.
algorithms works fine with small value but predicts less optimal solution for large values.why?
Last Visit: 19-Jan-19 8:39 Last Update: 19-Jan-19 8:39