March 10th, 2011, 11:53 AM
Data Structure VS Database
Why do we need to learn data structure? Why don't we just use database and sql command?
I am not quite sure but I think a database has flatten files. When running a database server, it creates an object which can serve operations (e.g. find, insert, remove, sort).
Q1: Is that object like a data collection that has some kinds of data structure inside? or Is that object like a stream?
I can code a program to read data from a text file and create an object to keep the data in any kinds of data structure (e.g. binary tree, hash map). In other word, to load data from disk to memory with a data structure. But loading tends to be slow. A sql database seems to be a better idea.
Initializing is faster, and all operations is fast too. Only one thing I can think why I need to use data structure is only when I manage with small data. It may not worth to create a database. But if i operate only small data, why do I need binary tree, hash map, etc. I just use an array.
Q2: In what kinds of application do we need data structure source code instead of a database?
The question may sound trivial for someone.
But I really doubt it. Please help!!
March 18th, 2011, 02:10 AM
Re: Data Structure VS Database
Long story short: databases are a good tool when you have a large amount of data to process and are optimized for certain tasks (for example, retrieving a record based on a key). There are many cases, however, when you'd not want to use a database, but using an array would be suboptimal.
For example, suppose I am generating numbers (for whatever purpose) and need to check to see if I have already ever generated each new number. One method of doing this would be to use a binary tree. That way whenever a new number comes up, I can check to see if I've already seen it in O(log n) steps [because the binary tree is sorted] instead of scanning through an entire array to see if it's present which requires O(n) steps. If I have to do this a million times, the tree structure will require n*log(n) = 19,000,000 steps while the array method will require n*n = 1,000,000,000,000 steps. This is the difference between a successful algorithm an unsuccessful one. Use of a database would not be advisable because of the bad performance overhead required.
This is sort of a contrived example to answer your question, but my basic advice is: don't be enamored with databases. They are a tool with a specific purpose rather than a crutch to be used to avoid learning data structures (and a broken crutch at that). Many programmers (me, for example) do not often encounter situations that require the use of a database. Every programmer, however, makes use of data structures every day. So learn about them and they will be powerful tools.
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
March 20th, 2011, 05:20 AM
Re: Data Structure VS Database
For one thing you cannot use a data base efficiently whithout knowing quite a lot about data structures.
Originally Posted by staccato
It's a common problem. Uneducated programmers use powerful tools knowing nada about how they work. The result usually is a major disaster.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!