Skip to content

Conversation

@Mike0121
Copy link
Owner

@Mike0121 Mike0121 commented Aug 1, 2024

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一応ですが、ここで配列を舐めるので線形時間かかりますね。
あと、if not _is_sored(arr): でもいいかなと思いました

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

下ではif notにしてますね

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一応ですが、ここで配列を舐めるので線形時間かかりますね。
ご指摘のとおりですね。。。後から加えたのですが、意味なくなっちゃいますね。

あと、if not _is_sored(arr): でもいいかなと思いました 下ではif notにしてますね
有難うございます。ちょっと悩んだので、どっちのパターンも書いてみました。
選択の根拠は、みやすさ以外特に現状ないです。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

計算量が悪いコードも実装が単純だと入力次第では好まれることもありますし、あと速いがバグを埋め込みやすいコードの確認などにも使えますね。

計算量がよいこと自体には価値を見出さないほうがいいです。一方で、計算量から見積もられる「計算にかかる時間」はコードの選択の一つのよく使われる基準ではたしかにあります。しかし、基準の一つでしかありません。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odaさん
ありがとうございます。bisect_leftを見たときに疑問に思った点だったので実装しました。
下記覚えておきます。

計算量がよいこと自体には価値を見出さないほうがいいです。一方で、計算量から見積もられる「計算にかかる時間」はコードの選択の一つのよく使われる基準ではたしかにあります。しかし、基準の一つでしかありません。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

さっき出てたのでご覧になったかわかりませんが、これわかりやすかったです
Yoshiki-Iwasa/Arai60#35 (comment)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有難うございます!読みました、分かりやすかったです!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここで配列内の全要素見てるので、下で二分探索する意味が無い気がします。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご指摘ありがとうございます。そのとおりですね。元々のbisectになかったので、後から良かれと思って追加しましたが、意味無くなっちゃいますね。以後気をつけます。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 行に分けて書いたほうが読みやすいように感じます。

ただし、今回のコードでは関係ナインドエスが、値を swap する場合は 1 行で書いたほうが読みやすいと思います。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらの方が読みやすく感じました。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nodechipさん、ありがとうございます。
自分で気づけたのでよかったです。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

私はこれは、if にしますが、趣味の範囲でしょう。ところで、少し空行が多い気がします。

@Mike0121 Mike0121 merged commit 923dabc into main Nov 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants