Theoretical reduction of O(n^3) to O(n) in certain cases
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Theoretical reduction of O(n^3) to O(n) in certain cases
An arbitrary matrix can be solved using Gauss-Jordan elimination with O(n^3) complexity. A tridiagonal matrix (i.e. a special type of matrix) can be solved using Gauss-Jordan with O(n) complexity. That is, a for an arbitrary matrix, Gauss-Jordan is a cumbersome algorithm, but for a tridiagonal matrix, the algorithm can be expressed as a loop and a simple formula.
If I were writing, for example, a compiler or some optimization program, is there a way to test the problem to see if it has become less complex, so I can express the algorithm more simply?
If I were writing, for example, a compiler or some optimization program, is there a way to test the problem to see if it has become less complex, so I can express the algorithm more simply?
The most straight-forward approach would probably be to traverse all the matrix elements that belong to each "triangle" to determine if they are all zero. For large matrices I imagine that this operation would definitely pay off if they do in fact turn out to be tridiagonal, however since I have never done this myself I'm afraid this assumption is just conjecture.
But I would like to hear about the results if you do program this
...
If I were writing, for example, a compiler or some optimization program, is there a way to test the problem to see if it has become less complex, so I can express the algorithm more simply?
The (kind of) problems you've described has known beforehand loop limits, so the loops can be unrolled statically. Counting lines in the unrolled loop is a pretty good measure of complexity, though, strictly saying, you should also count arithmetic operations.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.