Tag: bisect
4 รายการ
Blog

leetcodepythonalgorithms
LeetCode #35 Search Insert Position: เต่า เหยี่ยว แมว ชิงตำแหน่งเสียบเลข
เทียบ 3 วิธีหาตำแหน่งแทรกในลิสต์เรียงแล้ว ตั้งแต่เดินทีละช่องถึง binary search และ bisect พร้อมเทสต์และ benchmark ที่รันจริง
pythonbisectalgorithms
Python bisect กับ key: แทรก record ลงลิสต์เรียงโดยไม่สร้าง key list ใหม่
ใช้ bisect_left และ insort_right กับ key function ให้ถูก โดยแยกค่าที่ค้นจาก record ที่แทรก พร้อม trade-off ของ O(log n) search กับ O(n) insertion
pythonbisectstdlib
Python bisect.insort: สอดค่าใหม่แล้วยังเรียงอยู่
ใช้ bisect.insort คงลิสต์เรียงตอนแทรก พร้อมตัวอย่าง unittest — เหมาะคิวคะแนน/ตารางเวลาเล็ก ๆ
pythonbisectalgorithms
Python bisect key=: ค้นช่วงในข้อมูลเรียงโดยไม่เรียก key ซ้ำเกินจำเป็น
ใช้ bisect_left กับ key อย่างถูกชนิด และเลือก precomputed keys หรือ cache เมื่อต้องค้นซ้ำบนข้อมูลเดิม