In: Computer Science
What are the advantages and disadvantages of user-defined ordinal types as data types? What are the advantages and disadvantages to an associative array?
ANSWER:
An ordinal type is one in which the range of possible values can be easily associated with the set of positive integers
Examples of primitive ordinal types in Java
integer
char
boolean
Two common user-defined ordinal types
Enumeration: All possible values, which are named constants, are
provided or enumerated in the definition, e.g., C# example
enum days {mon, tue, wed, thu, fri, sat, sun};
Subrange: An ordered contiguous subsequence of an ordinal type,
e.g., 12..18 is a subrange of integer type
Advantage of enumeration are readability and reliability.
Code is more readable.
Code is more reliable, since compiler can check operations for
enumerations and it does not let them to be assigned to any thing
out of their set of constants.
Disadvantage of enumeration is :
Design Issue:
Is an enumeration constant allowed to appear in more
than one type definition, and if so, how is the type of an
occurrence of that constant checked?
Are enumeration values coerced to integer?
Any other type coerced to an enumeration type?
Advantage of subrange ordinal data type:
Aid to readability
Make it clear to the readers that variables of subrange can store
only certain range of values
Reliability
Assigning a value to a subrange variable that is outside the
specified range is detected as an error
Disadvantage of subrange:
What are the design issues for arrays?
What types are legal for subscripts?
Are subscripting expressions in elemnet refrence range
checked?
When are subscript ranges bound?
When does allocation take place?
What is the maximum number of subscripts?
Can array objects be initialized?
Are any kind of slices supported?
Advantage/Disadvantage of Associative array and Use cases:
Tha advantage and disadvantage of an associative array
are normally determined by the implementation you use for the
key/value association.
Some implementations, such as asoociation lists, are very easy to
implement but very inefficient for large
lists. Others, such as red-black trees and hash tables, are harder
to implement but
a lot more efficient for larger lists, and not so efficient for
smaller lists. If you
are willing to do the research and invest the coding time,
associative arrays can
be a very efficient tool.
The abstract data type (ADT) is essentially an API, and a concrete data structure provides an implementation of that API. For a given ADT, there are often several different choices of concrete data structures which support the query and update operations described by the ADT. Every concrete data structure for a given ADT must support all the operations described by the ADT (possibly with some probability of success in the case of randomized structures), but each concrete structure may make different guarantees of the running times of each operation. The choice of which concrete data structure to implement for a given ADT usually depends on the priorities of efficiency of each operation (including initializing the structure) and the complexity of implementing and maintaining the various data types. Some concrete data structures have excellent theoretical guarantees, but the overhead is such that a slightly less theoretically optimal data structure may be a better choice in practice.
There are far too many ADT and corresponding concrete structures to list in a single answer, but here are a few examples:
A dictionary supports Find(x) queries. For an a key xx, return the element in the dictionary with key xx, if such an element exists. A dynamic dictionary also supports Insert(x) and Delete(x). Common implementations of a dictionary include different kinds of balanced binary search trees (e.g. red black tree) and various kinds of hash tables.
In addition to Find an ADT may require support of successor(x) queries. That is, maintain a set of keys SS, and given key xx, find the smallest key t∈St∈S such that s<ts<t. Concrete data structures which support the Successor ADT include various binary search trees, and more complicated structures such as an X-fast trie or van Emde Boas tree (if the keys are integers).
A Priority Queue is an ADT that requires insert and delete-min operations (and sometimes other operations as well, such as find-min increase-key or delete-key). Data structures that implement the priority queue ADT include:
an unsorted linked list, which has fast insert but slow delete-min.
a sorted linked list which has fast delete-min but slow insert
a binary search tree, which has logarithmic insert and delete-min, and sort(n)sort(n) initialization time.
a binary heap which has logarithmic insert and delete-min, and linear time initialization.
There are also other variants of heap implementations.
An interval stabbing ADT maintains a set of intervals on the real line, and supports a stabbing(x) query, which returns the subset of intervals which contain (are stabbed by) the point xx. Data structures that implement the stabbing query ADT include a Segment Tree and an Interval Tree.
hope this is helpful to u.....thank u......