Question (test instructions):
Describe a O (n LG (n))-time algorithm, given a set S of n integers and another integer x, determines whether or not th ere exist elements in S whose sum is exactly x.
Design an O (n LG (n)) time complexity algorithm, given a set of n numbers, and a number x, asking if it is possible to find two numbers in this set, their and exactly X.
Solution (Solution):
In an array to find a certain number, O (n LG (n)), it is easy to think of sorting
at a time until an empty slot is found and the key is stored in that position. For example, the hash value of the conflict is H, followed by the order of H+1, h+2, h+3 ...To prevent aggregation (clustering), the skip slots method can be used.(ii) quadratic probing (square probe): that is, the conflicting hash value is H, then the next lookup is h+1, followed by h+4,h+9,h+16 ...(2) Chaining (linked list method): All elements of the same hash value are saved in a linked list. However, the more el
value.Similarly, when an element of the RightMark position is greater than or equal to the base value, RightMark moves to the left one position to continue scanning, and the scan stops when the element of the RightMark position is less than the base value.After stopping the scan, we compare the size of the Leftmark and RightMark, if the Rightmark After we have put the datum values in the correct position, we see that the elements on the left side of the base value are smaller than the datum va
"Select Sort"The selection sort is based on a bubbling sort (Bubble sort) that has been improved: each visit process (pass) needs to be exchanged at most.Each visit process, to find the maximum value, when the end of the visit, the maximum value is exchanged to the correct position;Then continue to repeat the process in the remaining sublist until the n-1 visit is completed (n is the length of the list);At this point, the remaining elements in the list are automatically aligned to the correct po
;next = NULL;return OK;}Advantages and disadvantages of single linked list and sequential table storage structure
Storage mode
Time performance
Space performance
Sequential storage
Successive storage units are sequentially storedData Elements for linear tables
Insertion: O (1)Insert and delete: Average moveThe length of the table is half the element, the timeis O (n)
Easy Overflow
Single linked list
Use a set of ar
Unit
0-1:1-bit (2^1=2), bit, bit (b)
Bytes: 8 bits (2^8=256), Byte (B);
1kb:2^10 bytes (2^13 bit)
The ASCII encoding scheme is to represent a letter, number, or punctuation in a single byte.
Binary conversion
Decimal->n binary: a0xk^0+ .... Anxk^n
N Decimal: Take remainder
Hexadecimal--binary: 4 binary corresponds to 16 binary
C++
Basic program
#include
Input: scanf ("%d", num)
PLACEHOLDER: %d , (int) %c (char), %ul (unsigned long)
Note: Multiple
In machine learning, there are many problems, there is no analytic form of solution, or analytic form of the solution but the computation is very large (for example, the problem of the least-squares solution), for such problems, we usually choose to use an iterative optimization method to solve.These commonly used optimization algorithms include gradient descent method (gradient descent), conjugate gradient
ReferenceNB: High efficiency, easy to implement;LR: Less assumptions about data, strong adaptability, can be used for online learning, and the requirement of linearDecision tree: Easy to interpret, independent of data linearity or not; easy overfitting, no online supportRF: Fast and scalable, with few parameters, possibly over fittingSVM: High accuracy, processing of non-linear sub-data (high-dimensional data processing); Memory consumption, difficult
Complete color-to-gray algorithm Learning
Source: gameres Author: zyl910 Date: 2006/05/26
--------------------------------------------------------------------------------
File: studyrgb2gray.txt
Name: complete learning of color to grayscale Algorithms
Author: zyl910
Version: V1.0
Updata: 2006-5-22
I. Basics
There is a well-known psychological formula for the
MySpace qizmt is a mapreduce framework designed to run and develop distributed computing application projects running on Windows Server large-scale clusters. MySpace qizmt is an open-source framework initiated by MySpace to develop trustworthy, scalable, and super-Simple distributed application projects. Open Source Address: http://code.google.com/p/qizmt /.
Infer. NET is an open-source framework that runs Bayesian inference in graphical mode. It is also used for ProbabilityProgramDesign. Open
(First chapter above)1.2.5 Linalg Linear Algebra LibraryBased on the basic operation of matrices, the Linalg Library of NumPy can satisfy most linear algebra operations.. determinant of matrices. Inverse of the Matrix. Symmetry of matrices. The rank of the matrix. The reversible matrix solves the linear equation1. Determinant of matrices from Import * in[#N-order matrix determinant operation in [6]: A = Mat ([[[1,2,3],[4,5,6],[7,8,9]]) in [print]det (A):"6.66133814775e-162. Inverse of the Matrix
Decision tree is to select the most information gain properties, classification.The core part is to use information gain to judge the classification performance of attributes. The information gain is calculated as follows:Information entropy:Multiple categories are allowed.Calculates the information gain for all attributes, choosing the largest root node as the decision tree. Then, the sample branches, continuing to determine the remaining properties of the information gain.Information gain has
When we successfully implement a machine learning algorithm and use it to solve practical problems, we often find its performance(classification, regression accuracy) does not reach our satisfactory state. In this case, we have the following six optionsTo improve the performance of the current algorithm1 increasing the number of training sets this method is suitable for cases where the model has been fitted2 reduce the number of feature (use less feat
Write this code without hesitation: /* n: Array length for (i = 1 ; i int t = I; while (T > 0 ? a[t]]:0 ) { int k = a[t]; A[t] = a[t-1 ]; A[t -1 ] = K; T = t-1 ; }}The elements in the original a[i] have been found, if the order is correct, as compared to the previous one. A[0..I-1] elements are ordered, which is called "cyclic invariant" in the book.Also: can expressions in a while loop be written as "T > 0 a[t] "? Is it likely that an access is out of bounds? Ple
from small to large: \ n"); inti,j,x,m,p,q; inta[]={4,3,5,1,2}; I=0; J=4; X=A[i]; printf ("Original order:"); for(q=0;q5; q++) printf ("%d", A[q]); printf ("\ n"); while(ij) {if(a[j]x) {m=A[J];//Mark A[j], since the right move will overwrite the last for(p=j;p>0;p--) A[p]=a[p-1];//except the first one, all the rest, move right .a[0]=m; //Put the last one in the first place, that is, the whole sequence has a loop right shift x=a[++i]; //contrast item unchanged, but posit
* num2) {int TMP = * num1; * num1 = * num2; * num2 = TMP;} void selectsort (INT array [], int length) {If (array = NULL | L Ength
Ii. Tree-based sorting (tournament sorting)
Tree-based sorting is also called tournament sorting. First, the key words of N records are compared in pairs, and then the two smaller ones in n/2 are compared in pairs. This is repeated until the record with the minimum keyword is selected. This process can be represented by a Complete Binary Tree with N leaf nodes.
Cod
select the pivot record according to the rule of "getting the three", that is, compare the one in the middle of the low, high, and mid values as the pivot value, this greatly improves the performance of quick sorting in the worst case.
Summary:
1. In terms of time, the average performance of quick sorting is better than that of other sorting methods.
2. In terms of space, quick sorting requires a stack space to implement recursion.
References:
1. Edited by Yan Weimin Wu Weidong, data structur
table in the sorted order. Compared with direct insertion sorting, the difference is that the records are moved only by modifying the 2N pointer value, and the number of comparisons between keywords required in the sorting process is the same. Therefore, the time complexity of table insertion sorting is still O (N ^ 2 ).
References:
1. Edited by Yan Weimin Wu Weidong, data structure (C language version)
2. Data Structure and algorithm analysis-C language description Mark Allen Weiss translated
(); Treelinkedlist e =NewTreelinkedlist (); Treelinkedlist f =NewTreelinkedlist (); Treelinkedlist g =NewTreelinkedlist (); A =NewTreelinkedlist (NULL,0DNULL); b =NewTreelinkedlist (A,1, D,c.getfirstchild ()); c =NewTreelinkedlist (A,2,NULL,NULL); D =NewTreelinkedlist (b,3, F,e.getfirstchild ()); E =NewTreelinkedlist (b,4,NULL,NULL); f =NewTreelinkedlist (D,5,NULL, G.getfirstchild ()); g =NewTreelinkedlist (D,6,NULL,NULL); System. out. println (A.getdepth ()); System. out. println (B.getdepth (
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.