The end of the holiday - 8 kinds of optimization of algorithms such as quick sorting rekindle your desire to learn

Bubble sorting and its optimization Basic idea of bubble sorting 1. Access each element of the array from scratch and exchange between adjacent elements 2. Exchange elements in pairs. Change the small one to the front and the large one to the back. 3. After all elements are exchanged, one exchange is completed, and the largest element will ...

Posted by james_4k2 on Thu, 07 Oct 2021 11:34:15 -0700

The kth largest element in the array of LeetCode

The title requires the k-largest element in the array. My most direct idea is to sort the whole array and then return the k-largest element in the array. 1. Bubble sorting To complete the sorting of the array nums, bubble sorting requires nums.size() - 1 round of sorting, because the last element does not need to be sorted. Bubble sort e ...

Posted by capitala on Thu, 07 Oct 2021 08:33:11 -0700

Interview question 8 - next node of binary tree

Title: Given a binary tree and one of its nodes, please find the next node in the middle order traversal order and return. Note that the nodes in the tree contain not only left and right child nodes, but also pointers to parent nodes. Problem solving ideas: Let's take the above figure as an example. The middle order traversal of the binary ...

Posted by lemonpiesaregood on Thu, 07 Oct 2021 08:19:57 -0700

Python implementation of single linked list

The first is the representation of nodes in Python Similar to C language, C language is represented by structs, while Python is represented by classes 1. Use class to represent nodes class ListNode(object): def __init__(self,val,next = None): self.val = val #Data domain self.next = next ...

Posted by zampu on Wed, 06 Oct 2021 23:48:04 -0700

Personal notes on data structure Lesson 8 circular linked list & linked list

Circular linked list As long as the two ends of the linked list are connected, it becomes a circular linked list, which is usually called circular linked list It should be noted that although the circular linked list is a ring, it is still a linked list in essence. Therefore, in the circular linked list, you can still find the head pointe ...

Posted by Merve on Wed, 06 Oct 2021 21:17:00 -0700

Data structure -- linked list

Linked list Single linked list: a linked list refers to a linear structure connected in series through pointers. Each node consists of two parts, one is the data field, the other is the pointer field (storing pointers to the next node), and the pointer field of the last node points to null (null pointer). The entry node of the linked list ...

Posted by kks_krishna on Wed, 06 Oct 2021 21:12:57 -0700

[sword finger Offer] stack and queue

Sword finger Offer 59 - I. maximum value of sliding window Given an array num and the size k of the sliding window, please find the maximum value in all sliding windows. Example: input: nums = [1,3,-1,-3,5,3,6,7], and k = 3 output: [3,3,5,5,6,7] explain: Position of sliding window Maximum --------------- -- ...

Posted by marsupillami on Wed, 06 Oct 2021 19:55:20 -0700

7, Binary tree (18): path sum

Force button topic link (opens new window) Given a binary tree and a target sum, judge whether there is a path from root node to leaf node in the tree. The sum of all node values on this path is equal to the target sum. explain:   A leaf node is a node that has no children. Example:   Given the following binary tree, and the ...

Posted by pbdude23 on Wed, 06 Oct 2021 17:19:01 -0700

7-37 Xiaoming typing (10 points) (data structure) The simplest code to write the simplest data structure

Xiao Ming is typing a document using Microsoft Word. The document contains only a-z lowercase letters and spaces. During typing, the Home key, End key, _arrow key, _arrow key, Insert key, Backspace key may be pressed one or more times. Write a program that gives Xiao Ming the sequence of keys on the keyboard and outputs the final text displayed ...

Posted by Otoom on Wed, 06 Oct 2021 15:29:22 -0700

The linked list completes the addition and subtraction of two polynomials

Content: complete the addition operation of two polynomials. It is known that there are two polynomials PM (x) and QM (x). Design an algorithm to realize the operation of Pm(x)+Qm(x) and Pm(x)-Qm(x). Moreover, the wig operation does not reopen the storage space, and it is required to be realized by chain storage structure. Steps: algorithm an ...

Posted by blckspder on Wed, 06 Oct 2021 12:20:44 -0700