It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I've searched a lot over the past few days on this theme and I don't understand how could I make an undirected graph without having a weight. Can anybody tell me which structure should I use and a simple algorithm? Thanks in advance!!!
There isn't any specific requirement that forces you to give weights to your edges. Your adjacency matrix could have binary entries 1-0 or true-false to specify a connection between nodes. All graph algorithms apply as normal.
A VERY helpful lecture about graphs: http://www.youtube.com/watch?v=ylWAB6CMYiY
In a slight elaboration on P.R.s answer. The standard matrix representation can easily be interpreted as the top (north-east) being from top to left (B to A), left being left to top (south-west, none here). A one (1) in any position (boolean internally perhaps) would indicate an unweighted connection.
x A B C D
A 0 1 0 0
B 0 0 1 1
C 0 0 0 1
D 0 0 0 0
Would imply that A is connected to no nodes. B is connected to A. C is connected to B. D is connected to B and C.
This particular example would create a tree with D as the root with children B and C, A as a child to B. A and C leafs.
Note that the unweighted property really does not simplify much. Only in a pure pointer implementation exercise, but that is quite pointless FAPP. An adjacency list instead of this adjacency matrix might give you memory usage advantages.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
May I know how can I do the interpolation for a matrix in C++?
Eg:
I have a 3x3 matrix
{0 0 0
0 1 1
0 0 1}
I wish to resize it to a 10x10 matrix using bilinear interpolation.
Any tips or references about this?
What you want to do is called image resizing using bilinear interpolation. Knowing that google is your friend. I would try using a C++ library for that purpose. This question covers all C++ imaging libraries: Fastest C/C++ image resizing library Any reasonable library should satisfy your needs.
In order to linearly interpolate between two things you need to embed (put) them in a common vector space and then "draw" the line between them.
I can't see a useful embedding of a 3x3 matrix and a 10x10 matrix in a common vector space...
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have an array of floats Float_t xbins[41] that defines 40 bins i.e. ranges of floats.
E.g. y is in bin 7 if y > xbins[7] && !(y > xbins[8]).
How do I determine what bin a given float should belong to without having 40 if statements?
Please answer in C++ as I don't speak other languages.
If the array is sorted, then do a binary search to locate the correct bin. You'll need a combination of std::sort (if not sorted), then something like std::lower_bound, to locate. You'll need to ensure that operator< is implemented correctly for Float_t.
As it turned out that the bins are not uniformly spaced but have integer bounds, the probably fastest method is to have a (inverse) look up table that apparently has about 100 entries. One needs to make basically two comparisons for the lower & higher bounds.
If the array bounds are derived with a formula, it could be possible to write an inverse formula that outperforms the LUT method.
For a generic case binary search is the way -- and even that can be improved a bit by doing linear interpolation instead of exactly subdividing the range to half. The speed (if the data is not pathological) would be O(loglogn) compared to O(logn) for binary search.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I would like to insert data in a ublas::matrix but in one line the same as Matlab just like this (or something similar):
model = [
0.0685 0.6383 0.4558 0.7411 -0.7219 0.7081 0.7061 0.2887 -0.9521 -0.2553
0.4636 0.0159 -0.1010 0.2817 0.6638 0.1582 0.3925 -0.7954 0.6965 -0.7795
0 0 0 0 0 0 0 0 0 0];
If you take a look at the boost documentation, here is a list of the constructors of the matrix class http://www.boost.org/doc/libs/1_51_0/libs/numeric/ublas/doc/matrix.htm#18Members
As you can see from this documentation, it does not appear that there is a means of doing what you want at the present time, so I would suggest (unless you receive a better answer) that you populate your matrix using loops. Matlab and C++ are distinct languages so you cannot assume that you will be able to access functionality in identical manners.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Consider N chords in a circle, each determined by its endpoints. Describe an O(nlogn) solution for determining the number of pairs of chords that intersect inside the circle.
ASSUMPTION: No two chords share an endpoint.
There exists a general line-segment intersection algorithm which does the job in O(nlogn).
This can be used in your case as two chords can't intersect in the exterior of a circle.
The following link contains the algorithm:
http://www.cs.princeton.edu/~chazelle/pubs/IntersectLineSegments.pdf
P.S.
It requires knowledge of basic computational geometry (line sweeps, range trees).
Hope this helps.
Off the top of my head, sort the chord endpoints by polar angle (this is the O(n log n) part). Then read through the sorted list (which is O(n)) - if two adjacent endpoints belong to the same chord, it has no intersections. Where two adjacent entries in the list belong to different chords, there may be an intersection depending on where the other endpoints for those two chords lie - e.g. if a chord A has endpoints A1 and A2 in their sorted order, and similarly chord B has B1 and B2, finding B2-A1 in the list is not an intersection, because B1 is earlier and A2 is later. However, B1-A2 would be an intersection.
See also biziclop's comment for another, somewhat more carefully constructed, solution.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
Q.1.2 List all the different ways to connect two different objects for the input/output in the table below:
Input | Output | Not Output (Connection Already Established)
3-4 3-4
4-9 4-9
8-0 8-0
2-3 2-3
5-6 5-6
2-9 2-3-4-9
5-9 5-9
7-3 7-3
4-8 4-8
5-6 5-6
0-2 0-8-4-3-2
6-1 6-1
A.1.2 (I don't understand this question) How would you answer this? That is you are given a pair, and if the nodes are not connected by other nodes already in the graph it outputs the pair else it does not output the pair because it is already connected based on the data that came before it.
As you describe it I would say
Your table describes a graph:
3<->4
4<->9
etc...
Now given 2 nodes (2 numbers) you need to find all the path from one to another. I guess you can look at this post for an optimise way to find all the paths :
Graph Algorithm To Find All Connections Between Two Arbitrary Vertices