2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Author's homepage: Knowing that a lonely cloud has emerged from a mountain
The time complexity of inserting an element into an array is ().
A. O(1)
B. O(n)
C. O(log n)
D. O(n^2)
In heap sort, the time complexity of building a maximum heap is ().
A. O(n)
B. O(n log n)
C. O(log n)
D. O(n^2)
A red-black tree is a ().
A. Complete binary tree
B. Balanced Binary Tree
C. Minimum Heap
D. Max Heap
The following statement about hash table is wrong ().
A. The search time complexity of a hash table is O(1)
B. The insertion time complexity of the hash table is O(1)
C. Hash tables can resolve conflicts
D. The search time complexity of a hash table must be O(1)
In graph traversal, the time complexity of depth-first search (DFS) and breadth-first search (BFS) are ().
A. O(V + E) and O(V)
B. O(V^2) and O(V)
C. O(V + E) and O(V + E)
D. O(V) and O(V^2)
The time complexity of reversing a singly linked list is ().
A. O(1)
B. O(n)
C. O(log n)
D. O(n^2)
In a binary search tree, the worst time complexity of deleting a node is ().
A. O(1)
B. O(n)
C. O(log n)
D. O(n log n)
Which of the following sorting algorithms has an average time complexity of O(n log n) ().
A. Bubble sort
B. Quick sort
C. Insertion sort
D. Selection sort
In a binary tree, the degree of a node is ().
A. The number of child nodes of this node
B. The depth of the node
C. The height of the node
D. The node's level
The main difference between B-tree and B+tree is ().
A. All nodes of the B-tree store data, while only leaf nodes of the B+ tree store data
B. B-tree is more balanced than B+ tree
C. B-tree insertion and deletion operations are simpler
D. B+ tree search efficiency is lower
Please implement a function to determine whether a linked list is a palindrome linked list.
def is_palindrome(head):
# 请在这里编写代码
Please write code to implement the insertion operation of the binary search tree.
class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def insert(root, key):
# 请在这里编写代码
Given a graph, represented by an adjacency matrix, implement a breadth-first search (BFS).
def bfs(graph, start):
# 请在这里编写代码
Properties of Red-Black Trees:
How red-black trees maintain balance:
The difference between dynamic arrays and linked lists:
The principle of hash table:
Determine whether the linked list is a palindrome linked list:
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
def is_palindrome(head):
# 使用快慢指针找到链表中点
slow = fast = head
while fast and fast.next:
slow = slow.next
fast = fast.next.next
# 反转后半部分链表
prev = None
while slow:
temp = slow.next
slow.next = prev
prev = slow
slow = temp
# 比较前半部分和后半部分
left, right = head, prev
while right:
if left.val != right.val:
return False
left = left.next
right = right.next
return True
Insertion operation of binary search tree:
class TreeNode:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def insert(root, key):
if root is None:
return TreeNode(key)
if key < root.val:
root.left = insert(root.left, key)
else:
root.right = insert(root.right, key)
return root
Breadth First Search (BFS):
from collections import deque
def bfs(graph, start):
visited = [False] * len(graph)
queue = deque([start])
visited[start] = True
result = []
while queue: