What is a data structure?
A data structure is a way of organizing data so that they can be accessed efficiently in the computer.
Types of data structures
There are two categories of data structures: Linear and Non-linear data structures. Linear data structures
Here, elements are arranged sequentially and each element is connected to the previous and the next adjacent. Examples:
1. Arrays
Elements of the same type are stored where each element is accessed using an index
Strength: Access is done in constant time.
Weakness: Fixed size
2. Stack
LIFO- Last In First Out
Strength: Insertion and deletion are done in constant time Weakness: Search is done in linear time
3. Queue
FIFO- First In First Out
Strength: Insertion and deletion are done in constant time
Weakness: Search is done in linear time
4. Linked List
This consists of nodes where each node has a data field and a reference to the next node in the list.
Strength: Insertion and deletion are done in constant time and has Dynamic size
Weakness: Requires additional memory for pointer and search is done in linear time
Non-linear data structures
Elements are not connected in any sequence. An element can be connected to one or more elements. Examples:
1. Trees
Elements are arranged in multiple levels. Data is stored in a node and the data is of any type. Examples: B-Tree, Binary tree, B+ tree, Binary search tree
2. Graphs
Consists of nodes and edges. The edges connect a pair of nodes
What is an algorithm?
An algorithm is a defined set of steps or instructions to be followed to solve a problem. Algorithms can be written as flowcharts, natural languages or pseudo code.
Types of algorithms
- Search engine algorithm
- Greedy algorithm
- Recursive algorithm
- Backtracking algorithm
- Divide and conquer algorithm
Sorting algorithm
Characteristics of algorithms
Have well defined inputs
- Are clear and unambiguous
- Have well defined outputs
- They should be language independent
Importance of data structures and algorithms
- Data structures help us to organize and store data while algorithms enable us to process the data in a meaningful way. As a programmer understanding data structures and algorithms, you will be able to write code that is efficient and reliable.