Data Structures And Algorithms (2 Part Series)
Hello There, My Gorgeous Friend On The Internet
So, After two and a half years of college and almost a year of serious coding, now I want to start competitive programming. And before starting with the challenges, I decided to brush-up my Data Structure and Algorithms skills.
So I've started learning data structures from today and I decided to start posting about it here to keep track of my progress and to share it with you, comrades.
Check out my GitHub repository for all the programs:
Data Structure is basically a way to store and organize data for efficient use. Organized data is far more easy to use than unorganized data.For example, think about the words in a dictionary. They are organized in alphabetical order and thus, it is easy to find a word from it. The same way, when in a computer we need to organize data for efficient and easy use;
data structure is the answer.
Data Structures can be-
Basic Types Of Data Structure:
- Linked List
Tree and Graph are two examples of non-linear Data Structure.
The rest of them are linear Data Structure.
Now, Let's start with the first Data Structure:
Simply, an Array is a collection of elements of the same data type such as Integer or String. So, we can use an array to store data of the same data-type. For example, we can store the "name of people" in a String type Array, we can store "age of people" in an Integer type Array, etc.
- We access elements of an array using index. arr[i] = ith element.
- Array index starts from 0. i.e. arr = first element, arr = second element.
Here is a simple program implementing an Array in Java.
- We can also create Multi-Dimensional Arrays.
- Multi-Dimensional Arrays are useful to implement Matrices.
Here is a simple program implementing a Two Dimensional Array in Java.
- An array is useful for fixed-size data and when we know the total number of elements already.
- We can do pretty much all the operations on an array such as inserting an element at a particular position, removing an element from a particular position, read the value of an element from a particular position.
- It is costly to implement dynamic array. i.e, When we don't know the size of an array, we randomly create an array of some size and if we need to put more elements than the size of our array - we need to create a new array of double size, copy all the elements of old array to the new array, and then insert new elements. It is costly in terms of time complexity and thus, not practical.
Thanks For Scrolling, Stick Around✌🏻.