# Data Structures and Algorithms

## Algorithm Find the level of the node whose node value is x in a binary tree

Find the level of the node whose node value is x, considering the unique case of the node int find_node_level(BTNode *bt, ElemType x, int h) { if (bt == NULL) return 0; else if (bt->data == x) return h; else { int l = find_node_level(bt->lchild, x, h+1); if (l != 0) return l; else return …

## [Sword Pointing OFFER] Tree JZ36 Binary Search Tree and Doubly Linked List

Article directory @[TOC] 1. Topic 2. Solution 2.1 The structure of the tree 2.2 Solution 1 Summarize 1. Topic Input a [binary search tree] , convert the binary search tree into a sorted doubly linked list. 2. Solution 2.1 The structure of the tree class TreeNode { int val = 0; TreeNode left = null; …

## [python] 4 ways to add elements to List

In Python, there are four ways to add elements to a List: append(), extend(), insert(), plus sign + [1] append() Appends a single element to the end of the List. It only accepts one parameter. The parameter can be any data type. The added element maintains the original structure type in the List. If this …

## Sequential lookup and sequential lookup of java versions with sentinels

import java.util.Arrays; import java.util.Random; class seqSearch { public static void main(String[] args) { seqSearch sq= new seqSearch(); //Generate a random array Random r = new Random(); int arr[] = new int [ 10 ]; for ( int i= 0 ;i<arr.length;i++){ arr[i] =r.nextInt(10); } System.out.println(Arrays.toString(arr)); System.out.println(sq.SeqSearch(arr,arr.length,3)); System.out.println(sq.SeqSearch2(arr,arr.length,3)); } /* Sequential search is also known as linear …

## Python implements tree structure

Trees are used in many areas of computer science, including operating systems, graphics, database systems, and computer networking. Tree data structures have a lot in common with their plant cousins. A tree data structure has roots, branches and leaves. The difference between a tree in nature and a tree in computer science is that a …

## LeetCode training (2) sum of two numbers, merge two ordered arrays

For LeetCode Day -02 topic source: https://leetcode-cn.com/ sum of two numbers Simple Given an integer [array] nums and an integer target value target, please find the two integers in the array whose sum is the target value target, and return their array indices. You can assume that there will only be one answer for each …

## java data structure—PriorityQueue (priority queue, heap)

java [data structure] —PriorityQueue (priority queue, heap) 1. What is PriorityQueue (priority queue, heap) 2. How to use 1. What is PriorityQueue ( [priority queue] , heap) The nature of the normal [queue] is first in, first out, elements are added at the end of the queue and popped at the head of the queue. …

## Data Structures and Algorithms – Linear Search – Sequential Search

This article is an original article by joshua317, please indicate: reprinted from joshua317 blog  Data Structure and Algorithm – Linear Search – Sequential Search – joshua317’s blog A brief description of [sequential search] What is a sequential search? Sequential search is to traverse the entire data list, and compare the elements with the given value …

## Data Structures and Algorithms – Breadth-First Traversal of Trees

Implementation: Add a node to the complete binary tree, so that the tree is still a complete binary tree after the addition class Node : def __init__ ( self , val) : self .val = val # data field self .left = None # left pointer field self .right = None # right pointer field …

## Common data structure of Stack (stack)

1. Theory introduction In the last article, we introduced the [heap in the data structure.] As the saying goes, the [stack] is not divided. Let’s continue to talk about the data structure of the stack. The stack is essentially a linear table with special requirements. If you are interested, you can learn about the linear …