Should be easy points here how do I do the bold function below. Should be farly
ID: 3547737 • Letter: S
Question
Should be easy points here how do I do the bold function below. Should be farly quick like the other functions. Can import anything in.
package data_structures;
import java.util.Iterator;
import java.util.TreeMap;
public class BalancedTree<K,V> implements DictionaryADT<K,V> {
TreeMap<K,V> treemap = new TreeMap<K,V>();
public boolean contains(K key) {
return treemap.containsKey(key);
}
public boolean insert(K key, V value) {
return treemap.put(key, value) != null;
}
public boolean remove(K key) {
return treemap.remove(key) != null;
}
public V getValue(K key) {
return treemap.get(key);
}
public K getKey(V value) {
}
public int size() {
return treemap.size();
}
public boolean isFull() {
return false;
}
public boolean isEmpty() {
return treemap.size()==0;
}
public void clear() {
treemap.clear();
}
@Override
public Iterator<K> keys() {
return (Iterator<K>) treemap.navigableKeySet();
}
@Override
public Iterator<V> values() {
return (Iterator<V>) treemap.values();
}
}
Explanation / Answer
Veusz is a scientific plotting package. It was designed to be easy to use, easily extensible, but powerful. The program features a graphical user interface, which works under Unix/Linux, Windows or Mac OS X. It can also be easily scripted (the saved file formats are similar to Python scripts) or used as module inside Python. Veusz reads data from a number of different types of data file, it can be manually entered, or constructed from other datasets.
In Veusz the document is built in an object-oriented fashion, where a document is built up by a number of widgets in a hierarchy. For example, multiple function or xy widgets can be placed inside a graph widget, and many graphs can be placed in a grid widget.
The technologies behind Veusz include PyQt (a very easy to use Python interface to Qt, which is used for rendering and the graphical user interface, GUI) and numpy (a package for Python which makes the handling of large datasets easy). Veusz can be extended by the user easily by adding plugins. Support for different data file types can be added with import plugins. Dataset plugins automate the manipulation of datasets. Tools plugins automate the manipulation of the document.
Here we define some terminology for future use.
A document and its graphs are built up from widgets. These widgets can often by placed within each other, depending on the type of the widget. A widget has children (those widgets placed within it) and its parent. The widgets have a number of different settings which modify their behaviour. These settings are divided into properties, which affect what is plotted and how it is plotted. These would include the dataset being plotted or whether an axis is logarithmic. There are also formatting settings, including the font to be used and the line thickness. In addition they have actions, which perform some sort of activity on the widget or its children, like "fit" for a fit widget.
As an aside, using the scripting interface, widgets are specified with a "path", like a file in Unix or Windows. These can be relative to the current widget (do not start with a slash), or absolute (do not start with a slash). Examples of paths include, "/page1/graph1/x", "x" and ".".
The widget types include
document - representing a complete document. A document can contain pages. In addition it contains a setting giving the page size for the document.
page - representing a page in a document. One or more graphs can be placed on a page, or a grid.
graph - defining an actual graph. A graph can be placed on a page or within a grid. Contained within the graph are its axes and plotters. A graph can be given a background fill and a border if required. It also has a margin, which specifies how far away from the edge of its parent widget to plot the body of the graph.
A graph can contain several axes, at any position on the plot. In addition a graph can use axes defined in parent widgets, shared with other graphs.
More than one graph can be placed within in a page. The margins can be adjusted so that they lie within or besides each other.
grid - containing one or more graphs. A grid plots graphs in a gridlike fashion. You can specify the number of rows and columns, and the plots are automatically replotted in the chosen arrangement. A grid can contain graphs or axes. If an axis is placed in a grid, it can be shared by the graphs in the grid.
axis - giving the scale for plotting data. An axis translates the coordinates of the data to the screen. An axis can be linear or logarithmic, it can have fixed endpoints, or can automatically get them from the plotted data. It also has settings for the axis labels and lines, tick labels, and major and minor tick marks.
An axis may be "horizontal" or "vertical" and can appear anywhere on its parent graph or grid.
If an axis appears within a grid, then it can be shared by all the graphs which are contained within the grid.
The axis-broken widget is an axis sub-type. It is an axis type where there are jumps in the scale of the axis.
The axis-function widget allows the user to create an axis where the values are scaled by a monotonic function, allowing non-linear and non-logarithmic axis scales. The widget can also be linked to a different axis via the function.
plotters - types of widgets which plot data or add other things on a graph. There is no actual plotter widget which can be added, but several types of plotters listed below. Plotters typically take an axis as a setting, which is the axis used to plot the data on the graph (default x and y).
function - a plotter which plots a function on the graph. Functions can be functions of x or y (parametric functions are not done yet!), and are defined in Python expression syntax, which is very close to most other languages. For example "3*x**2 + 2*x - 4". A number of functions are available (e.g. sin, cos, tan, exp, log...). Technically, Veusz imports the numpy package when evaluating, so numpy functions are available.
As well as the function setting, also settable is the line type to plot the function, and the number of steps to evaluate the function when plotting. Filling is supported above/below/left/right of the function.
xy - a plotter which plots scatter, line, or stepped plots. This versatile plotter takes an x and y dataset, and plots (optional) points, in a chosen marker and colour, connecting them with (optional) lines, and plotting (optional) error bars. An xy plotter can also plot a stepped line, allowing histograms to be plotted (note that it doesn't yet do the binning of the data).
The settings for the xy widget are the various attibutes for the points, line and error bars, the datasets to plot, and the axes to plot on.
The xy plotter can plot a label next to each dataset, which is either the same for each point or taken from a text dataset.
If you wish to leave gaps in a plot, the input value "nan" can be specified in the numeric dataset.
fit - fit a function to data. This plotter is a like the function plotter, but allows fitting of the function to data. This is achived by clicking on a "fit" button, or using the "fit" action of the widget. The fitter takes a function to fit containing the unknowns, e.g. "a*x**2 + b*x + c", and initial values for the variables (here a, b and c). It then fits the data (note that at the moment, the fit plotter fits all the data, not just the data that can be seen on the graph) by minimising the chi-squared.
In order to fit properly, the y data (or x, if fitting as a function of x) must have a properly defined, preferably symmetric error. If there is none, Veusz assumes the same fractional error everywhere, or symmetrises asymmetric errors.
Note that more work is required in this widget, as if a parameter is not well defined by the data, the matrix inversion in the fit will fail. In addition Veusz does not supply estimates for the errors or the final chi-squared in a machine readable way.
If the fitting parameters vary significantly from 1, then it is worth "normalizing" them by adding in a factor in the fit equation to bring them to of the order of 1.
bar - a bar chart which plots sets of data as horizontal or vertical bars. Multiple datasets are supported. In "grouped" mode the bars are placed side-by-side for each dataset. In "stacked" mode the bars are placed on top of each other (in the appropriate direction according to the sign of the dataset). Bars are placed on coordinates given, or in integer values from 1 upward if none are given. Error bars are plotted for each of the datasets.
Different fill styles can be given for each dataset given. A separate key value can be given for each dataset.
key - a box which describes the data plotted. If a key is added to a plot, the key looks for "key" settings of the other data plotted within a graph. If there any it builds up a box containing the symbol and line for the plotter, and the text in the "key" setting of the widget. This allows a key to be very easily added to a plot.
The key may be placed in any of the corners of the plot, in the centre, or manually placed. Depending on the ordering of the widgets, the key will be placed behind or on top of the widget. The key can be filled and surrounded by a box, or not filled or surrounded.
label - a text label places on a graph. The alignment can be adjusted and the font changed. The position of the label can be specified in fractional terms of the current graph, or using axis coordinates.
rect, ellipse - these draw a rectangle or ellipse, respectively, of size and rotation given. These widgets can be placed directly on the page or on a graph. The centre can be given in axis coordinates or fractional coordinates.
imagefile - draw an external graphs file on the graph or page, with size and rotation given. The centre can be given in axis coordinates or fractional coordinates.
line - draw a line with optional arrowheads on the graph or page. One end can be given in axis coordinates or fractional coordinates.
contour - plot contours of a 2D dataset on the graph. Contours are automatically calculated between the minimum and maximum values of the graph or chosen manually. The line style of the contours can be chosen individually and the region between contours can be filled with shading or color.
2D datasets currently consist of a regular grid of values between minimum and maximum positions in x and y. They can be constructed from three 1D datasets of x, y and z if they form a regular x, y grid.
image - plot a 2D dataset as a colored image. Different color schemes can be chosen. The scaling between the values and the image can be specified as linear, logarithmic, square-root or square.
polygon - plot x and y points from datasets as a polygon. The polygon can be placed directly on the page or within a graph. Coordinates are either plotted using the axis or as fractions of the width and height of the containing widget.
boxplot - plot distribution of points in a dataset.
polar - plot polar data or functions. This is a non-orthogonal plot and is placed directly on the page rather than in a graph.
ternary - plot data of three variables which add up to 100 per cent.This is a non-orthogonal plot and is placed directly on the page rather than in a graph.
The various settings of the widgets come in a number of types, including integers (e.g. 10), floats (e.g. 3.14), dataset names ("mydata"), expressions ("x+y"), text ("hi there!"), distances (see above), options ("horizontal" or "vertical" for axes).
Veusz performs type checks on these parameters. If they are in the wrong format the control to edit the setting will turn red. In the command line, a TypeError exception is thrown.
In the GUI, the current page is replotted if a setting is changed when enter is pressed or the user moves to another setting.
The settings are split up into formatting settings, controlling the appearance of the plot, or properties, controlling what is plotted and how it is plotted.
Default settings, including the default font and line style, and the default settings for any graph widget, can be modified in the "Default styles" dialog box under the "Edit" menu. Default settings are set on a per-document basis, but can be saved into a separate file and loaded. A default default settings file can be given to use for new documents (set in the preferences dialog).
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.