Question:
What are data structures?
ShqiptarProgrammer
2015-02-05 10:28:54 UTC
I am looking for some one to give me a basic understanding of what a data structure is. Currently I am studying linked lists in C++. I have an elementary understanding of C++ and I am a novice programmer. I know what objects, pointers, and functions are. What I don't understand is what a data structure really is. As far as linked lists are concerned, I know they are similar to an array that doesn't require a block of adjacent memory but they also seem kind of like an object.

Can someone just give me a basic explanation? I have looked for an answer and even asked my professor but he is really bad at explaining things.
Three answers:
Kookiemon
2015-02-05 12:08:31 UTC
A data structure is a convenient method for keeping properties of an object together.



eg.



    Customer Personal Data



    Customer object

        Name : John Doe

        Age : 32

        Adddress : 1234 Main Street

        City : Anywhere

        State : Virginia

        Zipcode : 12345



There are different ways of implementing this and they will be different based on the programming language that you use. I'll use C++ as an example. This is a Struct in its most basic form.



    struct Customer

    {

        char[ 40] name;

        int age;

        char[ 40] address;

        char[ 20] city;

        char[ 20] state;

        char[ 10] zipcode;

    }



    ...

    int main()

    {

        Customer[ 20] Customer_List;



        Customer_List[ 0].name = "John Doe";

        Customer_List[ 0].age = 32;

        ...



        return 0;

    }



By using a data structure, you can now dynamically access, add, and remove objects from a list. You can make a generalized script to add customer information.



eg.



    // Function declaration

    //    Ideally you would create a method inside of a Class.

    Customer addCustomer( void)

    {

        Customer NewCustomer = new Customer();



        cout << "Enter customer name : ";

        cin >> NewCustomer.name;



        ...



        cout << "Enter zip code : ";

        cin >> NewCustomer.zipcode;



        return NewCustomer;

    }



    Customer_List[ 1] = addCustomer();



This is a very simplified example. One would preferably use a Class in this example where you would have method that would add and/or edit the contents of a data structure. This is where you would also control who and what has access to the information contained in a structure. It's also how you would programmatically authenticate the information entered.



There are many different types of data structures, not just ones that hold such straight-forward data. You've already mentioned linked lists which is a data structure that organizes data. The uses go on and on and on and is only limited by your imagination.
?
2015-02-05 10:43:21 UTC
Data Structures are ways to organize data, so it is easier to access and use. Data structures can be very basic:

An Array is one of the simple data structures. It is good for data which you want to access either serially (i.e. 1, 2, 3) or randomly using an index. But not so good for updating the data in the structure.

A Linked List is a slightly more complex data structure which is good for serial access, but bad for random access. However it is easier to add and remove elements from a Linked List than from an Array.

Other common data structures: Binary Trees, Heaps, Self balancing Binary Trees (e.g. AVL), B-Trees, Queues, FIFO, etc.

Each type of data structure has things that it makes easy to do and things it makes hard to do.



When you understand how you want to manipulate your data, you can pick a data structure that makes it easier to perform those operations.
Chris
2015-02-05 10:37:40 UTC
Basically anything more complex than a single variable is a data structure. Wikipedia has a nice list of them: http://en.wikipedia.org/wiki/List_of_data_structures#Linear_data_structures



In general, whenever you organize multiple values in a specific way for efficiency, you have probably created a data structure. There's really not much more to the term itself; learning about the different types and when to use which one is what's important.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...