Introducción

1

¿Qué es un grafo?

2

¿Qué es un árbol?

3

¿Qué es recursión?

4

Aplicaciones reales de grafos y árboles

5

Formas de representar un grafo

DFS

6

Análisis de DFS: algoritmo de búsqueda en profundidad

7

Programando DFS de forma recursiva

8

Otras formas de programar DFS

9

Recorridos y profundidad de un Árbol

10

Sum Root to Leaf Numbers: análisis del problema

11

Solución de Sum Root to Leaf Numbers

12

Playground: Sum Root to Leaf Numbers

13

Programando Sum Root to Leaf Numbers en Golang

14

Number of Islands: análisis del problema

15

Solución de Number of Islands

16

Playground: Number of Islands

17

Programando Number of Islands en Python

18

Ejercicios recomendados de DFS

19

Ejercicios resueltos de DFS

BFS

20

Análisis de BFS: algoritmo de búsqueda en anchura

21

Programando BFS con Python

22

Minimum Knights Moves (movimientos de caballo en ajedrez): análisis del problema

23

Solución de Minimum Knights Moves

24

Playground: Minimum Knights Moves

25

Programando Minimum Knights Moves con Python

26

Rotting Oranges: análisis del problema

27

Solución de Rotting Oranges

28

Playground: Rotting Oranges

29

Rotting Oranges con Java

30

Shortest Bridge Between Islands: análisis del problema

31

Solución de Shortest Bridge Between Islands

32

Playground: Shortest Bridge Between Islands

33

Programando Shortest Bridge Between Islands con Python

34

Ejercicios recomendados de BFS

35

Ejercicios resueltos de BFS

Backtrack

36

Algoritmo de Backtrack

37

Letter Combinations of a Phone Number: análisis del problema

38

Solución de Letter Combinations of a Phone Number

39

Programando Letter Combinations of a Phone Number con C++

40

Playground: Letter Combinations of a Phone Number

41

Restore IP Addresses: análisis del problema

42

Programando Restore IP Addresses con C++

43

Playground: Restore IP Addresses

44

Word Search: análisis del problema

45

Solución de Word Search

46

Playgrund: Word Search

47

Programando Word Search JavaScript

48

Reto: N Queens Puzzle

49

Ejercicios recomendados de Backtrack

50

Ejercicios resueltos de Backtrack

Próximos pasos

51

¿Qué otros algoritmos y tipos de grafos puedes aprender?

52

¿Quieres más cursos avanzados de algoritmos?

You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesión a prueba de IA

Antes: $249

Currency
$209
Suscríbete

Termina en:

0 Días
22 Hrs
14 Min
47 Seg

Solución de Letter Combinations of a Phone Number

38/52
Resources

How to solve the Letter Combinations of a Phone Number?

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.

What is backtracking and why is it useful here?

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.

How do we implement the solution?

  1. Understanding the problem:

    • A telephone keypad contains letters associated with the numbers 2 through 9.
    • For example, the number "2" corresponds to the letters "A", "B", "C" and "3" to "D", "E", "F".
  2. Problem approach:

    • Using backtracking allows full exploration of all combinations in an efficient manner.
    • Recursion helps to maintain simplicity by processing each digit and combining the possibilities.
  3. Structuring with hash table:

    • We will create a hash table that associates each number from 2 to 9 with its respective list of letters.
    • This table facilitates quick access to the corresponding letters and allows iterative aggregation of solutions.

Example implementation

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)

What elements to consider when implementing?

  • Optimization: Avoid redundant iterations by using efficient data structures such as hash table and potentially hash set to handle duplicates.
  • Iteration: Decide when and how to use recursion to manage the growth of the tree of possibilities without compromising performance.
  • Scalability: Make sure the solution is scalable for longer phone numbers.

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

Sort by:

Want to see more contributions, questions and answers from the community?