Stacks and queues
A data structure is a way of organising information so that certain operations are easy and fast. You already know lists…
Learn to organise information with the classic structures of programming. In this lesson you will build and use stacks, queues and deque, linked lists, binary search trees, graphs with breadth-first and depth-first traversals, and priority queues with heapq, and you will learn to choose the right structure for each problem.
A data structure is a way of organising information so that certain operations are easy and fast. You already know lists…
A Python list stores the elements one next to another. A linked list does something different: each element lives in a node that…
A tree is a structure of nodes organised hierarchically: there is a root node and each node can have children . They appear…
A graph is a set of nodes (vertices) joined by edges . It models networks of all kinds: road maps, friendships in a social…
In a normal queue the one who arrived first goes first. In a priority queue the one with the highest priority goes first, even if…
Create a Python program that checks whether the parentheses, square brackets and curly braces of a text are correctly matched. It…
Create a Python program that evaluates expressions in postfix notation (RPN), where operators come after the operands. They are…
Create a Python program that solves the Josephus problem with a double-ended queue ( deque ): n people stand in a circle and one…
Create a Python program that simulates the back and forward buttons of a browser using two stacks .
Create a Python program that implements a singly linked list with a Node class (value and next) and a LinkedList class (head)…
Create a Python program that merges two sorted linked lists into a single sorted list by reusing the nodes, without creating an…
Create a Python program that builds a binary search tree (BST) and queries it. In a BST, values smaller than a node go to its…
Create a Python program that finds the shortest path (fewest edges) between two nodes of an undirected graph using a…
Create a Python program that counts the connected components of an undirected graph (groups of nodes that can reach each other)…
Create a Python program that manages a priority queue of tasks with the heapq module: the task with the lowest priority number…