c. Identify the base cases and provide a direct solution to each base case.
d. Identify the general cases and provide a solution to each general case in terms
of smaller versions of itself.
Linked list
1. A linked list is a list of items, called nodes, in which the order of the nodes is
determined by the address, called a link, stored in each node.
2. The pointer to a linked listthat is, the pointer to the first node in the listis
stored in a separate location called the head or first.
3. A linked list is a dynamic data structure.
4. The length of a linked list is the number of nodes in the list.
5. Item insertion and deletion from a linked list do not require data movement;
only the pointers are adjusted.
6. A (single) linked list is traversed in only one direction.
7. The search on a linked list is sequential.
8. The first (or head) pointer of a linked list is always fixed, pointing to the first
node in the list.
9. To traverse a linked list, the program must use a pointer different than the
head pointer of the list, initialized to the first node in the list.
10. In a doubly linked list, every node has two links: one points to the next node
and one points to the previous node.
11. A doubly linked list can be traversed in either direction.
12. In a doubly linked list, item insertion and deletion require the adjustment of
two pointers in a node.
13. A linked list in which the last node points to the first node is called a circular
linked list.
Sequences
BINARY TREE
1. A binary tree is either empty or it has a special node called the root
node. If the tree is nonempty, the root node has two sets of nodes, called
the left and right subtrees, such that the left and right subtrees are also
binary trees.
2. The node of a binary tree has two links in it.
3. A node in the binary tree is called a leaf if it has no left and right
children.
4. A node U is called the parent of a node V if there is a branch from U to V
5. A path from a node X to a node Y in a binary tree is a sequence of
nodes X0, X1, . . ., Xn such that (a) X X0, Xn Y, and (b) Xi_1 is the
parent of Xi for all i 1, 2, . . ., n. That is, there is a branch from X0 to X1,
X1 to X2, . . ., Xi_1 to Xi, . . ., Xn_1 to Xn.
6. The length of a path in a binary tree is the number of branches on that
path.
7. The level of a node in a binary tree is the number of branches on the
path from the root to the node.
8. The level of the root node of a binary tree is 0, and the level of the
children of the root node is 1.
9. The height of a binary tree is the number of nodes on the longest path
from the root to a leaf.
10. In an inorder traversal, the binary tree is traversed as follows:
a. Traverse the left subtree.
b. Visit the node.
c. Traverse the right subtree.
11. In a preorder traversal, the binary tree is traversed as follows:
a. Visit the node.
STL LIBRARY
The three main components of the STL are containers, iterators, and
algorithms.
STL containers are class templates. Iterators are used to step through the
elements of a container. Algorithms are used to manipulate the elements
in a container.
The main categories of containers are:
Sequence Containers
Associative Containers
Container Adapters.
The three predefined sequence containers are vector, deque, and list.
A vector container stores and manages its objects in a dynamic array.
Because an array is a random access data structure, elements of a vector
can be accessed randomly.
The name of the class that implements the vector container is vector.
Item insertion in a vector container is accomplished by using the
operations insert and push_back.
Item deletion in a vector container is accomplished by using the
operations pop_back, erase, and clear.
An iterator to a vector container is declared using the typedef iterator,
which is declared as a public member of the class vector.
Member functions common to all containers are the default constructor,
constructors with parameters, the copy constructor, the
destructor, empty, size, max_size, swap, begin, end, rbegin, rend,
insert, erase, clear, and the relational operator functions.
The member function begin returns an iterator to the first element into
the container. The member function end returns an iterator to one past
the last element into the container.
32. Bidirectional iterators can be used with containers of type list, set,
multiset, multimap, map, and multimap.
33. Random access iterators are bidirectional iterators that can randomly
process the elements of a container.
34. Random access iterators can be used with containers of type vector,
dequeue, and string, as well as arrays.
35. Elements in an associative container are automatically sorted
according to some various ordering criteria. The default ordering criterion
is the relational operator less-than, <.
36. The predefined associative containers in the STL are set, multiset,
map, and multimap.
37. Containers of the type set do not allow duplicates.
38. Containers of the type multiset allow duplicates.
39. The name of the class defining the container set is set.
40. The name of the class defining the container multiset is multiset.
41. The name of the header file containing the definition of the classes set
and multiset, and the definitions of the functions to implement the various
operations on these containers, is set.
42. The operations insert, erase, and clear can be used to insert or delete
elements from sets.
43. Most of the generic algorithms are contained in the header file
algorithm.
44. The main categories of STL algorithms are nonmodifying, modifying,
numeric, and heap.
45. Nonmodifying algorithms do not modify the elements of the container.
46. Modifying algorithms modify the elements of the container by
rearranging, removing, and/or changing the values of the elements.
47. Modifying algorithms that change the order of the elements, not their
values, are also called mutating algorithms.
48. Numeric algorithms are designed to perform numeric calculations on
the elements of a container.
49. A function object is a class template that overloads the function call
operator, operator().
50. The predefined arithmetic function objects are plus, minus, multiplies,
divides, modulus, and negate.
51. The predefined relational function objects are equal_to, not_equal_to,
greater, greater_equal, less, and less_equal.
52. The predefined logical function objects are logical_not, logical_and,
and logical_or.
53. Predicates are special types of function objects that return Boolean
values.
54. Unary predicates check a specific property for a single argument;
binary predicates check a specific property for a pairthat is, two
arguments.
55. Predicates are typically used to specify a searching or sorting criteria.
56. In the STL, a predicate must always return the same result for the
same value.
57. The functions that modify their internal states cannot be considered
predicates
58. The STL provides three iteratorsback_inserter, front_inserter, and
insertercalled insert iterators to insert the elements at the destination.
59. The back_inserter uses the push_back operation of the container in
place of the assignment operator.
60. The front_inserter uses the push_front operation of the container in
place of the assignment operator.
61. Because the vector class does not support the push_front operation,
this iterator cannot be used for the vector container.
62. The inserter iterator uses the containers insert operation in place of
the assignment operator.
63. The function fill is used to fill a container with elements, and the
function fill_n is used to fill in the next n elements.
64. The functions generate and generate_n are used to generate elements
and fill a sequence.
65. The functions find, find_if, find_end, and find_first_of are used to find
the elements in a given range.
66. The function remove is used to remove certain elements from a
sequence.
67. The function remove_if is used to remove elements from a sequence
using a specified criterion.
68. The function remove_copy copies the elements in a sequence into
another sequence by excluding certain elements from the first sequence.
69. The function remove_copy_if copies the elements in a sequence into
another sequence by excluding certain elements, using a specified
criterion, from the first sequence.
70. The functions swap, iter_swap, and swap_ranges are used to swap
elements.
71. The functions search, search_n, sort, and binary_search are used to
search elements.
72. The function adjacent_find is used to find the first occurrence of
consecutive elements satisfying a certain criterion.
73. The algorithm merge merges two sorted lists.
74. The algorithm inplace_merge is used to combine two sorted,
consecutive sequences.
75. The algorithm reverse reverses the order of the elements in a given
range.
76. The algorithm reverse_copy reverses the elements in a given range
while copying into a destination range. The source is not modified.
77. The algorithm rotate rotates the elements in a given range.
78. The algorithm rotate_copy copies the elements of the source at the
destination in a rotated order.
79. The algorithm count counts the occurrences of a given value in a
given range.
80. The algorithm count_if counts the occurrences of a given value in a
given range, satisfying a certain criterion.
81. The algorithm max is used to determine the maximum of two values.