Violent recursive attempt
1: Hanoi Tower problem
Interview question 08.06. Hanoi Tower question LeetCode (LeetCode CN. Com)https://leetcode-cn.com/problems/hanota-lcci/
class Solution {
public:
void zhuanYi(int i,vector<int>&from,vector<int>&other,vector<int>&to){
if(i==1){int ding=from.back();from.pop_back();to.push_back(ding);}
...
Posted by GaryE on Fri, 03 Dec 2021 04:19:20 -0800
Java data structure and algorithm
preface
Data structure and algorithm is to estimate the time cost and space cost when the program runs on a large number of data sets!
1, Data structure
summary
data structure refers to the collection of data elements with one or more specific relationships.
structure
selecting an appropriate data structure can i ...
Posted by badal on Thu, 02 Dec 2021 20:19:57 -0800
Chapter 3 stack and queue
Chapter 3 stack and queue
Stacks and queues are linear tables that restrict inserts and deletions to the "end" (end) of the table
That is, stacks and queues are subsets of linear tables (linear tables with restricted insertion and deletion positions)
Stack features: first in, last out
Queue characteristics: first in first out
3.1 ...
Posted by lrdaramis on Thu, 02 Dec 2021 07:59:54 -0800
leetcode: 145. Post order traversal of binary tree
1: Recursive implementation
void endTraversal(struct TreeNode *root,int *ret,int *returnSize)
{
if(root)//If the tree is not empty, it will traverse, and if it is empty, it will end
{
endTraversal(root->left,ret,returnSize);//Postorder traversal of left subtree
endTraversal(root->right,ret,returnSize);//Postorder ...
Posted by the_924 on Wed, 01 Dec 2021 17:24:49 -0800
Basis of data structure -- sequence table and its addition, deletion, query and modification
One sentence a day
There is only one kind of heroism in the world, that is, to love life after recognizing the truth of life
catalogue
1. Data structure
2. Linearity table
3. Sequence table
Create classes and member properties and member methods
create object
1. Print sequence table: public void display()
2. Number of retur ...
Posted by crochk on Wed, 01 Dec 2021 12:46:16 -0800
Binary tree non recursive traversal algorithm
Preorder non recursive (stack implementation)
Algorithm idea:
Access the root node to the left and down in turn, and then immediately put the node on the stack (until the left child is empty);When you get to the bottom left, the top element of the stack goes out of the stack and turns to the right subtree (judge whether the right child is emp ...
Posted by djot on Wed, 01 Dec 2021 05:04:50 -0800
Time complexity and space complexity
Algorithm efficiency
There are two kinds of algorithm efficiency analysis:
Time efficiency,Space efficiency.
Time efficiency - > time complexity Space efficiency - > space complexity. Time complexity mainly measures the running speed of an algorithm, while space complexity mainly measures the additional space required by an algorithm I ...
Posted by siko on Wed, 01 Dec 2021 01:27:13 -0800
Balanced binary tree
In extreme cases, a binary search tree evolves into a tree with only one child on one side, such as a left or right child for each non-leaf. When searching, you need to traverse the tree to find the target value. Its fast search value is not reflected. If the search tree balances the height difference between left and right subtrees when it is ...
Posted by bben95 on Wed, 01 Dec 2021 00:31:56 -0800
LeetCode brush questions - restore IP address #93#Medium
Discussion on the idea and source code of restoring IP address The problem of restoring IP address is shown in the figure below. This problem belongs to the type of string and backtracking. It mainly focuses on the use of backtracking traversal method and the understanding of the characteristics of string itself. In th ...
Posted by pahunrepublic on Tue, 30 Nov 2021 20:45:04 -0800
[data structure] two way circular linked list
Structure of bidirectional linked list
1. Each node of the bidirectional circular linked list includes the following parts: 2. The data field in the header node has no practical significance
3. Bidirectional circular linked list For example:
Basic operation
data structure
typedef int LTDataType;
typedef struct ListNode
{
LTDataType ...
Posted by spillage on Tue, 30 Nov 2021 15:27:55 -0800