Saturday, August 28, 2021

Choose The Right Data Structure at The Right Time and Right Place

Sometimes it may happen for all of us as programmers, which data structure is suitable for this part of code? These days we have a basket full of various data structures, that most of which have similar functions. So which one is correct for my current problem? Ok now, I need to list the data structure in this part of my code which one is better? LinkedList or ArrayList, for answering these questions we must first have a clear understanding of the problem.
There is a very sacred book on computer science named Introduction to Algorithms, or briefly called CLRS, I suggest that everyone read this book at least once.
This book has a chapter named Complexity of Algorithms.

Types of Complexity

Okay, let's get to the point. As you can see, one of the most important factors in choosing a data structure is the complexity of the algorithms used in the program.
It means that before you choose the data structure from multiple choices you should detect first,
what is the dominant function in your application? And then you can choose the right data structure according to this function. For example, if most of your operations are 'insert' you should choose one data structure that has better complexity in the 'insert' function or if the most of operations are 'select' you should select another one that has good complexity in the 'select' operation.
So, what is complexity? The complexity of an algorithm is a measure of the amount of time and/or space required by an algorithm for an input of a given size (n).
There are 3 types of complexity:



from DZone.com Feed https://ift.tt/2WuL5or

No comments:

Post a Comment