User Tools

Site Tools


Sidebar

projects

  • php0 (due 20150909)
haas:spring2016:php:projects:dlt0

Corning Community College

CSCS2320 Data Structures

~~TOC~~

Project: Tree part of EOCE0

Errata

This section will document any updates applied to the project since original release:

  • revision 1: Makefile fixes and unit test typo fixes (20151201)
  • revision 2: another unit test typo fix– things should compile now (20151201)
  • revision 3: app/list/Makefile had a typo (20151205)
  • revision 4: traverse unit tests had a typo (20151208)
  • revision 5: traverse unit tests had another typo (20151216)

Objective

In this project, we continue our conceptual journey and explore yet another data structure: trees.

Background

A tree is our first foray into the realm of non-linear data structures. While it still consists of nodes, and those nodes are linked together, they are not linked together in a way providing a contiguous succession as we have in a list.

Truth be told, the simplest tree is merely a list- the underlying data structure we've worked with all semester. But now, under this new light, we can start to look at a list as merely a procession of singled childed nodes. The more things are different, the more they are the same…

The simplest conceptual tree is one which has a maximum of two connections- often these are called 'binary' trees. We will use that description interchangeably here with 'doubly linked trees'.

The premise behind a binary tree is that of a parent-child relationship. Each node can be a parent (of up to two child nodes), and each child can in turn be its own parent (of up to two child nodes). This creates a connection between relationships of nodes (ie a parent and its descendants), and ends up offering some interesting and useful algorithmic opportunities, along with implementation experience.

conceptualizing a tree

It is common to think of a tree as a vertical structure, upside-down from the item we commonly think of in nature. Here we will have the tree's “root” at the very top, and all the branches (nodes, and connections to nodes) growing down and out from the root.

the tree

The tree data structure presents certain advantages that encourages its use in solving problems, and we accomplish that by its compositional definition:

  • a tree has a root which forms the basis or starting point of the structure; all nodes are reachable (and related through means of descendance) from the root.
  • to put an item on the tree, we insert or add it. When we add a node to the tree, it gets positioned in the appropriately available child link off some parent node.
  • to get an item off of the tree, we grab it (my term- often times it is referred to as deleting a node from the tree). Just as with a list and its obtain action, disconnecting a node from the structure can involve a lot of work to maintain connections and overall integrity of the data structure.
  • an important action that will be taking place is the traversal of the tree- ie walking it in certain orders to achieve desired results (sorting/ordering of values, among other things).

As we will be placing nodes in the tree according to their stored values (lesser values go to the left, or prior; greater values go to the right, or after), our tree will naturally sort our data for us, allowing us to search through its contents quite advantageously. As such, the tree we will be implementing is also known as a binary search tree.

tree height can matter

For some operations (specifically, visualization), the height of the tree can be very important, and constraining the tree height can impose a nice upper bound on the total number of nodes put into the tree.

Just as with the stack's size and the queue's buffer, our tree will have the ability to set a max_height, which our adding logic needs to respect.

Project Overview

For this project, we're going to be implementing the tree data structure utilizing nodes. Isn't it neat how we've been able to use this same basic structure in so many different ways and configurations? That speaks to what we're exploring in Data Structures- ideas. It isn't as much about WHAT we're manipulating (nodes), but HOW.

In inc/data.h

Here we see some additional status code defines:

105
//////////////////////////////////////////////////////////////////////
//
// Status codes for the doubly linked tree implementation
//
#define  DLT_SUCCESS         0x0000010000000000
#define  DLT_CREATE_FAIL     0x0000020000000000
#define  DLT_NULL            0x0000040000000000
#define  DLT_EMPTY           0x0000080000000000
#define  DLT_MAX             0x0000100000000000
#define  DLT_ERROR           0x0000200000000000
#define  DLT_INVALID         0x0000400000000000
#define  DLT_DEFAULT_FAIL    0x0000800000000000

I also created the typedefs sc and uc to simplify the declaration of signed chars and unsigned chars (respectively). These can me seen in the typedef stanza.

In inc/tree.h

1
#ifndef _TREE_H
#define _TREE_H
 
#include "data.h"
#include "list.h"
 
#define  INORDER       0
#define  PREORDER      1
#define  POSTORDER     2
 
struct tree {
    Node *root;                         // pointer to root node of tree
    uc    max_height;                   // max height of tree (0 = unlimited)
};
 
code_t mktree    (Tree **, uc        ); // create new tree
code_t cptree_r  (Tree  *, Tree **   ); // copy given tree (recursive)
code_t rmtree    (Tree **            ); // purge and deallocate tree
 
code_t addnode   (Tree **, Node *    ); // add given node to tree
code_t grabnode_r(Tree **, Node **   ); // get node from tree (recursive)
code_t traverse_i(Tree  *, List **,uc); // traverse tree by mode (iterative)
code_t traverse_r(Tree  *, List **,uc); // traverse tree by mode (recursive)
code_t traverse_s(Tree  *, List **,uc); // traverse tree by mode (stacks)
 
code_t searchtree(Tree  *, Node **,sc); // find node in tree (by value)
 
#endif

tree library

In src/tree/, you will find skeletons of the above prototyped functions, hollowed out in anticipation of being made operational.

Figure out what is going on, the connections, and make sure you understand it.

