Thought problems
Specify which data structures and what algorithm you might use to
solve each of the following:
- Count the lines in a file.
- Count the number of unique (non-equal) lines in a file.
- Count the number of occurrences of each different word in a file.
- Print out all the lines in a file in alphabetical order.
- Print out all the unique lines in a file in alphabetical order.
- Each line in a file begins with a 6 digit ID number. Process
(print) each line in the file but skip any line after you have
seen that ID number. Also, skip all blank lines.
- Ditto, but process the last line for any lines that have the
same ID number.
- Given this regular expression pattern "#\((.*?)\)" and data
file data02.txt, solve each of the following:
- Process each line in a file that contains a pattern.
- Ditto, but process each of the lines in alphabetical order.
- Ditto, but process each of the lines in alphabetical order by the
pattern found.
- Digraphs and trees:
- Represent a tree structure as a digraph (a directed graph with
nodes and edges) or network. Each node has a name and some
children. Starting at the root node, walk the tree and print
out the name/data of each node.
- Add the ability of each node in your tree to have any number of
attributes.
- Imagine that the edges of the digraph are labeled. Represent
that tree. Walk the tree and print the name/value at each node
and (2) the path from the root to the node.
- Read from stdin and write to stdout. Transform the input before
writing, for example, (a) convert to upper case or (b) add "#" at
the beginning of each line.