Big-O Notation
by tadman (Prior) on Jul 05, 2001 at 07:48 UTC
|
Just a quick note on the
O(n)
or so-called "Big-O Notation" used by computer
science folks. It's not really "math"1 so much as it is
an approximation. You can't get an exact number out of it,
per se, and it isn't really something you can do algebra
on in a direct sense. Quoting from that link:
Definition: A theoretical measure of the execution of an algorithm, usually the time or memory needed, given the problem size n,
which is usually the number of items. Informally, saying some equation f(n) = O(g(n)) means it is less than some constant multiple
of g(n). More formally it means there are positive constants c and k, such that 0 <= f(n) <= cg(n) for all n >= k. The values of c and k
must be fixed for the function f and must not depend on n.
A first year computer science textbook is certainly in order
if you want to discover some of the theory behind the way
algorithms work. The classic White Book is a
popular choice of professors and students alike. One of the
authors is Ronald L. Rivest, the "R" in RSA encryption.
It introduces you to a variety of different algorithms
used to find substrings, sort lists, and navigate networks.
Some of this is redundant considering Perl does a lot of
this for you, but understanding the theory behind it, and
the work you are making Perl do, can help you write better
code.
The other tool that would be handy is a graphing calculator
program, or even Excel, where you could familiarize yourself
with the shape of various functions such as log(n).
In computer science terms, these shapes are used to approximate
how a function will scale, or how long it will take to run
given a data-set of size n.
Here's a quick rundown on some popular types:
- O(n) - As the data doubles in size, the algorithm
takes twice as long to run.
- O(n2) - As the data doubles in size,
the algorithm takes four times as long to run.
- O(n3) - As the data doubles in size,
the algorithm takes eight times as long to run.
- O(log n) - As the data size increases, the amount
of time the algorithm takes to run increases, but increases
less and less as the size increases more and more.
- O(en) - As the data size increases,
the amount of time the algorithm takes to run increases
exponentially, becoming very long very quickly.
For example, if you had a sort function which runs in O(n)
time, it is fairly efficient because if you try and sort 20
things, it only takes about twice as long as sorting 10.
If you had another sort function that ran in O(n3)
time, sorting 20 things would take eight times longer.
1. Okay, so maybe adamsj is correct in saying that it
is math, but I was merely trying to suggest that it's
not, well, mathy math, which is another way of saying
that understanding O(n) is not quite as hard as, say,
learning multi-dimensional Calculus.
I would have to agree that O(n)-notation is math inasmuch
as it uses math to express, not surprisingly,
mathematically how these functions are expected
to run.
| [reply] |
|
As a former bookseller and math student, I want to second your nomination of Introduction to Algorithms--I wish my copy weren't hundreds of miles away--and also want to quibble with what you said about O(f(n)).
It is math.1
A lot of interesting math--especially math of interest to computing science--is done through approximation rather than turning out exact answers. I, too, used to look down on that as not real math, but I was wrong.
Now that that's out of my system, here's a little more good advice from my bookseller self:
Don't buy a current used textbook. Instead, look for an old edition. Trust me on this--little has changed in calculus and trig in the last century or so--and old texts are worthless to the college bookstore. If they have any, they probably have them out on the dollar a sack sale table.
If they don't have them out there, ask the textbook manager or try a used non-textbook store, and don't pay over five bucks--ten at the most--or ask around for a freebie at the math department at the local colleges.
There is a very good chance that your math teacher can't help you--mine couldn't (but he was a good track coach, I'm told), when I took on calculus in tenth grade. What he did do for me (since he couldn't explain how the Chain Rule was derived) was tell me that if I'd sit in class and quietly study calculus, he'd grade me just on my text scores (i.e., no algebra homework). That I wasn't supposed to bug him with calculus questions went unsaid.
This doesn't mean that your teacher won't be able to help you directly with the material--more likely she can than can't, but it's not a slam dunk--but it does mean that she can surely help you in some manner. However, the degree of help you get in this optional exercise is more than directly proportional to the politeness and respect with which you approach her. Only a saint (and I've benefited from a couple) will help a hateful student.
Let's see, what else? Oh, yeah--for an introductory text on discrete math, I like Discrete Mathematics by Richard Johnsonbaugh. It's in its fourth edition, so look for an old edition, and again, don't go over ten bucks.
Good luck, and have fun!
adamsj
They laughed at Joan of Arc, but she went right ahead and built it. --Gracie Allen
1. I'm jealous of tadman, since, while I would agree with him that the ideas in the various O-notations are simpler than the ideas in multi-variable calculus, I found them harder to learn and prove.
| [reply] |
|
| [reply] |
|
|
Eh, I'll add my $.02 (hehe).
I think that the best math in computer science is the REALLY "outlandish" stuff, that you'll NEVER see in other fields. I love toying with Automata and Computation Theory problems. Nothing like a Turing Machine to make your day complete. And that is as MATHY as it gets, though it certainly doesn't feel like math was in high school, I didn't love math so much in HS... Not because of the teachers and all, but because I was taking the area of triangles just a bit more often than I care to think of.
Just Another Perl Backpacker
| [reply] |
Re: What??? You wanna learn math?
by ariels (Curate) on Jul 05, 2001 at 10:39 UTC
|
An excellent (first-year university) textbook that teaches what you need for analysis of algorithms is Ronald Graham, Oren Patashnik and Donald Ervin Knuth's (yes, that's THE Knuth) Concrete Mathematics. It won't teach you trigonometry or elementary calculus, though. But it will teach you lots of "neat stuff", all of it relevant to computing.
| [reply] |
Re: What??? You wanna learn math?
by Beatnik (Parson) on Jul 05, 2001 at 11:49 UTC
|
Mastering Algorithms with Perl resembles my math course at Uni... I remember using it to while studying for my finals.
Greetz
Beatnik
... Quidquid perl dictum sit, altum viditur. | [reply] |
Re: What??? You wanna learn math?
by cacharbe (Curate) on Jul 05, 2001 at 17:17 UTC
|
When I decided that I wanted to learn Crypto, I found out that the Probability and Stats classes I took *AHEM* years ago were actually pertinent...and also pretty much forgotten. So I went searching on the web. I needed to brush up my calculus and shake the dust out of the Stats portion of my brain.During my quest, I found a number of texts that were immensely useful, but I also found some resources on the web that I put directly to use. These include: I hope this helps. Good Luck. C-. | [reply] |
Best Bet+Cheapest
by dondelelcaro (Monk) on Jul 05, 2001 at 15:03 UTC
|
You definetly want to talk to your Math teachers, especially if there are any decent ones at your school. They generally have easier access to decent textbooks for teaching precalc+calculus, and could probably arrange for you to borrow one.
Beyond that, you can of course buy your textbook. If there is a college campus somewhere near you, I strongly suggest visiting their bookstore and checking out their textbooks. You will probably be able to get a decent deal on a used calculus book (but that's still going to be expensive, like $70).
If textbooks aren't your thing, there are some fairly good online courses available, but that's pretty much something you can find out on your own. (Google anyone?)
You might also be able to get into some community college courses if there is one in your area. (You'll probably be able to learn enough calculus to get yourself started in 2-3 courses) Your guidance counsellors should know something about that. (If not, just go talk to the community college... they tend to know more.) | [reply] |
Re: What??? You wanna learn math?
by voyager (Friar) on Jul 05, 2001 at 06:16 UTC
|
Well I took geometry and trig long before Al Gore invented the Internet. But a quick search on Google search on "trigonometry" yielded several promising looking hits, including this one. | [reply] |
Re: What??? You wanna learn math?
by larsen (Parson) on Jul 05, 2001 at 16:11 UTC
|
| [reply] |
Re: What??? You wanna learn math?
by toma (Vicar) on Jul 06, 2001 at 12:00 UTC
|
Trigonometry is a strange subject. One way to think about
trigonometry is that it is a practical, numeric form of
geometry that emphasizes the real world and getting
answers instead of worrying about proofs. To balance this
practical information, a course in trig will include a long
section on "trigonometric identities." The importance of
these identities is difficult to discover until you
get to some *very* advanced topics in engineering
(or somethine else I've missed altogether!)
The most important thing is that you have a really solid
understanding of geometry. My favorite tool for
learning Euclidean geometry really well is a commercial
Windows program called
The Geometer's Sketchpad. Add-on modules for the
sketchpad include trigonometry, so this might be a
great way to learn it.
For calculus, there are many books to choose from.
A solid, modern calculus textbook is
Thomas' Calculus. Buy it
used!
This, combined with a Schaums Outline, is an unstopable combination.
Thomas is both loved and hated by students and faculty all
over, so don't be surprised if there are flames on this one.
If you have trouble finding a book that really suits you,
extreme measures are called for.
It turns out that there was a 'golden age' for textbooks.
Books were written clearly and there was no worry about
conforming to the latest educational fads. These years
were from about 1958 to 1964. These books were written
to win the space race. Many of these books can now be found for
cheap at used book stores. The best bookstore for books
from this period is
Powell's Used Books.
If you have trouble affording the books you need, buy a
used book. Also, you may want to buy additional, low
cost books to fill in the gaps for your main text. This
is especially important if you are teaching yourself,
because there will be sections of your textbook that
won't make sense. An explanation from another book may
be all that you need to make everything clear.
A publisher that specializes in supplementary reading
and problems is Schaums. You need
Schaum's Outline of Theory and Problems of Differential and Integral Calculus
and
Schaum's outline of theory and problems of
college mathematics: algebra, discrete mathematics,
trigonometry, geometry, introduction to caculus.
A publisher that specializes in low-cost books is Dover.
I don't recommend a Dover book as a main text. Instead,
find a specialized Dover books that cover something that
is interesting and uses the advanced math you are learning.
It should work perfectly the first time! - toma | [reply] |
|
Older editions of Thomas' Calculus had a really neat appendix called "Lies that your Computer and Calculator Told You", and it had a bunch of examples showing how to break, confuse or at least horribly slow down a lot of computational methods for some mathematical problems.
The point? Computers can never 'replace' math. They make things easier, but aren't a do-all end-all solution.
For example, try to use a TI-85 to find the derivative of the absolute value of x at x=0. The calculator tells you the answer is 0, when really it is undefined.
Sadly, that appendix seems to have disappeared from the newest edition (I could be wrong there).
| [reply] |
|
Yes, yes, yes! to your suggestion of Thomas' Calculus book--it's so good, they actually reprinted the third edition as a classic. I have an alternate fourth edition, which is slightly more abstract in its approach, but still great.
I didn't really get calculus until I stumbled on the third edition in the town library--I'd tried many others, but that one really clicked for me. If I'd only found that one in ninth grade!
adamsj
They laughed at Joan of Arc, but she went right ahead and built it. --Gracie Allen
| [reply] |
Re: What??? You wanna learn math?
by hding (Chaplain) on Jul 05, 2001 at 17:30 UTC
|
I'll second the advice that you seek advice from a teacher whom you regard as competent to get started. A high school is pretty likely to have extra books sitting around and it's pretty likely that you can borrow one. If not, they're often available at libraries and so on. There is such a glut of books available at that level that it's hard to know about any one in particular, and my experiences are too far behind me to remember. :-)
Perhaps even more important is that you find someone (perhaps the aforementioned hypothetical teacher; if that can't be done, sensible questions usually seem to at least receive hints on sci.math, although one has to cut through a lot of dross there too) who can give you some guidance while you study. It's all too easy to become distracted and miss the really important concepts. (A well written book should help ameliorate this effect, but it's always something for which to guard.) And while it best to work out as much as possible by oneself (IMHO), it's also silly to get stuck on and become frustrated by something that could easily be cleared up by spending a few moments with someone knowledgable.
Don't forget to do a lot of exercises, too. :-)
| [reply] |
Re: What??? You wanna learn math?
by pmas (Hermit) on Jul 05, 2001 at 19:04 UTC
|
Do not skipp your classes. Do talk to your teacher. S/he will be excited, I suppose, with over-archieving student. Will be glad to guide you.
School bokks are slow advancing - they are spoon-feeding you. In city library, they might have popular-science books which might be much better suited for self-learner. Or some home-schooling books. Ask your teacher - if it is not too late.
From my own experience: I learned by myself over the summer 3 years worth of high-school math after my freshman HS year - I just borrowed the books from teacher. It is doable. But knowledge of calculus did not helped me a lot in programming: It depends of your application, but you basicaly do not need advanced calculus. In 15 years of programming, I am using always integer numbers (or fixed decimal point, basicaly the same). I consider algebra much more usefull, and solving small little funny problems (like in Gardner books) much more relevant to programming (= solving problems) than knowledge of calculus.
I had a friend, PhD in astronomy, who told me he needs a week to switch from math (scientific) way of thinking (solving advanced differential and integral equations) to programming thinking (when coding huge FORTRAN program to calculate satelite trajectories).
Your mileage may vary - it depends on application.
pmas
To make errors is human. But to make million errors per second, you need a computer. | [reply] |
Re: What??? You wanna learn math?
by Anonymous Monk on Jul 05, 2001 at 19:36 UTC
|
If you're encountering O(log(n)), you need to read an introductory computer algorithms book, or take a course in the same. Textbooks on the subject are guaranteed to be in your local uni. library. Graph theory should be covered in those same books, and is also worth studying. | [reply] |
Re: What??? You wanna learn math?
by beretboy (Chaplain) on Jul 05, 2001 at 18:37 UTC
|
Find people in your school who are failing geo/trig and don't care (you know the type) pay/ask them for their text-books
"Sanity is the playground of the unimaginative"
-Unknown | [reply] |
Re: What??? You wanna learn math?
by Anonymous Monk on Jul 06, 2001 at 20:31 UTC
|
Your question, as you might guess, depends on where you are mathematically and how deep you want to go. A reasonable beginning (and affordable, too) is one of the Schaum's Outline series on Caluculus, Trigonometry. A far better and harder to find option is Edwin Moise's (out of print) book entitled something like Calculus. You should be able to find a reference on Amazon or Barnes & Noble or whatever. Another good source is Springer-Verlag and Dover Publications (less expensive). Hope this helps. | [reply] |