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 ) เพื่อให้ส่วนที่สมดุล
การแปล กรุณารอสักครู่..
