CSE101 Introduction to Data Structures and Algorithms

2024-01-10 10:58:04
CSE 101
Introduction to Data Structures and Algorithms
Programming Assignment 7
In this project we will create a program that is very similar in operation to pa1, this time in C++. The main? program will be called Order.c, and will use a Dictionary ADT based on a Binary Search Tree.
The Dictionary ADT
The Dictionary ADT maintains a set of pairs whose members are called key and value , respectively. A state?of this ADT is a set (possibly empty) of such pairs. The file Dictionary.h is posted in /Examples/pa7 and contains the following typedefs for key and value.
typedef std::string keyType;
typedef int valType;
Think of the key as being some kind of identifying information, such as an account number, and the value as being data associated with that account. The Dictionary ADT will enforce the constraint that all keys are unique, while values may occur multiple times.
The main Dictionary operations are getValue(𝑘): Return a reference to the value corresponding to key k . Pre: such a pair exists.
setValue(𝑘, 𝑣) : If a pair with key k exists, overwrite its value with v , otherwise insert the pair (𝑘, 𝑣) . remove(𝑘): Delete the pair with key k . Pre: such a pair exists.
The Dictionary will also support a built-in iterator called current , that allows the client to step through the keys in alphabetical order, somewhat like cursor in the various incarnations of our List ADT. Other operations, including some suggested helper functions, along with their descriptions, are included in
Dictionary.h.
Binary Search Trees
Before you begin this project, you should read Chapter 12 of our text (CLRS pp. 286-307.) Basically, a
BST is a generalization of a (doubly) linked list, in which each Node has two next pointers, called left child and right child , respectively. The prev pointer in a linked list is replaced by parent .
In this project, the "other data" will consist of one (key, value) pair in our Dictionary. For purposes of this
simplified discussion though, "other data" will be a single integer which we
call key.
A binary tree assembled out of these Node objects looks something like this:
Two more conditions, called the Binary Search Tree properties, are necessary for such a structure to be a
BST. Let 𝑥 and 𝑦 be Nodes in a BST. Then
(1) if 𝑦 is in the left subtree of 𝑥 (i.e. 𝑦 is a descendant of 𝑥's left child), then key[𝑦] ≤ key[𝑥] ,
(2) if 𝑦 is in the right subtree of 𝑥 (i.e. 𝑦 is a descendant of 𝑥's right child), then key[𝑥] ≤ key[𝑦] .
Observe that the preceding example satisfies these properties, which make a number of sorting, searching and query algorithms possible. Other algorithms perform insertions and deletions in such a way as to maintain the BST properties. All of these algorithms will be discussed at length during lecture, and will be implemented by you in this project, some as ADT operations and some as helper functions.

文章来源:https://blog.csdn.net/2301_81917451/article/details/135495321
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。