Why need data structure and algorithm? We need to provide an efficient way to find and solve a problem.
Data Structure: The contacts list in your phone is a data structure that organizes your contacts in a way that makes them easy to find and use. This list might be organized alphabetically, by first name or last name, or by other criteria, making it easy for you to find and contact the person you need.
Algorithm: For example, when you search for a contact by name, your phone's software likely uses an algorithm to search through the contacts list and find the contact you're looking for. Similarly, when you add or delete a contact from the list, your phone's software may use algorithms to update the list and ensure that it remains organized and easily searchable. So while the primary function of the Contacts list on your phone is to store and organize data, there is some algorithmic processing involved in managing and manipulating that data as well.
A data structure is a technique of storing and organizing the data in such a way that the data can be utilized in an efficient manner.A data structure is classified into two categories:-
- Linear data structure
- Non-linear data structure
The types of linear data structures are Array, Queue, Stack, Linked List......
- Array:- A collection of elements of similar data types in contiguous memory locations.
- Linked Lists:- A collection of elements, each of which contains a reference to the next element in the list.
- Stack:- Stack is linear data structure that uses the LIFO (Last In-First Out).
- Queue:- Queue is a data structure that uses the FIFO rule (First In-First Out).
A non-linear data structure is also another type of data structure in which the data elements are not arranged in a contiguous manner. As the arrangement is non-sequential, so the data elements cannot be traversed or accessed in a single run. In the case of linear data structure, element is connected to two elements (previous and the next element), whereas, in the non-linear data structure, an element can be connected to more than two elements.
Trees and Graphs are the types of non-linear data structure.
- Tree:- A tree is a non-linear data structure that is used to represent a hierarchical structure. It consists of nodes connected by edges, where each node has a single parent, except for the root node which has no parent.
- Graph:- A graph is a non-linear data structure that is used to represent a collection of vertices (nodes) and edges that connect them. Unlike a tree, a graph can have multiple edges connecting the same pair of vertices.