Data structures and algorithms incorporated and Overview

Chapter One classical algorithm face questions

1.1 string matching problem

  • ① has a string str1 = "How are you my bad bad is not good that I do not please you," and a sub-string str2 = "I'm so bad for you."
  • ② now we need to determine whether str1 contains str2, if there is, please return to the first occurrence of the problem, if not, it returns -1.
  • ③ requirements with the fastest speed to complete the match?

 

  • Ideas ①: Matching violence
  • For example: first with the "I" to match str1 str2 in, find the first str1 is "no", not match, and str1 continue in "good" match, not match, continue, to know matching " I "word, and then continue to take the" good "go and str1 in the" I "behind the character" does not "match, no match is found, continue to use str2 in the" I "go and str1 is" ​​no "match and then repeat this process, know all the characters and str1 str2 in a substring matching to.
  • Question: match violence to solve if there are a lot of backtracking, a time to move one, if not match, then move up a judge, a waste of time.

 

  • Ideas ②: KMP algorithm (partial match table).

1.2 Tower of Hanoi

  • A disk ① all moved to column C column.
  • ② The disk can not be enlarged small disk.
  • ③ can only move a disc between three columns.

 

  •  Ideas: Use divide and conquer algorithm.

1.3 Eight Queens problem

  • International players busy Western Felix Bethel presented in 1848: placing eight queens on an 8 x 8 grid of chess, it can not be total with each other, namely: Any two queens can not be in the same line, the same the column or the same slash and asked how many there are in place. 92 kinds.

 

  •  Ideas: backtracking algorithm.

1.4 horse riding board (Knights travel around)

  • Horse riding board algorithm, also known as the Knights travel around the algorithm.
  • A horse box will randomly on the international chess 8 * 8 chessboard, the horse moves in accordance with the rules of chess go (horse walking day). It requires each box is only entered once traveled all the 64 squares on the chessboard.

 

  •  Ideas: the depth of the traversal algorithm of FIG optimization (DFS) + greedy optimization algorithm.

 

The importance of Chapter II data structures and algorithms

  • Algorithm is the soul of the program, the program can be excellent when massive data computing, remains a high-speed computing.
  • 一般来讲,程序会使用内存计算框架(如Spark)和缓存技术(如Redis)来优化程序,那么这些计算框架和缓存技术,其核心功能是什么?

 

Guess you like

Origin www.cnblogs.com/xuweiweiwoaini/p/11306512.html