Algorithm training 𞓜 sword finger Offer 07 Rebuild binary tree

Method 1: recursion, starting from the root node, regards each node under the root node as the root node (the idea of recursion), and then according to the characteristics of preorder traversal, the first value of the traversal result is the value of the root node. Therefore, the recursive assignment process can be determined, and then the pos ...

Posted by Scabby on Tue, 08 Feb 2022 01:39:50 +0100

Algorithm self-study notes: binary search tree search operation

In this paper, we continue to build a binary tree, and the rest of the methods API: size() returns the total number of nodes select(int k) returns the key ranked K in the tree, that is, K keys are less than it Rank (key) returns the ranking of a given key, that is, the number less than the key in the tree To implement these methods, we ...

Posted by magie on Fri, 04 Feb 2022 08:56:12 +0100

Data structure notes - red black tree

1, The concept of red black tree Red Black tree is a binary search tree, but a storage bit is added on each node to represent the color of the node, which can be red or Black. By limiting the coloring mode of each node on any path from root to leaf, the red Black tree ensures that its longest path does not exceed twice the shortest path, so ...

Posted by aleX_hill on Tue, 01 Feb 2022 16:24:23 +0100

High order data structure and algorithm | RB_ Implementation of tree

Mangrove black Red black tree is a binary search tree, but a storage bit is added on each node to represent the color of the node, which can be red or black By limiting the coloring mode of each node on any path from root to leaf node, the red black tree ensures that no path will be twice longer than other paths, so it is close to balance ...

Posted by Jim from Oakland on Sun, 30 Jan 2022 22:15:21 +0100

[data structure] tree - traversal of binary tree (dynamic diagram, c + +, java, recursion, multi thought non recursion)

GitHub sync update (Classified): Data_Structure_And_Algorithm-Review (it's best to give a star!!!) The following is the main body of this article, and the following cases can be used for reference. Traversal of binary tree Traversing a binary tree is to access each node in the binary tree successively and only once according to a searc ...

Posted by jasonmills58 on Sun, 30 Jan 2022 18:12:42 +0100

Jianzhi Offer interview question: 09 rebuild binary tree

The algorithm is not the hard core "Nine Yang Sutra" in Jin Yong's martial arts novels, nor the lightweight "Lingbo micro step" ", which is the basic skill of programmers, just as people who practice martial arts need to take a horse step. Whether the Kung Fu is good or not depends on whether the horse step is not solid ...

Posted by icedude on Sat, 29 Jan 2022 23:58:27 +0100

Data structure - balanced binary tree (AVL tree)

preface First, let's think about an ordinary binary tree to save data. If you want to find a data, because the ordinary binary tree to save data is random, the time complexity to find the data is O(n). Back for convenience ,We also learn the binary search tree. Its definition is to put the number smaller than the root node on the left and ...

Posted by nmcglennon on Sat, 29 Jan 2022 20:34:12 +0100

Binary tree: the maximum and minimum depth of a binary tree

1, Maximum depth of binary tree Maximum depth of binary tree The maximum depth of binary tree can be achieved by recursion, level traversal and depth first traversal, but the simplest and easiest is recursion. 1. Recursive method 1) Determine the three elements of recursion Return value and parameters of recursive function: the return ...

Posted by Flinch on Sat, 29 Jan 2022 01:25:28 +0100

Basic problems of binary tree in classic force deduction

preface: The vast majority of binary tree problems can be solved by recursion. Mastering the first, middle and last sequence traversal and sequence traversal of binary tree is the basis for quickly solving binary tree problems. catalogue preface: Maximum depth of binary tree Idea: code: Same tree Idea: code: Symmetric binary tree Ide ...

Posted by Disgone on Fri, 28 Jan 2022 19:27:45 +0100

Sword finger offer (jz31--jz40) python!!

Number of occurrences of 1 in jz31 integers (from 1 to the number of occurrences of 1 in n integers) describe Enter an integer n and find the number of occurrences of 1 in the decimal representation of N integers 1 ~ n For example, the numbers 1, 10, 11, 12 and 13 containing 1 in 1 ~ 13 appear 6 times in total thinking Direct method: splice ...

Posted by johnpdmccall on Wed, 26 Jan 2022 18:15:45 +0100