ABSTRACT
We present an immediate approach in hoping to bridge the gap between the
difficulties of learning ordinary Binary Search Trees (henceforth BST) and
their height-balanced variants in the typical data structures class. For each
node in the tree, instead of balancing the heights of the two children, we
balance the number of their nodes. The concepts and programming techniques
required are much easier than the AVL tree or any other height-balanced
alternatives. We also show that the height of a node-balanced tree is bounded
by c log n with c ≈ 1. Because of its simplicity, our approach is pedagogically
worthwhile to be introduced in the class to smooth student's learning process.
Our experimental results also show that node-balanced BST may also be
considered for practical uses under some reasonable conditions.
Keywords: Binary Search Trees, Node-Balanced Binary Search Trees, Data
Structures
INTRODUCTION
In a typical Data Structures syllabus for undergraduates, BST seems to be the first
real challenge for students, which is introduced after students have been familiar with
linked lists and had preliminary understanding of recursion. Then, about two weeks
(equivalently, six class hours) are needed to introduce the general concepts of the BST
including basic data structures, searching, traversals, insertion/deletion, and some
preliminary analysis. It certainly is not easy to manage all these concepts and necessary
programming techniques in six class hours, especially when students after CS1 and CS2 are not yet well-trained to manage complicated algorithms under today's programming
paradigm for beginners. Moreover, it makes only little sense to learn BST without
knowing how to balance them given the fact that a completely random data set is a
strongly theoretical assumption. Students should realize that the advantage of BST over
linked lists disappears when the height of BST grows out of control. There are many
alternatives to the ordinary BST. Many textbooks from old textbooks such as [6, 10] to
more recent ones like [5, 9] introduce the AVL tree1
as a supplement to the BST.
The standard AVL tree uses the balance-factor and four rotations (RR, LL, RL, and
LR) to keep the BST balanced, where the balance-factor is the difference between the
heights of a node's lift-child and right-child. While this standard solution is not too
difficult for an average student to understand, the implementation is rather involved.
However, many textbooks and instructors skip detailed discussion about the
implementation due to the time constraints. Students are on their own to program their
AVL trees. This may be reasonable because we intend to assume that students should
have learned sufficient programming skill from CS1 and CS2 to handle the details. But
it may not be the case in reality. Pedagogically, we should be aware of the potential
difficulties students may face. In their implementations, for example, students may use
very inefficient method to determine the balance factor. A common inappropriate
approach is to recursively calculate the heights of the two children. In such as way, the
program has to travel through the entire tree whenever a balance-factor needs to be
updated. Students may also use back-links for traveling back to the parent in order to
determine the type of rotation, but back-links make the implementation even more
difficult. Deletion a node from an AVL tree is worse. Many textbooks simply omit this
indispensable operation from their texts for no good reason.
Apart from the implementations, in order to help students appreciate BST and AVL
trees, some analyses are necessary. Unfortunately, the analyses are not straightforward
and many of them are out of the scope of the course. For example, the expected height
of a random binary search tree is asymptotically in O (log n). The proof requires
nontrivial mathematical background which is more suitable for the algorithm analysis
class (see [2] for a detailed proof). Without asymptotic notation, the exact bound of the
height of a random BST is much more complicated, which has been an active research
topic with some fundamental questions still open, e.g., [4, 7].
With these frustrations, as we have observed, balancing BST is unfortunately the
turning point where students begin dropping the course and change their majors to those
that demand less technical contents. This usually happens in the sixth week2
of the
semester when students are just about to begin to appreciate linked lists and binary search
trees.3
To smooth this learning difficulty in the classroom, an easier way to adjust
unbalanced binary search trees is needed. Two papers with this attempt have appeared in JCSC 21, 4 (April 2006)
240
SIGCSE 2005. In [8] Okasaki suggests a simple alternative to Red-Black trees, but his
method can't be extended to deletion. In [1] Barnes et al. present Balanced-Sample BST
in hoping to improve the balance of ordinal BST without demanding too many extra
techniques. Their method is indeed simple and straightforward. However, the
experimental results do not show significant improvement; only about 12% of
improvement in heights from the ordinary BST on random data.
Before our investigation initiated, we had had the following observation. When we
asked students what to do about an unbalanced BST, they usually responded intuitively
that we should move some nodes from the bigger child (the one with more nodes in it)
to the smaller one. If we approve this why-not-idea and give them some time, it is not
hard for students to figure out how to implement the idea. In fact, moving a node from
one child to the other is the easiest operation in reconstructing BST. Pedagogically, we
should let students practice this operation before rush them into more advanced
techniques. Therefore, we polish and analyze this intuitive idea and present what we call
the Node-Balanced Binary Search Tree in this paper.
นามธรรม
เรานำเสนอแนวทางทันทีในหวังที่จะลดช่องว่างระหว่างความยากของการเรียนธรรมดา
ต้นไม้ค้นหาทวิภาค ( ต่อจากนี้ BST ) และตัวแปรของพวกเขาสมดุล
ความสูงในระดับโครงสร้าง ข้อมูลทั่วไป สำหรับแต่ละ
โหนดในต้นไม้ แทนที่จะจัดความสูงของเด็กทั้งสอง เรา
ยอดโหนดของพวกเขา แนวคิดและเทคนิคการเขียนโปรแกรม
ต้องการจะง่ายกว่าต้นไม้เอวีแอล หรืออื่น ๆความสูงสมดุล
แทน เราพบว่า ความสูงของปมสมดุลต้นไม้ล้อมรอบ
โดย C กับ C ≈เข้าสู่ระบบ 1 เพราะความเรียบง่าย แนวคิดของเราคือ pedagogically
คุ้มค่าที่จะแนะนำในชั้นเรียนของนักเรียนเรียบกระบวนการเรียนรู้ .
ผลการทดลองของเรายังแสดงโหนดสมดุล BST ยังอาจ
ถือว่าใช้ประโยชน์ภายใต้เงื่อนไขที่เหมาะสม
คำสำคัญ : ต้นไม้ไบนารีค้นหาโหนดต้นไม้ค้นหาทวิภาค , สมดุล , ข้อมูล
ในเบื้องต้นโครงสร้างทั่วไปโครงสร้างข้อมูลหลักสูตรสำหรับนักศึกษา BST น่าจะเป็นครั้งแรก
ความท้าทายที่แท้จริงสำหรับนักเรียนซึ่งเป็นที่รู้จักหลังจากนักเรียนได้รับคุ้นเคยกับ
รายการที่เชื่อมโยงและมีความเข้าใจ เบื้องต้นการเรียกซ้ำ จากนั้นเกี่ยวกับสองสัปดาห์
( ก้อง , หกชั้นเรียนชั่วโมง ) ต้องการที่จะแนะนำแนวคิดทั่วไปของ BST
รวมทั้งโครงสร้าง ข้อมูลพื้นฐานการค้นหา traversals แทรก / ลบ , และบาง
เบื้องต้น การวิเคราะห์ แน่นอนมันไม่ง่ายที่จะจัดการ แนวคิดเหล่านี้ทั้งหมดที่จำเป็นและเทคนิคการเขียนโปรแกรมในระดับชั่วโมง
6 ,โดยเฉพาะอย่างยิ่งเมื่อนักเรียน CS1 cs2 ไม่ได้ การฝึกอบรมและการจัดการที่ซับซ้อนขั้นตอนวิธีในวันนี้โปรแกรม
กระบวนทัศน์สำหรับผู้เริ่มต้น นอกจากนี้ มันทำให้ความรู้สึกที่จะเรียนรู้เพียงเล็กน้อยส่วนโดยไม่
รู้วิธีการสมดุลได้ให้ข้อเท็จจริงว่า สุ่มสมบูรณ์ชุดข้อมูลเป็น
ทฤษฎีขอสมมุติ นักเรียนควรตระหนักว่าประโยชน์ของ BST กว่า
รายการการเชื่อมโยงจะหายไปเมื่อความสูงของ BST เติบโตออกจากการควบคุม มีหลายทางเลือกเพื่อสามัญ bst.
หลายตำราจากตำราเก่าเช่น [ 6 , 10 ]
ชอบคนล่าสุดมากกว่า [ 5 , 9 ] แนะนำและ tree1
เป็นอาหารเสริมเพื่อ bst.
ต้นไม้ AVL มาตรฐานใช้ปัจจัยความสมดุลและสี่รอบ ( RR , LL , RL และ
LR ) เพื่อให้ส่วนที่สมดุลซึ่งปัจจัยความสมดุล คือ ความแตกต่างระหว่าง
ความสูงของเด็กยกเป็นโหนดลูกขวา ขณะนี้โซลูชั่นมาตรฐานไม่เหมือนกัน
ยากสำหรับนักเรียนโดยเฉลี่ยที่จะเข้าใจการใช้งานค่อนข้างเกี่ยวข้อง .
แต่ตำรามากมาย และอาจารย์ข้ามการอภิปรายรายละเอียดเกี่ยวกับ
การใช้งานเนื่องจากเวลาจำกัด . นักเรียนด้วยตนเองของโปรแกรม
AVL ต้นไม้ นี้อาจจะเหมาะสม เพราะเราตั้งใจที่จะสันนิษฐานว่า นักเรียนควรได้เรียนรู้เพียงพอ
ทักษะการเขียนโปรแกรมจาก CS1 cs2 จัดการและรายละเอียด แต่
มันอาจไม่ใช่กรณีในความเป็นจริง pedagogically เราควรจะตระหนักถึงศักยภาพนักเรียน
ปัญหาอาจเผชิญ ในการใช้งานของพวกเขา ตัวอย่างเช่น นักเรียนอาจใช้วิธีไม่ได้ผลมากว่า
ปัจจัยความสมดุลโดยทั่วไปไม่เหมาะสม
วิธีการคือ recursively คำนวณความสูงของเด็กทั้งสอง ในสถานการณ์เช่นนี้ ,
มีโปรแกรมที่จะเดินทางผ่านต้นไม้ทั้งหมด เมื่อใดก็ตามที่ปัจจัยความสมดุลต้อง
ปรับปรุง นักเรียนอาจใช้ลิงก์ย้อนกลับเพื่อเดินทางกลับผู้ปกครองเพื่อ
ตรวจสอบชนิดของการหมุน แต่การเชื่อมโยงกลับทำให้การใช้งานมากขึ้น
ยากการลบโหนดออกจากต้นไม้เอวีแอล กำลังแย่ ตำราหลายเพียงละเว้นการดำเนินงานขาดไม่ได้นี้
จากข้อความของพวกเขาโดยไม่มีเหตุผล
นอกจากการใช้งานเพื่อช่วยให้นักเรียนชื่นชมและ BST AVL
ต้นไม้บางการวิเคราะห์ที่จำเป็น แต่การวิเคราะห์ไม่ตรงไปตรงมา
และมากของพวกเขาจะออกจากขอบเขตของหลักสูตร ตัวอย่างเช่น ความสูงที่คาดหวัง
ของต้นไม้ค้นหาทวิภาคแบบ asymptotically เป็น O ( log n ) หลักฐานที่ต้องใช้พื้นฐานทางคณิตศาสตร์
นอนทริเวียล ซึ่งเหมาะมากสำหรับ
การวิเคราะห์ขั้นตอนวิธี คลาส ( ดู [ 2 ] สำหรับหลักฐานรายละเอียด ) โดยเฉลี่ยโน้ต , แน่นอนผูกพันของ
ความสูงของ BST แบบซับซ้อนมากขึ้น ซึ่งมีหัวข้อวิจัย
ปราดเปรียวด้วยคำถามพื้นฐานที่ยังเปิดอยู่ เช่น [ 47 ] .
กับปัญหาเหล่านี้ เราได้สังเกตความสมดุล BST เป็นโชคร้าย
จุดเปลี่ยนที่นักเรียนเริ่มวางหลักสูตรและเปลี่ยนวิชาเอกของพวกเขาเหล่านั้น
ที่ความต้องการทางเทคนิคน้อยกว่าเนื้อหา นี้มักจะเกิดขึ้นใน 6 week2
เทอมของนักเรียน เพิ่งจะเริ่มต้นที่จะชื่นชมรายการที่เชื่อมโยงและต้นไม้ค้นหา
3
ไบนารีเพื่อความเนียนนี้การเรียนรู้ในชั้นเรียน วิธีที่ง่ายเพื่อปรับสมดุลต้นไม้ค้นหาทวิภาค
ที่จําเป็น สองเอกสารกับความพยายามนี้มีปรากฏใน 21 jcsc 4 ( เมษายน 2549 )
sigcse 240 2005 [ 8 ] okasaki เสนอทางเลือกที่ง่ายต้นไม้สีดำแดง แต่วิธีการของเขา
ไม่สามารถขยายการลบ ใน [ 1 ] บาร์น et al . ปัจจุบันสมดุล BST
ตัวอย่างในหวังที่จะปรับปรุงความสมดุลของส่วนเทคนิคพิเศษ
. โดยไม่เรียกร้องมากเกินไป วิธีของพวกเขาเป็นจริงที่ง่ายและตรงไปตรงมา อย่างไรก็ตาม
ผลไม่แสดงการปรับปรุงที่สำคัญ ; เพียง 12% ของการพัฒนาในความสูงจาก BST ธรรมดาบนข้อมูลสุ่ม
ก่อนที่การสืบสวน เริ่มต้นเราจะมีข้อสังเกตดังต่อไปนี้ เมื่อเรา
ขอให้นักเรียนทำอะไรเกี่ยวกับ BST สมดุล พวกเขามักจะตอบสนองสัญชาตญาณ
ที่เราควรจะย้ายบางโหนดจากเด็กกว่า ( หนึ่งกับอีกจุด )
ให้เล็กกว่านี้ ถ้าเรายอมรับเรื่องนี้ ทำไมไม่คิด และให้เวลา มันไม่ได้ยากสำหรับนักเรียน
หาวิธีที่จะใช้ความคิด ในความเป็นจริง การย้ายโหนดจาก
เด็กกับอื่น ๆ คือ การดำเนินงานที่ง่ายที่สุดในการสร้าง bst. pedagogically เราควรจะให้นักเรียนฝึกปฏิบัติการนี้
ก่อนจะวิ่งเข้าไปในเทคนิคขั้นสูงเพิ่มเติม ดังนั้น เราปรับและวิเคราะห์ความคิดนี้ง่าย และปัจจุบันสิ่งที่เราเรียกว่าการค้นหาแบบทวิภาคสมดุล
โหนดต้นไม้ในกระดาษนี้
การแปล กรุณารอสักครู่..
