Squaring n-bit int vs. multiplying two n-bit ints

前端 未结 6 648
南旧
南旧 2021-01-05 05:25

Disclaimer: Homework question. I\'m looking for a hint…

Professor F. Lake tells his class that it is asymptotically faster to square an n-bit integer than to multip

6条回答
  •  盖世英雄少女心
    2021-01-05 06:09

    My thought is that to multiply two n-bit integers your algorithm needs to cater for any two n-bit integers. That's (2^n)^2 possible inputs.

    A squaring algorithm only needs to handle 2^n possible inputs, although it can be modelled as a multiply algorithm with two inputs the same.

    My guess is that there would be some way to optimise the generic multiply algorithm when you know that both inputs will be the same, but I'd have to think about it. That's the line I'd be investigating, anyway...

提交回复
热议问题