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 to implement a sparse matrix (a matrix that has predominantly zeroes, so you only record values different than 0), but I have to implement it using a binary search tree.
EDIT:
So now I'm thinking of implementing it by using the line / column as a key, but what do I use as the root of that tree ?
/EDIT
I hoped once I researched binary search trees I would understand how this implementation would be beneficial, or at the very least possible, but I for the life of me can't figure it out.
I have tried google to no avail, and I myself cannot imagine how to even attempt in doing so.
I haven't decided on the language I shall be implementing this in yet, so I need no code examples, my problem is logic. I need to see how this would even work.
P.S. I have no idea what tags to use, if someone could edit some in, It'd be much appreciated.
To use a binary tree you need to have a key that is distinct for each (possible) entry in the matrix. So if you want to lookup (2, 4) in a matrix [100, 100] then the key could be something like "002004". With this key you can insert a value into the tree.
For each dimension the key would be longer, so you also might consider a hash function to hash the coordinates of the cell and within the tree you have a list of entries for this hash key. The tree is then only an index to the right list. Within the list you need to perform a sequential search then. Or if you order the list you could improve by using a binary search.
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.
I am creating a lucky draw system whereby the participants' username will be stored in either a file or a database and later one of the username will be picked as the winner. Each product has many participants.
My question is what would be the best way to store the usernames? Should I use a text file with each username separated as username\n ? Should I store the usernames in a field (type text) separated by comma? Or should create a participant table that links the member table and product table?
The best way will be to use a database due to the following reasons
1.Data of such apps may grow beyond control and file ops will take significant time then.
2.Databases ensure easy usage of the data stored,rather than file.
3.Database allows adding of new attributes,which is costly beyond imagination if you use a file.For eg,You may need to add attributes like score to your username in future.
So I would recommend using a table.
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 to do a project for my college course in data structures using c and was wondering if anyone can tell me any real life uses of data structures so that I can base my project on it.
Please keep in mind that it is only my first year of programming in c so I currently do not have the skills to write very advanced code.
Since this is your first year of college, I wouldn't go into the depths of datastructures and their uses.
Simplest use of a data structure: A English-to-English Dictionary, which can be built using a Hash Table.
From here, you can go into depths of DS
Datastructures in OS design, such as memory manager (Linked List + Hash-Map),
BTrees in Database Design
Trees in Filesystems
Graphs in electronic circuit simulation, AI etc
many many more.
Well, data structures improve the logic or performance of manipulations on your data. To see the latter, you could try the following. Generate a list of a million or more random numbers and try to find one of them in particular.
Try comparing the performance of the following two representations: an array and a sorted binary tree.
There are lots of real usages of data structures, whether it's in your OS, in Databases, etc.
Think of the case of (not only) MySQL that uses B-Trees to manage records (http://dev.mysql.com/doc/refman/5.5/en/index-btree-hash.html).
Look at list of data structures from wikipedia. Most of the data structures have real world examples or applications section on their own description page.
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.
What is the need of function in databse as everything that a function does, can also be achieved by Procedures in database.
In Oracle they are very similar. Principal difference is that function returns result, procedure doesn't. (Not to be confused with output parameters which is possible to have in both of them...)
This difference makes possible to use functions inside SQL statements like
select user_name, myFunction( some_attribute ) from ...
or
select ... where fn2(col1)=something
You can think of it as some kind of transformation.
Of course, for efficient use inside SQL statements, they should be fast, as can be executed many times for each line in output or each examined line. (And/or be sure that number of lines will not be too big).
Also, in recent versions is possible to use return as real time dbms_output (search for pipe row).
You can also use functions in function based indexes.
And these indexes can also be unique indexes.
With function based unique indexes you can build sophisticated unique constraints.
create unique index UK_MYINDEX
on TBL_MYTABLE (case when IS_ACTUAL(MY_COLUMN_2) then MY_COLUMN_1 end);
In this example I use the IS_ACTUAL function in a unique index in order to enforce the unique MY_COLUMN_1 constraint only on the actual records.
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.
Ive got an app containing contact list, similar to Contacts application. I have all the objects in an array, but I have another array for favourite contacts, which is displayed in another tab. The problem is that once I delete an objects from my contacts array, it stays in the favourites array. Any ideas how can this be solved? It would help a lot. Thanks
As the comments said, your language and array structure would be useful, but I'll try and answer from a "algorithm" perspective.
Your "Favourites" should contain the same objects as in your Contact list (and I assume that object has an ID. If it doesn't, put one in). From there you can say "if I delete from Favourites, simply remove that object from the array". Otherwise, "if I delete from the 'Contacts list' then iteratively remove all the equivalent objects from the other arrays".
Alternatively, if your "Favourites" array simply holds the ID of the contact (and to display it you retrieve the object from the Contact list), then similarly you can delete the number.
Hope this helps, and when you clarify your question more, I'm sure someone will give you a more efficient answer ;)
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.
Can I use malloc to add symbol table entries? How do I traverse the table to check if something is already there?
A "symbol table" doesn't describe a particular kind of data structure. It merely describes the primary modes of operation: adding symbols and retrieving symbols by name. Symbols here are basically attributed names. For a compiler class, one such an attribute could be IsAFunction.
C has very few built-in datastructures. You'd have to create one yourself in this case. In C++, it would just be a matter of a std::map<std::string, Attributes>. Now presumably if you're in a compiler class, you should already know how to implement datastructures in C (including the use of malloc()). If not, then a compiler class really isn't for you.
In general, symbol tables are implemented through hash tables. Hash tables have the advantage of O(1) store and retrieve, but they don't store data sequentially.
Assuming you're working in C you can uses malloc(), but it requires more work than that. The provided link should enlighten you.
I'v done that with a double chained linked list before. But now i will definitively do it with a hashtable.
It's just a datastructure.