Data Structures and Algorithms 101
Tags: datastructures, algorithms, beginners, tutorial
Published: 2022-06-20 20:03:45

## What is Data Structure?

  Is a collection of data values,the relationships among them  as well as the operations that can be applied to the data.

  In layman language,data structure is something that can be used to store and organize data to be use it in an efficient way when performing data operations. 

In its simplistic form:
> 
  >_Data + Structure = Data Structure,
            meaning without data(atomic value or collection of facts) and organization(the structure) of the data there is no data structure._


## Types of Data Structures

  Data Structures can either be:
 > 
1. primitive data structures (also known as built-in data types)- stores data of only one type. Examples are integer,floating point,character,pointer or 
2. non-primitive data structures (also known as derived data types which stores data more than one type. Such type includes array,linked list,queue,tree,graph.

### Data Structures enables us to:
>
1. Search for elements in the data structure 
2. Traverse or iterate through a data structure in some order
3. Insert one or more elements into our data structure
4. Delete elements from our data structure
5. Update elements to reflect the latest state of our data structure
6. Sort for reordering of elements in our data structure
7. Merge for merging elements in our data structure

### Advantages of Data Structures
>
- Efficiency - they facilitate efficient storage and retrieval of data for numerous use-cases
- Abstraction - each data structure provides clean interfaces in the form of operations exclusive of their abstract data types,making their internal implementation hidden from developers
- Composition -fundamental data structures can be combined to build more niche and complex data structures.

### Importance of learning data structures

> Data Structures are important so as to improve our problem-solving skills and increase efficiency by means of carefully organizing data.

## Algorithm

> Is a set of rules or step-by-step procedures that are to be executed in a specific order to get the desired output.
            or
> can also be defined as a finite set of steps carried out in a specific problem-solving operations.Meaning,it is not the complete code,rather it is the logic that can be implemented to solve a particular problem.

## Characteristics of algorithm
>
- Unambiguous - it should be clear and simple in nature and lead to meaningful outcome
- Input - it should have some input values.
- Output - every algorithm should have well-defined outputs
- Finiteness -  the steps of an algorithm should be countable and it should terminate after the specified number of steps
- Effectiveness - each step of an algorithm should be effective and efficient enough to produce results. Effectiveness of an algorithm is evaluated with the help of two parameters:
    - Time Complexity -which is the amount of time taken by the computer to run an algorithm. This is also called computational complexity of an algorithm. It can either be best-case,average-case or worst-case.We always aim for the best-case for effectiveness.
    - Space Complexity - which refers to the amount of computational memory needed to solve an instance of the problem.Actually,this is the total space taken by an algorithm with respect to the input size.The lower the space complexity of an algorithm,the faster the algorithm will work.

- Language Independent - algorithms should be language independent,meaning the algorithm should work for all programming languages and give same output.

## Why we need algorithms
We need algorithms for the following reasons
 >    . Scalability - breaks real-world problems into smaller steps so that it is analyzed easily.
     . Performance - algorithm help us break down big problems into smaller modules which makes the problem feasible and provide efficient performance driven solutions.

### Factors of an algorithm
When designing and algorithm consider these factors:
>
1. Modularity - breaks a big problem into smaller ones.
2. Correctness - analysis of the problem statement and consequently the algorithm must be correct.It should work correctly for all possible test cases of the problem at hand.A test case here,refers to a specification of inputs,executing conditions,testing procedures and expected results,which we can be developed from the problem statement itself.
3. Maintainability - it should be designed so as to be easy to maintain and refine it at some point without making major changes.
4. Functionality - steps of an algorithm should successfully solve a real world problem
5. User friendly -should be easy to be understood by developers
6. Simplicity - should be the simplest possible solution to a problem.Simplicity refers to the fact that the algorithm should have the best-case time complexity.It should be simple yet produce desired results in a time-efficient,keeping both time and space complexities in mind.
7. Extensive -  should facilitate re-usability.That is the programmers should be able to reuse it or extend for their own problem statement too. 

### Example

 Problem: Design an algorithm that accept two numbers and print their product

> 
_Step 1: START
Step 2: Declare variables a,b and product
Step 3: Read the values of a and b
Step 4: Multiply a and b
Step 5: Store the output of step 4 in product
Step 6: Print product
Step 7: STOP_