الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

DeLete Binary Search Tree

مغلق
بدأه CoMPuTeR-SCIeNCe في 20 يوليو 2005 · 11 رد · 1,975 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

لو سمحتم اعضاء منتدى المحترمين

تحيه وبعد

عندي هوروورك عن delete binary search tree وتسليمه يوم 24 - 7 - 2005 الاحد القادم وبصراحه انا موفاهم طريقه حل هووموورك عدل فممكن احد يقدر يحلي السؤال او اي مساعده انا تقريبا حليت برنامج كله بس عندي function يبيني احلها وانا والله العظيم حاولت كثر ماقدر بس مامشا وياي الحل اتمنى احد بس يحلي بس function delete node وانا حاط ملف للسؤال ممكن اي احد يقرا لو حب يحلي السؤال واسف لو ازعجتكم بطلبي وهذا نص سؤال وحاط ملف شرح اكثر للسؤال وشكرا.

Binary search tree The deletion algorithm is not as straightforward as the inser-tion algorithm. There are three cases that are encountered when deleting an item – the item is contained in a leaf node, i.e., it has no children, the item is con-tained in a node that has one child, or the item is contained in a node that has two children.

If the item to be deleted is contained in a leaf node, the node is deleted and the pointer in the parent node is set to null.

If the item to be deleted is contained in a node with one child, the pointer in the parent node is set to point to the child node and the node containing the data item is deleted. This causes the child node to take the place of the deleted node in the tree.

The last case is the most difficult. When a node with two children is deleted, an-other node in the tree must take its place. However, the pointer in the parent node cannot simply be assigned to point to one of the children of the node to be deleted. In most cases, the resulting binary search tree would not adhere to the following characteristic of binary search trees: The values in any left subtree are less than the value in the parent node, and the values in any right subtree are greater than the value in the parent node.

Which node is used as a replacement node to maintain this characteristic? Ei-ther the node containing the largest value in the tree less than the value in the node being deleted, or the node containing the smallest value in the tree greater than the value in the node being deleted. Let us consider the node with the smaller value. In a binary search tree, the largest value less than a parent's value is located in the left subtree of the parent node and is guaranteed to be contained in the rightmost node of the subtree. This node is located by walking down the left subtree to the right until the pointer to the right child of the current node is null. We are now pointing to the replacement node, which is either a leaf node or a node with one child to its left. If the replacement node is a leaf node, the steps to perform the deletion are as follows:

1. Store the pointer to the node to be deleted in a temporary pointer variable (this pointer is used to delete the dynamically allocated memory)

2. Set the pointer in the parent of the node being deleted to point to the re-placement node

3. Set the pointer in the parent of the replacement node to null

4. Set the pointer to the right subtree in the replacement node to point to the right subtree of the node to be deleted

5. Delete the node to which the temporary pointer variable points.

The deletion steps for a replacement node with a left child are similar to those for a replacement node with no children, but the algorithm also must move the child in to the replacement node's position in the tree. If the replacement node is a node with a left child, the steps to perform the deletion are as follows:

1. Store the pointer to the node to be deleted in a temporary pointer variable.

2. Set the pointer in the parent of the node being deleted to point to the re-placement node

3. Set the pointer in the parent of the replacement node to point to the left child of the replacement node

4. Set the pointer to the right subtree in the replacement node to point to the right subtree of the node to be deleted

5. Delete the node to which the temporary pointer variable points.

Your public method deleteNode should take as its argument the value to be de-leted. It should locate the tree node containing the value to be deleted and use the algorithms discussed here to delete the node. If the value is not found in the tree, your function should return without doing anything.

After deleting an item, call the inOrder and postOrder traversal functions to con-firm that the delete operation was performed correctly.

Test your implementation by creating two binary search trees. The first should be created by entering the following values in the order shown: 10, 12, 5, 7, 2, 1, 3. The second tree should be created by entering the following values in the order shown: 10, 8, 15, 12, 20, 18, 25. Verify that you can delete any node in either of these trees and then correctly print both an inorder traversal and a postorder tra-versal of the resulting tree.

Assign_4.doc

#2

أخى للاسف الشديد المنتدى ليس لحل الواجبات

حاول ان تفكر وتجتهد وتطرح افكارك حتى نساعدك

Muhammad Allam

Computer Science

@Resource(MappedURL="My Blog" )

#3

اخي انا ملقلت احد يحلي الواجب انا واجب حليته كله بس عندي function delete ماعرفت احلها ابي احد يساعدني او يحلي كود كامل اذا احب وكون مشكور لو احد حلي بس يريت يكون الكود بسي او سي بلس بلس.

#4

أخى اذا كان كلامك صحيح (وانا مصدقك )

دة برنامج عن الtree

سهل وبسيط الفهم

يارب اكون أفتدك

Muhammad Allam

Computer Science

