Data Structure is the way of structuring the data in the memory. In simple words, anything that can store data can be called a data structure. In the computer, data is stored in a format so that we could access it properly. Data is stored in the memory. A data structure is a way of storing and organizing data in such a way so that we can perform operations on these data in an efficient way. A data structure is an organization, management, and storage format.
Example: In an array, data is stored in a contiguous memory location.
There are two basic types of data structures.
Types of Data Structure:
- Primitive Data Structure: These types of the data structure are basic blocks. It is the fundamental data structure. The primitive type data structure is not created by the user. It comes as an inbuilt feature of the memory. A primitive data structure is used to make the non-primitive data structure. These are pure form and supported at the machine level.
Example. Integer, Character, Boolean, float, pointer, etc.
- Boolean, which stores logical values that are either true or false.
- integer, which stores a range on mathematical integers -- or counting numbers. Different sized integers hold a different range of values -- e.g., a signed 8-bit integer holds values from -128 to 127, and an unsigned long 32-bit integer holds values from 0 to 4,294,967,295.
- Floating-point numbers, which store a formulaic representation of real numbers.
- Fixed-point numbers, which are used in some programming languages and hold real values but are managed as digits to the left and the right of the decimal point.
- Character, which uses symbols from a defined mapping of integer values to symbols.
- Pointers, which are reference values that point to other values.
- String, which is an array of characters followed by a stop code -- usually a "0" value or is managed using a length field that is an integer value.
- Non-Primitive Data Structure or Abstract Data Structure: This type of data structure is used to store large and connected data. It is structured by using the primitive data structure. It is a type for objects whose behavior is defined by a set of operations. It is called abstract data structure because this data structure is defined with a set of rules. Non-Primitive Data Structure is created using the Primitive data Structure. A non-primitive data structure is further divided into two categories.
- Linear data structure: In Linear Data Structure, data are stored sequentially. In this type of data structure, elements are stored in linear order. In linear data structures, elements are stored in a non-hierarchical way. Searching and sorting are quite easy in the linear data structure. Array, Linked List, Stack, Queue comes in the linear data structure.
- Non-Linear data structure: In this type of data structure elements are arranged in a non-linear arrangement. The meaning of Non-linear arrangement is that elements will not assign memory in a sequence. In this data structure, items are connected with two or more other items in a non-linear way. In non-linear data structure memory utilization is effective because data is not assigned in a sequence, so it is scheduled in such a way so that memory could be utilized effectively. Trees, Graphs are the example of non-linear data structure.
Operations on data structure:
- Searching: Search for any element in a data structure.
- Sorting: Sort the elements of a data structure either in an ascending or descending order.
- Insertion: Insert the new element in a data structure at any specific position or in the front or rare position.
- Updation: Update the element, i.e., we can replace the element with another element.
- Deletion: Delete operation to remove the element from the data structure from the desired place.