The basic data structure leetcode

2, the list

2,1, problem-solving skills

  • Using the pointer speed (sometimes need to use three pointers)
  • Flip the list
  • Looking penultimate k elements
  • Looking in the middle of the list elements
  • Determining whether a cycloalkyl list
  • Construction of a false list head
  • Two sorted lists, sorting integration
  • The parity sequence originally isolated in the list, generate the first half of an odd number, the latter part of an even number

2.2, how to train the skills

In the process of the mutual relationship between the class of white paper or draw the modified node shown

Figment of the imagination is more difficult

Painted in white class, will make the interviewer clearly see ideas

3. Stack

3.1, the characteristics of the stack

  • LIFO

3.2, the basic idea of ​​the algorithm

  • Can be achieved with a single linked list
  • Only care about the last operation
  • After a post-processing operation, the more can be found in the previous operation O (1) time

4, queue

4.1, queuing features

  • FIFO

4.2, commonly used scenes

  • Breadth search

5, deque

5.1, commonly used scenes

A dynamic change in length of the window or continuum

6, the tree (master key)

6.1 commonality, tree

  • Intuitive structure
  • To examine the recursive algorithm mastered by tree problem proficiency

The nature of the tree, often requires that each node must meet

  • When you define a binary search tree, no node must be a binary search tree
  • Seeking depth binary tree

6.2, the shape of the tree have often test interview

  • Ordinary binary tree
  • Balanced binary tree
  • Complete binary tree
  • Binary search tree

Special tree: red-black tree (do not understand)

6.3, often test

Traversal (recursive and non-recursive writing)

  • Preorder traversal (search tree, and create a new number to use)
  • Traversal sequence ( 二叉搜索树the sequence at this time is the access to the order of elements)
  • Postorder (when the need to modify the left and right child nodes, the leaf node modified information collected from the bottom to the heel)

[Pictures of foreign chains dump fails, the source station may have a security chain mechanism, it is recommended to save the picture down directly upload (img-0DLBPm2k-1585481734514) (C: \ Users \ Administrator \ AppData \ Roaming \ Typora \ typora-user-images \ 1585465293114.png)]

7, priority queue

(More complicated to achieve, in solving problems in the interview Oh, you can implement ism)

Nature

Binary heap structure, using an array of binary tree structure to achieve complete

[Pictures of foreign chains dump fails, the source station may have a security chain mechanism, it is recommended to save the picture down directly upload (img-guRQ7EXS-1585481734516) (C: \ Users \ Administrator \ AppData \ Roaming \ Typora \ typora-user-images \ 1585465613098.png)]

[Pictures of foreign chains dump fails, the source station may have a security chain mechanism, it is recommended to save the picture down directly upload (img-361HmvMI-1585481734518) (C: \ Users \ Administrator \ AppData \ Roaming \ Typora \ typora-user-images \ 1585465639989.png)]

Basic Operations

  • Screening Up
  • Screening down

`Time complexity: O (logk)

Another important time complexity: Priority Queue initialization time complexityo(n)

Feature

The difference between ordinary queue

Taken to ensure that each element is the highest priority queue

Priority can be customized

The most commonly used scenes

From the data in the chaotic (or priority) of data in a certain order filter

	* 给定一个数组,找到前k个大的数
	* 求前k个高频元素
	* 关键如何定义优先级

8, FIG.

[Pictures of foreign chains dump fails, the source station may have a security chain mechanism, it is recommended to save the picture down directly upload (img-Iv12U9vN-1585481734520) (C: \ Users \ Administrator \ AppData \ Roaming \ Typora \ typora-user-images \ 1585465974189.png)]

[Pictures of foreign chains dump fails, the source station may have a security chain mechanism, it is recommended to save the picture down directly upload (img-SvKEcsCs-1585481734522) (C: \ Users \ Administrator \ AppData \ Roaming \ Typora \ typora-user-images \ 1585465989483.png)]

9, the prefix tree

[Pictures of foreign chains dump fails, the source station may have a security chain mechanism, it is recommended to save the picture down directly upload (img-XBOatO6V-1585481734526) (C: \ Users \ Administrator \ AppData \ Roaming \ Typora \ typora-user-images \ 1585466149662.png)]

Here Insert Picture Description

10, segment tree

Here Insert Picture Description

11, Fenwick tree

Here Insert Picture Description

Published 223 original articles · won praise 22 · views 20000 +

Guess you like

Origin blog.csdn.net/ZHOUJIAN_TANK/article/details/105184564