Algorithm Pen Questions

Source: Internet
Author: User

1. Assuming x=500, the return value of the following function is6_ .

12345678910 int fun(int x){    int countx = 0;    while (x)    {        countx++;        x = x & (x – 1);    }    return countx;

Parsing:x& (x-1) is the first 1 that is encountered from right to left (including 1) all becomes 0, more intuitive: it results in a reduction of 1 in the X-binary. Answer: How many bits in x binary 1 will be performed and calculated.

The binary representation of 500 is: 111110100, a total of 6 1. So the answer is 6. 2. There are two n*n matrices A and B, want to be on the PC by the matrix multiplication basic algorithm programming realization computation a*b. Assuming that n is large and the native memory is large, a, B, and result matrices can be saved. So, in order to calculate the speed, how a and B should be stored in memory (the first row is stored by the row, then the second line, until the last row, the first column is stored first, then the second column, and then the last column)? are saved as rows.

Algorithm Pen Questions

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.