473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

sequence to FULLY test AVL tree implementation???

I recently wrote an AVL tree class, I think its mostly working, but I want
to make sure. Assuming it uses integers, is there an insert/delete sequence
that is known to exercise every possible case of inserting and deleting?
Jul 22 '05 #1
3 4308
"Nobody" <no****@cox.net> writes:
I recently wrote an AVL tree class, I think its mostly working, but I want
to make sure. Assuming it uses integers, is there an insert/delete sequence
that is known to exercise every possible case of inserting and deleting?


Excellent question. But you could easily find one yourself by
adding a little bit of instrumentation to your insert and delete
routines and then testing random insert and delete sequences.
--
"Let others praise ancient times; I am glad I was born in these."
--Ovid (43 BC-18 AD)
Jul 22 '05 #2

Ben Pfaff wrote:
"Nobody" <no****@cox.net> writes:
I recently wrote an AVL tree class, I think its mostly working, but I want to make sure. Assuming it uses integers, is there an insert/delete sequence that is known to exercise every possible case of inserting and
deleting?
Excellent question. But you could easily find one yourself by
adding a little bit of instrumentation to your insert and delete
routines and then testing random insert and delete sequences.

I don't think there's much hope of exhaustively "find<ing> one
yourself" because a complete test list is just about uncountably large.
Still there are constructive answers to the issue.

Devise a test case for each of the major conditions in the spec. Then
test to see the spec is met. What if there is an even (or prime, or
2**n) inserts before a similar number of deletes? Consider if the
input sequence is sorted, or reversed, or some other pattern that
challenges the specification.

Each such test that the component passes increases your confidence that
it's "correct".

John

Jul 22 '05 #3
"John" <jp********@irisinternet.net> writes:
Ben Pfaff wrote:
"Nobody" <no****@cox.net> writes:
> I recently wrote an AVL tree class, I think its mostly working, but I want > to make sure. Assuming it uses integers, is there an insert/delete sequence > that is known to exercise every possible case of inserting and

deleting?

Excellent question. But you could easily find one yourself by
adding a little bit of instrumentation to your insert and delete
routines and then testing random insert and delete sequences.


I don't think there's much hope of exhaustively "find<ing> one
yourself" because a complete test list is just about uncountably large.


It's really not that hard. There are only 10! = 3,628,000
possible orders in which 10 integers can be inserted into a tree.
I bet that several of those exercise all the AVL insertion cases,
and that a large fraction of those cases has a corresponding
deletion order that exercises all the deletion cases. If not,
you can probably go up to at least 13! before the problem starts
to become impractical.

There are only 4 rebalancing cases for AVL insertion and 6
rebalancing cases for AVL deletion, and none of them is
particularly rare in practice. I assumed that these were the
cases the OP was interested in. If he has a broader definition
of "case" then I agree that it's quite possibly impractical.
--
"A computer is a state machine.
Threads are for people who cant [sic] program state machines."
--Alan Cox
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sensorflo | last post by:
After browsing though many newsgroups articels I'm still not shure how operator precedence, operator associativity, sequence points, side effects go together. Currently I have the following view: ...
53
by: Deniz Bahar | last post by:
I know the basic definition of a sequence point (point where all side effects guaranteed to be finished), but I am confused about this statement: "Between the previous and next sequence point an...
3
by: kevin | last post by:
Is that even possible? I am creating a web service in .NET to expose some already created .NET programs to other groups. One group is writing the client in PERL, and thus wishes the wsdl schema...
9
by: John Smith | last post by:
I've been playing with splint, which returns the following warning for the code below: statlib.c: (in function log_norm_pdf) statlib.c(1054,31): Expression has undefined behavior (left operand...
7
by: desktop | last post by:
In the C++ standard page 472 it says that you can construct a std::set in linear time if the constructor gets a sorted sequence of elements. But how is this possible when insert takes logarithmic...
13
by: stef mientki | last post by:
hello, I generate dynamically a sequence of values, but this "sequence" could also have length 1 or even length 0. So I get some line in the form of: line = '(2,3,4)' line = '' line = '(2)'...
5
by: Anan18 | last post by:
Hello sir, I'm supposed to Implement and Test the sequence Class Using a Fixed-Sized Array (Chapter 3), from Data Structures & Other objects using c++. The header file is provided, and so is a test...
21
by: bilgekhan | last post by:
After doing a succcessful insert() or find() on a set<Tcontainer is it possible to get the item number of this item in the set? (ie. its zero-based sequence number (position/location/rank/index)...
2
by: RolfK | last post by:
Dear ALL, I need some help on xsl:sequence. I'm using the Altova XSLT processor, but I'm quite confident it is not an processor issue. It's probably my bad knowledge of xslt 2.0. I have probably...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.