Doeg Network - pen questions

database

analysis:

select SC.S#  from  (

    select  max(GRADE)  as grade from SC where SC.C# = 'C2'

) as temp

join SC on temp.grade = sc.GRADE

or:

select sc.S# from (

select S#, RANK() over(order by GRADE desc) rk from SC where SC.C# = 'C2' 

) sc

where rk = 1

 

Student number to find out the top three grades:

select  temp.S#  from(

    select  rank() over( order by sc.grade desc) rk , * from SC

) as temp

where rk <= 3

C # grouped according to performance ranking:

select  rank() over( partition by C# order by sc.grade desc)  , * from SC

 

Sort by:

row_number()  :123

Rank () : The first display in parallel, the latter postponed: 113

DENSE_RANK () : as juxtaposed, the latter continuously: 112

C

select  ename , sal from emp where sal <= (select min(sal) from emp) + 1000

Analysis : select min (sal) from emp find minimum wage

(Select min (sal) from emp) + 1000 minimum wage plus one thousand yuan

sal <= (select min (sal) from emp) + 1000 not exceeding $ 1,000 minimum wages

B:select  sal+1000  from emp where sal <= (select min(sal) from emp) + 1000

A:select  ename , sal from emp where sal <=  1000

D:  select  ename , sal from emp where sal > (select min(sal) from emp) + 1000

 

Multi-process memory allocation

 

 

Fill in the blank:

The more than one tree into a binary tree requires two steps : the first son of a multi-node tree as the left node of a binary tree, its sibling node as a binary tree right

Database protection is generally divided into : security control, integrity control, and production control, data recovery

 

Analysis: Option B is "may", not "necessarily"

Analysis C:

 

Initial data set has no effect on the performance of the algorithm is: heap sort

Links: https://www.nowcoder.com/questionTerminal/dc08e40e6c164dfb89c74c55839dedef?orderByHotValue=1&page=1&onlyReference=false
Source: Cattle customer network

1, algorithm complexity independent of the initial state are: selection sort, heap sort, merge sort, radix Sort.

2, comparing the total number of elements irrespective of the initial state: selecting order of ranking base.

3, the total number of moving elements are independent of the initial state: merge sort, radix sort.

 

 

Fast row: instability, the worst O (n * n) average O (n * logn) optimal O (n * logn)

 

 

Programming the big question:

public class test {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int num[]={-1,0,1,2,-1,4};
		Arrays.sort(num);
		List<List<Integer>> res=new ArrayList<List<Integer>>();
		for(int i=0;i<num.length-2;i++) {
			if(i>0&&num[i]==num[i-1])continue;
			int temp=-num[i];
			int l=i+1;
			int r=num.length-1;
			while(l<r) {
				if(num[l]+num[r]>temp) {
					r--;
				}
				else if(num[l]+num[r]<temp) {
					l++;
				}
				else {
					res.add(Arrays.asList(num[i],num[l],num[r]));
					l++;
					r--;
					while(l<r&&l<num.length-2&&num[l]==num[l-1])l++;
					while(l<r&&r>0&&num[r]==num[r+1])r--;
				}
			}
			
		}
		for(int j=0;j<res.size();j++)
			System.out.println(res.get(j));
	}

}

1. 将数组排序
2. 遍历数组,将将 a + b + c = 0 转换为 a + b = -c
3. 如果当前元素与上一个元素一致,直接跳过
4. 定义两个下标,分别从数组两端,即(i+1)跟数组最后一个元素开始,往中间扫描,如果,两元素的和,大于目标值(-c),则后面的下标往前移动;如果两元素的和小于目标值,则前面的下标往后移动;如果正好等于目标值,则发现一组目标,两下标均往中间移动
5. 两下标往中间移动的同时,判断是否与上一个相同,如果相同,继续移动
6. 输出结果

思路:

  1. 首先对数组进行排序,时间复杂度为O(n*logn)
  2. 然后对数组进行两层的遍历,先取出当前遍历的数字为nums[i],然后从数组两侧取出数字分别为nums[begin]和nums[end],然后三个数求和值为sum
  3. sum == 0,将三个数加入结果之中,同时将两侧的下标向中间移动,直到不与之前取出的数字相同,避免出现重复的三元组
  4. sum > 0,因为数组有序,说明右侧的数字过大,所以下标左移,故而执行end–
  5. sum < 0,因为数组有序,说明左侧的数字过小,所以下标右移,所以执行begin++
  6. 因为两层的遍历时间复杂度为O(n^2),O(n*logn) + O(n^2) = O(n^2),所以总体时间复杂度为O(n^2)

 

 

Guess you like

Origin blog.csdn.net/qq_39474604/article/details/94318971