As the name suggests, data structures allow us to organize, store, and manage data for efficient access and modification.
1. Lists
A list is defined using square brackets and holds data that is separated by commas. The list is mutable and ordered. It can contain a mix of different data types.
2. Tuples
A tuple is another container. It is a data type for immutable ordered sequences of elements. Immutable because you can’t add and remove elements from tuples, or sort them in place.
3. Sets
Set is a mutable and unordered collection of unique elements. It can permit us to remove duplicate quickly from a list.
4. Dictionaries
Dictionary is a mutable and unordered data structure. It permits storing a pair of items (i.e. keys and values). As the example below shows, in the dictionary, it is possible to include containers into other containers to create compound data structures.
5. Stack
Stack is a linear data structure where elements are arranged sequentially. It follows the mechanism L.I.F.O which means last in first out. Stack has the following operations:
- Push → inserting an element into the stack
- Pop → deleting an element from the stack
6. Queue
Queue is a linear data structure where elements are in a sequential manner. It follows the F.I.F.O mechanism that means first in first out. Queue has the following operations:
- Enqueue → inserting an element into the queue. It will be done at the rear.
- Dequeue → deleting an element from the queue. It will be done at the front.
7. Tree
Trees are used to define hierarchy. It starts with the root node and goes further down, the last nodes are called child nodes.
Algorithms
Algorithms are instructions that are formulated in a finite and sequential order to solve problems. When we write an algorithm, we have to know what is the exact problem, determine where we need to start and stop and formulate the intermediate steps. There are three main approaches to solve algorithms:
- Divide and Conquer → it divides the problem into sub-parts and solves each one separately
- Dynamic programming → it divides the problem into sub-parts remembers the results of the sub-parts and applies it to similar ones
- Greedy algorithms → involve taking the easiest step while solving a problem without worrying about the complexity of the future steps
Top comments (0)