DEV Community

Cover image for Introduction to Data Structures and Algorithms With Python.
hannahwn
hannahwn

Posted on

Introduction to Data Structures and Algorithms With Python.

Why Data Structures and Algorithms Are Important?

Data structures and algorithms provide a set of unique techniques for effectively managing data. A programmer should understand the basic concepts of data management .That is, to collect data a programmer needs to access and manage data effectively using data structures and algorithms .To write efficient code that handles data one needs to understand algorithms and data structure. It would take longer to resolve a problem if the programmer does not know the predefined algorithm techniques.
**

What are data structures?

**
A data structure is a format used to store and organize data. They are fundamental to all programming and most programming languages come with them built in.
Types of data structures
Lists
Lists can also be defined as arrays .They are ordered collections of data. To create a list we:

List = [1, 2, 3, "GFG", 2.3]
print(List)

Enter fullscreen mode Exit fullscreen mode

Tuples
A tuple is a list that cannot be modified but can have various types of data
Sets
Sets are used to include membership testing and eliminating duplicate entries
Stacks
A stack is like a list the only difference is you can add and remove the last item .If you have the list [1, 2, 3], you can delete the items it contains by first removing 3 then the rest. Removing an item from a stack is called popping.
To add items to the stack we use:

stack = Stack()
stack.push(1)
print(stack.is_empty()
Enter fullscreen mode Exit fullscreen mode

)
Queues
A queue is like a stack because you can only add and remove items in a certain order; the first item added is the first item removed
To add items on a queue we:

a_queue = Queue()

for i in range(5):
    a_queue.enqueue(i)
Enter fullscreen mode Exit fullscreen mode

Linked List
A linked list is where the elements are not stored at contiguous memory locations. A linked list is represented by a pointer to the first node of the linked list. The first node is called the head. If the linked list is empty, then the value of the head is NULL.
Dictionaries
A dictionary is a collection which is ordered*, changeable and do not allow duplicates. Dictionaries are used to store data values in key: value pairs. Dictionaries are written with curly brackets, and have keys and values:

thisdict = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
print(thisdict)
Enter fullscreen mode Exit fullscreen mode

An algorithm is a series of steps that can be taken to solve a problem.
To learn more about data structures and algorithms and the best way to use them here is a YouTube videohttps://www.youtube.com/watch?v=pkYVOmU3MgA

Top comments (0)