P54A (*) Check whether a given term represents a binary tree Write a predicate istree which returns true if and only if its argument is a list representing a binary tree. Example: (istree (a (b nil nil) nil)) T (istree (a (b nil nil))) NIL (define (i
Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as pos
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 2 3 题目大意:给定一个数字n,输出它能有多少种表示二叉搜索树的形式. 解题思路:因为是给一个数字n
刷题备忘录,for bug-free leetcode 396. Rotate Function 题意: Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a "rotation function" F on A as follow: F(k
347. Top K Frequent Elements Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2,2,3] and k = 2, return [1,2]. Note: You may assume k is always valid, 1 ≤ k ≤ number of unique elements. Your algorithm'
Description It's milking time at Farmer John's farm, but the cows have all run away! Farmer John needs to round them all up, and needs your help in the search. FJ's farm is a series of N (1 <= N <= 200,000) pastures numbered 1...N connected by N - 1
本文将主要讲述另一种树形结构,B 树:B 树是一种多路平衡查找树,但是可以将其理解为是由二叉查找树合并而来:它主要用于在不同存储介质之间查找数据的时候,减少 I/O 次数(因为一次读一个节点,可以读取多个数据): 一.结构概述 B 树,多路平衡查找树,即有多个分支的查找树:如图所示: B 树主要应用于多级存储介质之间的查找,图中的蓝色节点为外部节点,代表下一级存储介质:绿色节点则为内部节点:同时我们将B 树按照其最大分支树进行分类,比如图中的则为4 阶B 树: 对于 m 阶 B 树(m >= 2
先刷前四题,剩下的有空补. 792A New Bus Route 题意:给出x 轴上的n 个点,问两个点之间的最短距离是多少,有多少个最短距离. 思路:排序后遍历. 代码: #include<stdio.h> #include<algorithm> using namespace std; #define N 200005 int w[N]; int main(){ int n; while(~scanf("%d", &n)){ ; i<n; i+
前言 在上一节中,我们讲述了Splay的核心操作rotate与splay 本节我会教大家如何用这两个函数实现各种强大的功能 为了方便讲解,我们拿这道题做例题来慢慢分析 利用splay实现各种功能 首先,我们需要定义一些东西 各种指针 struct node { int v;//权值 int fa;//父亲节点 int ch[2];//0代表左儿子,1代表右儿子 int rec;//这个权值的节点出现的次数 int sum;//子节点的数量 }; int tot;//tot表示不算重复的有多少节点