Suggested Implementation Order

To make your life easier, I recommend implementing tree library functions in the following order:

  1. addnode()
  2. traverse_s()

Tree library unit tests

In unit/tree/, you will eventually find these files:

  • unit-addnode.c - unit test for the various addnode() library function
  • unit-traverse.c - unit test for traverse_s() library function

NOTE: At the time of project release, not all unit tests are available/fully functional; so expect some updates.

There are also corresponding verify-FUNCTION.sh scripts that will output a “MATCH”/“MISMATCH” to confirm overall conformance with the pertinent tree functionality.

These are complete runnable programs (when compiled, and linked against the tree library, which is all handled for you by the Makefile system in place).

Of particular importance, I want you to take a close look at:

  • the source code to each of these unit tests
    • the purpose of these programs is to validate the correct functionality of the respective library functions
    • follow the logic
    • make sure you understand what is going on
    • ask questions to get clarification!
  • the output from these programs once compiled and ran
    • analyze the output
    • make sure you understand what is going on
    • ask questions to get clarification!

Expected Results

To assist you in verifying a correct implementation, a fully working implementation of the node and tree libraries should resemble the following (when running the respective verify script):

tree library

Here is what you should get for tree:

lab46:~/src/data/dlt0$ bin/verify-tree.sh 
coming soon
lab46:~/src/data/dlt0$ 

Submission

Project Submission

When you are done with the project and are ready to submit it, you simply run make submit:

lab46:~/src/data/PROJECT$ make submit
...

Submission Criteria

To be successful in this project, the following criteria must be met:

  • Project must be submit on time, by the posted deadline.
    • Early submissions will earn 1 bonus point per full day in advance of the deadline.
      • Bonus eligibility requires an honest attempt at performing the project (no blank efforts accepted)
    • Late submissions will lose 25% credit per day, with the submission window closing on the 4th day following the deadline.
      • To clarify: if a project is due on Wednesday (before its end), it would then be 25% off on Thursday, 50% off on Friday, 75% off on Saturday, and worth 0% once it becomes Sunday.
      • Certain projects may not have a late grace period, and the due date is the absolute end of things.
  • All code must compile cleanly (no warnings or errors)
    • all requested functions must be implemented in the related library
    • all requested functionality must conform to stated requirements (either on this project page or in comment banner in source code files themselves).
  • Output generated must conform to any provided requirements and specifications (be it in writing or sample output)
    • output obviously must also be correct based on input.
  • Processing must be correct based on input given and output requested
  • Code must be nicely and consistently indented (you may use the indent tool)
    • You are free to use your own coding style, but you must be consistent
    • Avoid unnecessary blank lines (some are good for readability, but do not go overboard- double-spacing your code will get points deducted).
    • Indentation will be rated on the following scale (worth 3 total points):
      • 3/3: Aesthetically pleasing, pristine indentation, easy to read, organized
      • 2/3: Mostly consistent indentation, but some distractions (superfluous or lacking blank lines, or some sort of “busy” ness to the code)
      • 1/3: Some indentation issues, difficult to read
      • 0/3: Lack of consistent indentation (didn't appear to try)
  • Unless fundamentally required, none of your code should perform any inventory or manual counting. Basing your algorithms off such fixed numbers complicates things, and is demonstrative of a more controlling nature.
  • Code must be commented
    • Any “to be implemented” comments MUST be removed
      • these “to be implemented” comments, if still present at evaluation time, will result in points being deducted.
    • Commenting will be rated on the following scale (worth 3 total points):
      • 3/3: Aesthetically pleasing (comments aligned or generally not distracting), easy to read, organized
      • 2/3: Mostly consistent, some distractions or gaps in comments (not explaining important things)
      • 1/3: Light commenting effort, not much time or energy appears to have been put in.
      • 0/3: No original comments
    • Sufficient comments explaining the point of provided logic MUST be present
  • Code must be appropriately modified
    • Appropriate modifications will be rated on the following scale (worth 3 total points):
      • 3/3: Complete attention to detail, original-looking implementation
      • 2/3: Lacking some details (like variable initializations), but otherwise complete (still conforms, or conforms mostly to specifications)
      • 1/3: Incomplete implementation (typically lacking some obvious details/does not conform to specifications)
      • 0/3: Incomplete implementation to the point of non-functionality (or was not started at all)
    • Error checking must be adequately and appropriately performed, according to the following scale (worth 3 total points):
      • 3/3: Full and proper error checking performed for all reasonable cases, including queries for external resources and data.
      • 2/3: Enough error checking performed to pass basic project requirements and work for most operational cases.
      • 1/3: Minimal error checking, code is fragile (code may not work in full accordance with project requirements)
      • 0/3: No error checking (code likely does not work in accordance with project requirements)
  • Any and all non-void functions written must have, at most, 1 return statement
    • points will be lost for solutions containing multiple return statements in a function.
  • Absolutely, positively NO (as in ZERO) use of goto statements.
    • points will most definitely be lest for solutions employing such things.
  • Track/version the source code in a repository
  • Filling out any submit-time questionnaires
  • Submit a copy of your source code to me using the submit tool (make submit will do this) by the deadline.
haas/spring2016/php/projects/dlt0.txt · Last modified: 2015/12/16 15:22 by 127.0.0.1