DEV Community

Cover image for Data Structures And Algorithms(Day #1)
James Shah
James Shah

Posted on • Updated on

Data Structures And Algorithms(Day #1)

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:

GitHub logo jamesshah / Data-Structures-And-Algorithms

Data Structures And Algorithms For Learning Purpose.

Introduction

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-

  1. Linear
  2. Non-Linear

Basic Types Of Data Structure:

  • Array
  • Linked List
  • Stack
  • Queue
  • Tree
  • Graph

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:

Arrays

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[0] = first element, arr[1] = 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.

Pros:

  • 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.

Cons:

  • 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✌🏻.
Happy Coding!
πŸ’»πŸ–€

Top comments (6)

Collapse
 
cyber1998 profile image
Cyber Naskar

For two dimensional arrays, you should fix your second piece of code - both seem to be the same example.

Collapse
 
jamesshah profile image
James Shah

Ohhh thanks for that. There was a problem in embedding. Fixed itπŸ‘

Collapse
 
cyber1998 profile image
Cyber Naskar

The two pieces of code seem to have exchanged places now, the double dimensional array should actually come second according to what you wrote in the post, but currently it's at the top.

Thread Thread
 
jamesshah profile image
James Shah

It seems perfectly fine to me. I guess there is some issue on the website. I've double checked my side.

Collapse
 
jb7jay profile image
jb-7-jay

Very Good πŸ‘πŸ‘ Keep it up bro

Collapse
 
jamesshah profile image
James Shah

Thanks Brother ✌️