Anda di halaman 1dari 11

1.

The process of solving a problem by reducing it to smaller versions of itself is


called recursion.
2. A recursive definition defines a problem in terms of smaller versions of itself.
3. Every recursive definition has one or more base cases.
4. A recursive algorithm solves a problem by reducing it to smaller versions of
itself.
5. Every recursive algorithm has one or more base cases.
6. The solution to the problem in a base case is obtained directly.
7. A function is called recursive if it calls itself.
8. Recursive algorithms are implemented using recursive functions.
9. Every recursive function must have one or more base cases.
10. The general solution breaks the problem into smaller versions of itself.
11. The general case must eventually be reduced to a base case.
12. The base case stops the recursion.
13. While tracing a recursive function:
Logically, you can think of a recursive function as having an unlimited number
of copies of itself.
Every call to a recursive functionthat is, every recursive callhas its own
code and its own set of parameters and local variables.
After completing a particular recursive call, control goes back to the calling
environment, which is the previous call. The current (recursive) call must execute
completely before control goes back to the previous call. The execution in the
previous call begins from the point immediately following the recursive call.
14. A function is called directly recursive if it calls itself.
15. A function that calls another function and eventually results in the original
function call is said to be indirectly recursive.
16. A recursive function in which the last statement executed is the recursive call
is called a tail recursive function.
17. To design a recursive function, you must do the following:
a. Understand the problem requirements.
b. Determine the limiting conditions. For example, for a list, the limiting condition
is the number of elements in the list.

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.

Stack and Queues


1. A stack is a data structure in which the items are added and deleted
from one end only.
2. A stack is a Last In First Out (LIFO) data structure.
3. The basic operations on a stack are as follows: push an item onto the
stack, pop an item from the stack, retrieve the top element of the stack,
initialize the stack, check whether the stack is empty, and check whether
the stack is full.
4. A stack can be implemented as an array or a linked list.
5. The middle elements of a stack should not be accessed directly.
6. Stacks are restricted versions of arrays and linked lists.
7. Postfix notation does not require the use of parentheses to enforce
operator precedence.
8. In postfix notation, the operators are written after the operands.
9. Postfix expressions are evaluated according to the following rules:
a. Scan the expression from left to right.
b. If an operator is found, back up to get the required number of operands,
evaluate the operator, and continue.
10. A queue is a data structure in which the items are added at one end
and removed from the other end.
11. A queue is a First In First Out (FIFO) data structure.
12. The basic operations on a queue are as follows: add an item to the
queue, remove an item from the queue, retrieve the first or last element
of the queue, initialize the queue, check whether the queue is empty, and
check whether the queue is full.
13. A queue can be implemented as an array or a linked list.
14. The middle elements of a queue should not be accessed directly.
15. Queues are restricted versions of arrays and linked lists.

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.

b. Traverse the left subtree.


c. Traverse the right subtree.
12. In a postorder traversal, the binary tree is traversed as follows:
a. Traverse the left subtree.
b. Traverse the right subtree.
c. Visit the node.
13. A binary search tree T is either empty or:
i. T has a special node called the root node;
ii. T has two sets of nodes, LT and RT, called the left subtree and the right
subtree of T, respectively;
iii. The key in the root node is larger than every key in the left subtree and
smaller than every key in the right subtree; and
iv. LT and RT are binary search trees.
14. To delete a node from a binary search tree that has both left and right
nonempty subtrees, first its immediate predecessor is located, then the
predecessors info is copied into the node, and finally the predecessor is
deleted.

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.

In addition to the member functions listed in item 13 above, the other


member functions common to all sequence containers are insert,
push_back, pop_back, erase, clear, and resize.
The copy algorithm is used to copy the elements in a given range to
another place.
The function copy, using an ostream iterator, can also be used to
output the elements of a container.
When we create an iterator of type ostream, we also specify the type of
element that the iterator will output.
Deque containers are implemented as dynamic arrays in such a way that
the elements can be inserted at both ends of the array.
21. A deque can expand in either direction.
22. The name of the class containing the definition of the class deque is
deque.
23. In addition to the operations that are common to all containers, other
operations that can be used to manipulate the elements of a deque are
assign, push_front, pop_front, at, the array subscripting operator [], front,
and back.
24. List containers are implemented as doubly linked lists. Thus, every
element in the list points to its immediate predecessor and its immediate
successor (except the first and last elements).
25. The name of the class containing the definition of the class list is list.
26. In addition to the operations that are common to sequence containers,
other operations that can be used to manipulate the elements in a list
container are assign, push_front, pop_front, front, back, remove,
remove_if, unique, splice, sort, merge, and reverse.
27. The five categories of iterators are input, output, forward,
bidirectional, and random access iterator.
28. Input iterators are used to input data from an input stream.
29. Output iterators are used to output data to an output stream.
30. A forward iterator can refer to the same element in the same
collection and process the same element more than once.
31. Bidirectional iterators are forward iterators that can also iterate
backward over the elements.

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.

82. The algorithm max_element is used to determine the largest element


in a given range.
83. The algorithm min is used to determine the minimum of two values.
84. The algorithm min_element is used to determine the smallest element
in a given range.
85. The algorithm random_shuffle is used to randomly order the elements
in a given range.
86. The algorithm for_each is used to access and process each element in
a given range by applying a function, which is passed as a parameter.
87. The function transform creates a sequence of elements by applying
certain operations to each element in a given range.
88. The algorithm includes determines whether the elements of one range
appear in another range.
89. The algorithm set_intersection is used to find the elements that are
common to two ranges of elements.
90. The algorithm set_union is used to find the elements that are
contained in two ranges of elements.
91. The algorithm set_difference is used to find the elements in one range
of elements that do not appear in another range of elements.
92. Given two ranges of elements, the algorithm set_symmetric_difference
determines the elements that are in the first range but not the second
range or the elements that are in the second range but not the first range.
93. The algorithms accumulate, adjacent_difference, inner_product, and
partial_sum are numerical functions and manipulate numeric data.

Anda mungkin juga menyukai