联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codehelp

您当前位置:首页 >> OS程序OS程序

日期:2023-10-11 09:38

Problem 2: Find stone pair(s)
There are N number of stones, labeled as [0, N-1]. We know the weight of each of those stones. We want to find ONE stone pair, i.e. 2 stones,
whose weight difference is D.
Question A
Formally describe the problem to clearly define the problem without ambiguity. Something like:
write a function F that …
the inputs of the function are …
the output of the function are ….
This question might be harder than you thought. Please think carefully.
Question B
Write the function you described in your answer to question A.
What is the space complexity of your algorithm? What is the time complexity?
Can you achieve O(N) for both time complexity and space complexity? If yes, please implement it.
Write a test program to test your function.
Please list all corner cases you want to test
How to verify the function can process these corner cases correctly? Can you do it in a more systematic way?
Question C (optional)
Same as the original question B, but this time we want to find ALL stone pairs whose weight difference is D. Please note that pair (1, 4) and pair
(4, 1) are considered as the same pair, so only need to return one. Your algorithm’s time complexity should be O(max(R, N)), R is the number of
result pairs, N is the number of stones.

版权所有:留学生编程辅导网 2021,All Rights Reserved 联系方式:QQ:99515681 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。