Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm implementing the Chessboard class to represent the chessboard. I've to implement the transformations (reflections and rotations) on the chess board possible.
The possible transformations includes the combination of:
1. Vertical Reflection
2. Horizontal Reflection
3. Diagonal Reflection
Thus, we've 8 possible transformations for chess board.
There are 64 squares on the Chessboard numbered [0..63].
Thus, to represent the total resulting values after the transformations is 8*64 (No.of Transformations * Chessboard_Size).
There are two fundamental ways to represent the transformed_board using Arrays:
One-Dimensional Array with transformed_board[8*64]
Two-Dimensional Array with transformed_board[8][64]
Questions:
Which approach is better?
What are the pros and cons of each approach?
How will effect the performance with respect to time factor?
The memory layout is the same for both, so there isn't really any "real" difference whatsoever. It's just a matter if whether you want the compiler to do the offset calculation for you or not, so just go with the syntax you like better.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I just wanted to know if the above question is trivial or not. More importantly, how can you recognize if an algorithm is trivial?
It depends what do you mean by trivial. If you talk about complexity, it is O(n*M(N)) where M(N) is the complexity of the underlying multiplication algorithm with N maximum of the array's values and n is the length of the array.
If you talk about implementation, it is one loop with one check that the sum of the neighbors is a perfect square. If the elements fit into int, double etc. you have sqrt function in the standard library. If your elements are arbitrary length integers or float point numbers, you either need to use an appropriate library or implement the handling of these numbers on your own, which might be not trivial.
This understanding should help you to answer your last question
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
This might be a dumb question but I spend too long not knowing reason.
All through out math classes we learn to put co-ordinates in (x, y) fashion. And it sticks into our minds. Now enter C/C++ and to access x=0, y=3 element, I have to do data[0][3] instead of data[3][0].
Why array accessing is (y, x) format and not (x, y)?
Is there particular reason for this or is it something that I just have to accept and move on with my life?
Edit:
I was watching this GDC talk by Mike Acton, (http://gdcvault.com/play/1021866/Code-Clinic-2015-How-to) where he talks about performance regarding row major access and column major access. Its understandable since any Array is sequential memory, its takes time to jump to different memory location if i'm trying to do column major access.
The [row][col] convention makes since when you look at the conventions used mathematics. Think about and order pair from algebra: (x, y) where the x comes first. This is consistent in math until you get all the way to linear algebra where the order suddenly changes. When dealing with matrices the up-down element should come first as in: M[row][col]. This convention is used in linear algebra for constancy in higher level operations like matrix multiplication...or multiplying a 3x3 matrix by a 3 vector (or 3x1 matrix). If you think of it like a matrix of discrete values instead of a point it makes since.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
What is the and optimal method, if not the best, for doing it?
Assume that I have an object that has 2 wheels. The only information I have available is how far the wheels have rolled at any time.
Basically, I want to know how to calculate the coordinates (x2,y2)
I put this question on the programming section because I want to solve this with an algorithm or plainly put, by programming (in c++).
Given that you have how far the wheels have rolled at any time, it means that you have two functions of time w1(t) w2(t) giving the distance covered by the wheels.
from that you may by derivation get the scalar velocity of each wheel as v1(t) and v2(t).
As your object position is the mean between the position of those two wheels, the velocity of your object is the mean of those two velocities, but the difference of the velocities gives the speed of rotation of the object. So you have essentially a velocity described as a scalar velocity plus a rotation speed.
By integrating that vectorial quantity you may arrive to the current position of your object.
Details must be thought carefully, but the idea I think is that.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I was doing some work handling a lot of information and my partner told me that I was using too many matrices to manipulate the variables of the problem. The idea was to use one dimension arrays int a[] instead of the 2 dimensional arrays int b[][], to save memory and processing speed of the algorithm. How certain is that this change will accelerate the speed of execution or compilation of my code in c ++?
Your question invites to guesswork, but:
How certain is that this change will accelerate the speed of execution or compilation of my code in c ++?
Prognosis is extremely uncertain. The only proper response is to measure.
Measuring is knowing. You can quote me on that.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm developing an estimation algorithm in C++ and performance is key. Basically there is loop where in each iteration, a decision is made on whether to add a column vector to a matrix or to remove one.
I have implemented my own matrix and vector classes and used Intel MKL for matrix operations. However after the first version I'm now looking into using Armadillo.
I would like to know what the best strategy is for dynamic growing matrices inside loops. I know the maximum size of the matrix, so I could preallocate.
First of all, is there another matrix library you would recommend other than Armadillo for small matrices (50 X 50)?
Secondly, what would be the best way to tackle this problem using Armadillo?