DEV Community

Cover image for Introduction to Data Structures and Algorithms With Python
Eunice-777
Eunice-777

Posted on

Introduction to Data Structures and Algorithms With Python

Data structures allow us to organize, store, and manage data for efficient access and modification.
There are four types of data structures in Python:
• List
• Tuple
• Set
• Dictionary
LIST
A list is defined using square brackets. It can contain a mix of different data types. It holds data that is separated by commas. A list is ordered and you can modify the values in it. Example:
Tasks=[“Work”, “Code”, “Cook”, “Rest”]
TUPLE
A tuple is defined using brackets. It is similar to a list but once you create a tuple you cannot modify the values in it. Example:
Tasks=(“Work”, “Code”, “Cook”, “Rest”)
SET
A set is defined using curly brackets. The values in it can be modified and in no particular order. It has no key value pair and no repeated data. It can help us to remove repeated values from a list. Example:
Tasks={ “Work”, “Code”, “Cook”, “Rest”, “Cook”, “Code”, “Work”}
DICTIONARY
A dictionary is also defined using curly brackets and the data in it does not need be ordered. It permits storing a pair of items. Example:
user{
“Name”: “Dianne”
“Age”: “67”
}

ALGORITHMS
Algorithms are instructions that are made in a finite and sequential order to help solve problems.
There are three main approaches to solve algorithms:
• Divide et Impera (also known as 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 ;Involves taking the easiest step while solving a problem without worrying about the complexity of the future steps

Top comments (0)