@Resource(MappedURL="My Blog" )

#5

خد المشروع دة عن الtree

ممكن يفيدك

trees____p162322822003.zip

Muhammad Allam

Computer Science

@Resource(MappedURL="My Blog" )

#6

حبيبي eng_3llam انته تستاهل بوسه *

^_^

بس يريت اوضحلك شي انا اعرف اسوي function delete node بطريقتي خاصه بس قصدي هل يمكن بس تقرا السؤال الي بالملف وتشوف اذا حلك نفسك طريقه الحل موجوده بسؤال ولا لا لني حليت بطريقه ودكتور ماده الي يدرسني قالي طريقه حلي خطأ معنه الناتج يطلع صح

بس يريت اتشوفلي هالشغله اذا ماتبي على راحتك وعالعموم مشكور على حسن تجاوبك وياي ومشكوررر وايددد الله يوفقق

#7
اقتباس
هل يمكن بس تقرا السؤال الي بالملف

للأسف أعذرنى لانى ليس عندى وقت

اقتباس
طريقه حلي خطأ معنه الناتج يطلع صح

الناتج صح والطريقة غلط ازاى دى ؟؟؟

ولا انت مفبرك الطريقة اة احنا ساعات بنعلم كدة ونعرف نتوهة الدكتور فى المناقشة المشروع ودى شطارة :lol:

ولا الدكتور عاوزك تعملها بطريقتة التى يعرفها يعنى يكون الكود بتاعك مماثل لكود بتاعة اللى هوة عاملة

البرمجة تفكير بمعنى ممكن انا اكتب دالة وانت تكتب نفس الدالة و كلا بيقوموا بنفس الطلب ولكن الكود مختلف

Muhammad Allam

Computer Science

@Resource(MappedURL="My Blog" )

#8

اوكي مشكور اتمنى احد من المندى غيرك يساعدني على حله

#9

الظاهر مافي احد يقدر يحل الهوموورك المهم مشكورين اتمنة لو احد ساعدني ابي فزعتكم الله خليكم نخيتكم مانخيت الذيب

#10

اكيد لو كان احد يعرف رح يساعدك .. لكن يمكن لان السؤال طويل ..

logo1.png تطبيق طمأنينة ، نسخة بيتا على أندرويد

عبدالله الشمّري - Al-Shammari

CodingAlone.com

twitter @abshammeri

abshammeri AT gmail.com

github : abshammeri

#11

ماشفت احد يحله حقي هل هو دليل على ضعف الشباب العربي بالبرمجه انا اعترف اني مو قوي بس يري احد يساعدني ويحله حقي

#12
اقتباس
ماشفت احد يحله حقي هل هو دليل على ضعف الشباب العربي بالبرمجه انا اعترف اني مو قوي بس يري احد يساعدني ويحله حقي

الله المستعان عيب انت معاك خيرة شباب ال++c وعلى راسهم eng_3llam والشمري الله يهديك

جزاكم الله خير يا شباب

هم عطوك المفتاح

اقتباس
نفسك طريقه الحل موجوده بسؤال ولا لا لني حليت بطريقه ودكتور ماده الي يدرسني قالي طريقه حلي خطأ معنه الناتج يطلع صح

الناتج صح والطريقة غلط ازاى دى ؟؟؟

ولا انت مفبرك الطريقة اة احنا ساعات بنعلم كدة ونعرف نتوهة الدكتور فى المناقشة المشروع ودى شطارة

اخي العزيز eng_3llam انا معك يا اخي اذا في الرياضيات(ةالبرمجة جزء من الرياضيات المتقطعة بلا شك ) اذا كان الناتج صحيحا فهذا الا يعني ان طريقة الحل صحيحة

وربما صحيحة ولكنها ليست الافضل optimum افضل مثال على ذلك مثلا

64 قسمة 16 = 4 قسمة عادية

64 قسمة 16 = 4 بما اننا اختصرنا 6 مع 6

بالمثل 95 قسمة 19

واكيد الدكتور يقصد الخطا من نا حية درجة تعقيد الخوارزمية للحلين

والله اعلم

أضاعوني وأي فتى أضاعـوا * * * ليـوم كــريهـة وســـداد ثغــــر

وخـــــلونـي ومعتـرك المنايـا * * * وقد شـــرعوا أسنــتهم لنحـري

كأني لم أكــــــن فيهـم وسيطـا * * * ولم تك نســبتي في آل عمــرو

أجرر في الجـــوامع كـل يـوم * * * ألا لله مظــــلمتـي وهـصـــري

عسى الملك المجيب لمن دعاه * * * سينجيني فيعلم كيــف شكـري

فأجـــزي بالكرامـة أهـل ودي * * * وأجزي بالضـغينة أهل ضري

منتديات الرياضيات العربية

هذا الموضوع مغلق.

مواضيع مشابهة