Data structures are systematized ways of organizing data in order to use that data efficiently. There are some characteristics of every data structure that make it efficient. In this answer, we'll discuss those characteristics briefly and try to simulate them with basic examples. Let's have a look at the characteristics below.
There are three main characteristics:
This property is related to the algorithm of data structures. It's important that the algorithm is correct. Correctness here means that the algorithm always produces the expected output or follows the ground truth for the range of valid inputs, and eventually, it terminates. It is important because you're relying on it for the desired output.
There are further two types of correctness:
An algorithm is partially correct if it receives valid input and gets terminated. We can prove it through
An algorithm is totally correct if it receives valid inputs and gets terminated, and always returns the correct output. We can prove this formal reasoning or mathematically, for instance, by proof by induction.
Note: If you want to read more about correctness, click here.
The running time or execution time of a data structure as a function of the length of the input is known as time complexity.
It's a type of computation complexity that describe the time your algorithm needs to be executed. It should be as small as possible because the more time your data structure takes, it will decrease its efficiency.
Example: The access time complexity of an array is
Note: If you want to read more about time complexity, click here.
When an algorithm or data structure runs on your computer, it needs some sort of space/memory. The total memory space your data structure needs for its execution or to work properly is known as space complexity. Again, it should be as small as possible for data structures because it's one of the important factors in efficiency.
Example: A hashtable has a space complexity of
Note: If you want to read more about space complexity, click here.
Note: An efficient data structure execute quickly and save memory during the process.
Free Resources