Introducción
¿Qué es un grafo?
¿Qué es un árbol?
¿Qué es recursión?
Aplicaciones reales de grafos y árboles
Formas de representar un grafo
DFS
Análisis de DFS: algoritmo de búsqueda en profundidad
Programando DFS de forma recursiva
Otras formas de programar DFS
Recorridos y profundidad de un Árbol
Sum Root to Leaf Numbers: análisis del problema
Solución de Sum Root to Leaf Numbers
Playground: Sum Root to Leaf Numbers
Programando Sum Root to Leaf Numbers en Golang
Number of Islands: análisis del problema
Solución de Number of Islands
Playground: Number of Islands
Programando Number of Islands en Python
Ejercicios recomendados de DFS
Ejercicios resueltos de DFS
BFS
Análisis de BFS: algoritmo de búsqueda en anchura
Programando BFS con Python
Minimum Knights Moves (movimientos de caballo en ajedrez): análisis del problema
Solución de Minimum Knights Moves
Playground: Minimum Knights Moves
Programando Minimum Knights Moves con Python
Rotting Oranges: análisis del problema
Solución de Rotting Oranges
Playground: Rotting Oranges
Rotting Oranges con Java
Shortest Bridge Between Islands: análisis del problema
Solución de Shortest Bridge Between Islands
Playground: Shortest Bridge Between Islands
Programando Shortest Bridge Between Islands con Python
Ejercicios recomendados de BFS
Ejercicios resueltos de BFS
Backtrack
Algoritmo de Backtrack
Letter Combinations of a Phone Number: análisis del problema
Solución de Letter Combinations of a Phone Number
Programando Letter Combinations of a Phone Number con C++
Playground: Letter Combinations of a Phone Number
Restore IP Addresses: análisis del problema
Programando Restore IP Addresses con C++
Playground: Restore IP Addresses
Word Search: análisis del problema
Solución de Word Search
Playgrund: Word Search
Programando Word Search JavaScript
Reto: N Queens Puzzle
Ejercicios recomendados de Backtrack
Ejercicios resueltos de Backtrack
Próximos pasos
¿Qué otros algoritmos y tipos de grafos puedes aprender?
¿Quieres más cursos avanzados de algoritmos?
You don't have access to this class
Keep learning! Join and start boosting your career
In this Platzi class, we delve into the fascinating task of solving the problem known as Letter Combinations of a Phone Number. The logic is simple at first glance: given a phone number as input (in the form of a string), we must return a list of all possible word combinations that can be formed with the telephone keypad. Have you ever thought about how the letters on a telephone keypad can be used to generate words? This is where the concept of backtracking cleverly comes into play.
When we talk about generating all possible combinations, we cannot help but think of efficient algorithms, and here backtracking plays an essential role. This method allows us to explore all possibilities of letter combinations while keeping the order intact, which is crucial in a phone number. The approach resembles that of a depth-first search (DFS), where we explore each node (or number) and its letters before moving on to the next one.
Understanding the problem:
Problem approach:
Structuring with hash table:
In pseudocode, the general idea for implementing this solution might look like the following:
# map from numbers to lettershash_table = { '2': ['A', 'B', 'C'], '3': ['D', 'E', 'F'], # ... continues to number 9}
def combine(number): # Empty initial solution solutions = [""]
# Iterate over each digit in the phone number for digit in number: # Get the letters corresponding to the digit letters = hash_table[digit] # Expand each current combination with the new letters new_list = [] for existing_solution in solutions: for letter in letters: new_list.append(existing_solution + letter) solutions = new_list
return solutions
# Example of useresult = combine("23")print(result)
hash table
and potentially hash set
to handle duplicates.Put together your own code to solve this exercise and experiment with the possibilities. As you progress, don't hesitate to rely on these techniques and tools such as backtracking, DFS, and efficient data structures. Don't stop here, keep exploring and improving!
Contributions 0
Questions 0
Want to see more contributions, questions and answers from the community?