[data structure and algorithm] in-depth analysis of the solution idea and algorithm example of "different binary search tree II"

1, Title Requirements Give you an integer n, please generate and return all different binary search trees composed of N nodes with different node values from 1 to N, and you can return the answers in any order.Example 1: Input: n = 3 Output:[[1,null,2,null,3],[1,null,3,2],[2,1,3],[3,1,null,null,2],[3,2,null,1]] Example 2: Input: n = 1 ...

Added by waiwai933 on Thu, 06 Jan 2022 08:00:17 +0200

Luo Gu: P6687 on how to play with Excel tables [judgment questions (whether there is a solution) + finding the number of pairs in reverse order]

Valley: matrix rotation It can be found by observation that: For such a two column table, a 180 ° rotation of a 2x2 square is equivalent to the exchange of upper left and lower right, lower left and upper right And this exchange won't change anything? Two numbers in any column will not be changed! But it will change the positional rela ...

Added by littledragon on Thu, 06 Jan 2022 01:08:18 +0200

The transformation of recursive algorithm with classic cases (monkey eating peach problem) and irregular cases, including the core idea

1, Overview of method recursion 1. What is method recursion The form in which a method calls itself directly or indirectly is called method recursion. As an algorithm, recursion is widely used in programming languages. 2. Recursive form Direct recursion: the method calls itself. Indirect recursion: the method calls other methods, and othe ...

Added by dschreck on Mon, 03 Jan 2022 08:15:32 +0200

105 construct binary tree from preorder and inorder traversal sequences & & 106 construct binary tree from inorder and postorder traversal sequences (recursion + hash)

introduction These two questions are mainly to investigate the mastery of binary tree traversal, that is, the original binary tree is derived from the front order and middle order, and the original binary tree is derived from the back order and middle order. Let's talk about the derivation process first; Preorder and middle order Know the preo ...

Added by iarp on Sat, 01 Jan 2022 04:29:54 +0200

Recursive tutorial: a suspicious ambiguous list

Recently, an infinite classification of data was processed, mainly using recursive functions. Of course, laravel has a more elegant Association query method. However, due to the need for many other secondary modifications to the data, the original recursive processing was adopted. At the same time, an image metaphor was used to illustrate the p ...

Added by maralynnj on Wed, 22 Dec 2021 21:24:54 +0200

Computer experiment of data structure (Chapter 6) - tree and binary tree I

1. Establish the chain storage structure of binary tree (bracket representation) Algorithm idea: ① If ch = '(': it means that the node p just created has child nodes, and it needs to be stacked as the top node of the stack in order to establish the relationship between it and its child nodes (if a node has just been created, and the subsequ ...

Added by dotwebbie on Sat, 18 Dec 2021 12:28:04 +0200

Custom regular expression matching algorithm for Java

preface Customize the regular expression rules, and then complete the implementation of the matching algorithm. 1, Title Please implement a function to match regular expressions containing '.' and '*'. The character '.' in the mode represents any character, and '/ *' represents that the character before it can appear any time (in ...

Added by mbaroz on Wed, 01 Dec 2021 10:55:44 +0200

Recursive divide and conquer --- example 2. Chessboard coverage

Recursive divide and Conquer - Example 2. Chessboard coverage 1, Problem description In a chessboard composed of 2^k x 2k squares, exactly one square is incomplete. There are 2(2k) positions of incomplete squares. Therefore, there are 2^(2k) kinds of incomplete chessboard with K ≥ 0 In the problem of chessboard coverage, it is required t ...

Added by zedan_80 on Wed, 01 Dec 2021 00:57:27 +0200

LeetCode-131 split palindrome string

Split palindrome stringTitle Description: give you a string s. please divide s into some substrings so that each substring is a palindrome string. Returns s all possible segmentation schemes.A palindrome string is a string that reads the same forward and reverse.See LeetCode's official website for an example.Source: LeetCode Link: https://leet ...

Added by flashicon on Sun, 28 Nov 2021 03:44:42 +0200

LeetCode897 incremental sequential search tree & sword finger OfferII 052 flattening binary search tree

subject Problem solving The increasing order of binary search tree is the order of middle order traversal. LeetCode426 transforms binary search tree into sorted two-way linked list & sword finger Offer 36 binary search tree and two-way linked list The simple version of question 426 needs to construct a two-way circular linked list ...

Added by RobinTibbs on Thu, 04 Nov 2021 12:19:32 +0200