basic applications of data structure [closed] - c

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.

Related

A lucky draw system [closed]

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.

Implementing a sparse matrix using a binary search tree [closed]

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.

VARBINARY or BINARY for byte arrays of 250-1000 bytes? [closed]

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 have to create a table in a database and one of the fields will contain between 250 and 1000 bytes. When it comes to read-write performance, should I use VARBINARY or BINARY(1000)? Does it matter?
As per this Reference, you should be using varbinary. binary is for fixed length, and your requirement is a variable-length field.
As for performance, I don't know if there'd be a difference. The best way to find out would be to view the execution plan or run a trace to see performance. I would safely assume that it is similar performance and negligable difference, although I'd still use varbinary at least if only for the reason you have a variable length requirement.
EDIT: this post assumes SQL Server. Please clarify your RDBMS.
My first thought on this would be: Test it
If you could make some quick tables and load some data into them with the different datatypes then query off of that. I would think that would give you a pretty good indication of which would be the better to use.
Sorry i don't have any concrete data to give you on performance, but i think that would be a fairly legit test for the answer. I'm interested in your results if you decide to go that route :)

best distance functions in distributed compuing [closed]

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.
What are the distance functions so far implemented to find the distance between two nodes in distributed networks like p2p? i mean if each leaf node in a p2p tree network represents some data, there should be some defined ways to find distance between these nodes. I want to know the general practices and the distributed functions that help us to determine the similarity between these nodes.
If my question itself is wrong please forgive me.
I can think of a few distance functions like this. It depends on what your application cares about. What are you using this distance function for?
Latency. When nodes talk to each other they directly measure the Round Trip Time (RTT).
Bandwidth. When nodes talk to each other they directly measure their bytes/sec transfer rate.
IP prefix. Nodes with very similar IPs are probably close together, so 149.89.1.24 and 149.89.1.100 are probably very close together. This is a very coarse heuristic.
My advice is to directly and continuously measure whatever you pick as your distance metric. The distance metric will change over time, so measure it continuously. Any estimate that isn't based on the individual nodes taking measurements is likely to be wildly inaccurate. You should also remember that network distances are asymmetric. Packets the flow from node A to node B might take an entirely different route than those flowing from B to A.
What are the distance functions so far implemented to find the distance between two nodes in distributed networks like p2p?
It depends of the method you are using (see CAN, Kademlia, Pastry (DHT), Tapestry (DHT), Koorde). But keep in mind that these distances are theoretical and not necessarily pratical.
In a real P2P implementation on ipv4, all NAT-ed peers only need a reachable peer with a public address. Meaning the 'distance' between two private peers is at most 2.

How to create a symbol table? [closed]

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.

Resources