# What are the algorithms and data structures?

A **data structure** is a named location that can be used to store and organize **data**. And, an **algorithm** is a collection of steps to solve a particular problem. Learning **data structures** and **algorithms** allow us to write efficient and optimized computer programs? Seems so simple right?

Let’s dive deeper!

Data Structures are the programmatic way of storing data so that data can be used efficiently. Almost every enterprise application uses various types of data structures in one or the other way. As applications are getting complex and data-rich, there are three common problems that applications face now-a-days.

**Data Search**− Consider an inventory of 1 million(106) items of a store. If the application is to search an item, it has to search an item in 1 million(106) items every time slowing down the search. As data grows, search will become slower.**Processor speed**− Processor speed although being very high, falls limited if the data grows to billion records.**Multiple requests**− As thousands of users can search data simultaneously on a web server, even the fast server fails while searching the data.

To solve the above-mentioned problems, data structures come to rescue. Data can be organized in a data structure in such a way that all items may not be required to be searched, and the required data can be searched almost instantly.

Anything that can store data can be called as a data structure, hence Integer, Float, Boolean, Char etc, all are data structures. They are known as **Primitive Data Structures**.

Then we also have some complex Data Structures, which are used to store large and connected data. Some example of **Abstract Data Structure** are :

- Linked List
- Tree
- Graph
- Stack, Queue etc.

All these data structures allow us to perform different operations on data. We select these data structures based on which type of operation is required.

The data structures can also be classified on the basis of the following characteristics:

- CharactersticDescriptionLinearIn Linear data structures,the data items are arranged in a linear sequence. Example:
**Array** - Non-LinearIn Non-Linear data structures,the data items are not in sequence. Example:
**Tree**,**Graph** - HomogeneousIn homogeneous data structures,all the elements are of same type. Example:
**Array** - Non-HomogeneousIn Non-Homogeneous data structure, the elements may or may not be of the same type. Example:
**Structures** - StaticStatic data structures are those whose sizes and structures associated memory locations are fixed, at compile time. Example:
**Array** - DynamicDynamic structures are those which expands or shrinks depending upon the program need and its execution. Also, their associated memory locations changes. Example:
**Linked List created using pointers**

Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain order to get the desired output. Algorithms are generally created independent of underlying languages, i.e. an algorithm can be implemented in more than one programming language. Every Algorithm must satisfy the following properties:

**Input**- There should be 0 or more inputs supplied externally to the algorithm.**Output**- There should be atleast 1 output obtained.**Definiteness**- Every step of the algorithm should be clear and well defined.**Finiteness**- The algorithm should have finite number of steps.**Correctness**- Every step of the algorithm must generate a correct output.

From the data structure point of view, following are some important categories of algorithms:

**Search**− Algorithm to search an item in a data structure.**Sort**− Algorithm to sort items in a certain order.**Insert**− Algorithm to insert item in a data structure.**Update**− Algorithm to update an existing item in a data structure.**Delete**− Algorithm to delete an existing item from a data structure.

An algorithm is said to be efficient and fast, if it takes less time to execute and consumes less memory space. The performance of an algorithm is measured on the basis of following properties :

- Time Complexity
- Space Complexity

# Space Complexity

Its the amount of memory space required by the algorithm, during the course of its execution. Space complexity must be taken seriously for multi-user systems and in situations where limited memory is available.

An algorithm generally requires space for following components :

**Instruction Space:**Its the space required to store the executable version of the program. This space is fixed, but varies depending upon the number of lines of code in the program.**Data Space:**Its the space required to store all the constants and variables(including temporary variables) value.**Environment Space:**Its the space required to store the environment information needed to resume the suspended function.

# Time Complexity

Time Complexity is a way to represent the amount of time required by the program to run till its completion. It’s generally a good practice to try to keep the time required minimum, so that our algorithm completes it’s execution in the minimum time possible.

Resources: