Unit - I Divide and Conquer: Recursively

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 10

UNIT – I

Divide and conquer

Solve a problem, either directly because solving that instance is easy (typically, because
the instance is small) or by dividing it into two or more smaller instances. Each of these
smaller instances is recursively solved, and the solutions are combined to produce a
solution for the original instance.

Breadth-first search

A search algorithm that considers neighbors of a vertex, that is, outgoing edges of the
vertex's predecessor in the search, before any outgoing edges of the vertex. Extremes are
searched last. This is typically implemented with a queue.

Depth-first search

(1) Any search algorithm that considers outgoing edges of a vertex before any neighbors
of the vertex, that is, outgoing edges of the vertex's predecessor in the search. Extremes
are searched first. This is easily implemented with recursion. (2) An algorithm that marks
all vertices in a directed graph in the order they are discovered and finished, partitioning
the graph into a forest.

Best-first search

A state-space search algorithm that considers the estimated best partial solution next.
This is typically implemented with a priority queue.
UNIT – II
Abstract data type

A set of data values and associated operations that are precisely specified independent of
any particular implementation.

Stack

A collection of items in which only the most recently added item may be removed. The
latest added item is at the top. Basic operations are push and pop. Often top and isEmpty
are available, too. Also known as "last-in, first-out" or LIFO.

Queue

A collection of items in which only the earliest added item may be accessed. Basic
operations are add (to the tail) or enqueue and delete (from the head) or dequeue. Delete
returns the item removed. Also known as "first-in, first-out" or FIFO.

Deque

A data structure in which items may be added to or deleted from the head or the tail.

Data structure

An organization of information, usually in memory, for better algorithm efficiency, such


as queue, stack, linked list, heap, dictionary, and tree, or conceptual unity, such as the
name and address of a person. It may include redundant information, such as length of
the list or number of nodes in a subtree.

Linked list

A list implemented by each item having a link to the next item.

List

A collection of items accessible one after another beginning at the head and ending at the
tail.
Head

The first item of a list.

Tail

The last item of a list. (2) All but the first item of a list; the list following the head.

Doubly linked list

A variant of a linked list in which each item has a link to the previous item as well as the
next. This allows easily accessing list items backward as well as forward and deleting any
item in constant time.

Circular list

A variant of a linked list in which the nominal tail is linked to the head. The entire list
may be accessed starting at any item and following links until one comes to the starting
item again.
UNIT – III
AVL tree

balanced binary search tree where the height of the two subtrees (children) of a node
differs by at most one. Look-up, insertion, and deletion are O(log n), where n is the
number of nodes in the tree.

Height

The maximum distance of any leaf from the root of a tree. If a tree has only one node (the
root), the height is zero.

Leaf

A node in a tree without any children. See the figure at tree.

Node

(1) A unit of reference in a data structure. Also called a vertex in graphs and trees. (2) A
collection of information which must be kept at a single memory location.

Tree

1) A data structure accessed beginning at the root node. Each node is either a leaf or an
internal node. An internal node has one or more child nodes and is called the parent of its
child nodes. All children of the same node are siblings. Contrary to a physical tree, the
root is usually depicted at the top of the structure, and the leaves are depicted at the
bottom. (2) A connected, undirected, acyclic graph. It is rooted and ordered unless
otherwise specified.

Root

The distinguished initial or fundamental item of a tree. The only item which has no
parent.

Parent

Of a node: the tree node conceptually above or closer to the root than the node and which
has a link to the node. See the figure at tree.

Child

A node of a tree referred to by a parent node. See the figure at tree. Every node, except
the root, is the child of some parent.

Ancestor
A parent of a node in a tree, the parent of the parent, etc.

Descendant

A child of a node in a tree, any of the children of the children, etc.

Sibling

A node in a tree that has the same parent as another node is its sibling.

Binary search tree

A binary tree where every node's left subtree has keys less than the node's key, and every
right subtree has keys greater than the node's key.

Subtree

The tree which is a child of a node.

Priority queue

An abstract data type to efficiently support finding the item with the highest priority
across a series of operations. The basic operations are: insert, find-minimum (or
maximum), and delete-minimum (or maximum). Some implementations also efficiently
support join two priority queues (meld), delete an arbitrary item, and increase the priority
of a item (decrease-key).

Dynamic hashing

A hash table that grows to handle more items. The associated hash function must change
as the table grows. Some schemes may shrink the table to save space when items are
deleted.

Hash table

A dictionary in which keys are mapped to array positions by hash functions. Having the
keys of more than one item map to the same position is called a collision. There are many
collision resolution schemes, but they may be divided into open addressing, chaining, and
keeping one special overflow area. Perfect hashing avoids collisions, but may be time-
consuming to create.

Hash function
A function that maps keys to integers, usually to get an even distribution on a smaller set
of values.

Open addressing

A class of collision resolution schemes in which all items are stored within the hash table.
In case of collision, other positions are computed, giving a probe sequence, and checked
until an empty position is found. Some ways of computing possible new positions are less
efficient because of clustering. Typically items never move once put in place, but in
Robin Hood hashing and other techniques, previously placed items may move.

Linear probing

A hash table in which a collision is resolved by putting the item in the next empty place
in the array following the occupied place. Even with a moderate load factor, primary
clustering tends to slow retrieval.

Heap

A complete tree where every node has a key more extreme (greater or less) than or equal
to the key of its parent. Usually understood to be a binary heap.

Binary heap

A complete binary tree where every node has a key more extreme (greater or less) than or
equal to the key of its parent.

Separate chaining

A scheme in which each position in the hash table has a list to handle collisions. Each
position may be just a link to the list (direct chaining) or may be an item and a link,
essentially, the head of a list. In the latter, one item is in the table, and other colliding
items are in the list.
UNIT – IV
Heapsort

A sort algorithm that builds a heap, then repeatedly extracts the maximum item. Run time
is O(n log n).

Selection sort

A sort algorithm that repeatedly looks through remaining items to find the least one and
moves it to its final location. The run time is Θ(n²), where n is the number of elements.
The number of swaps is O(n).

Insertion sort

Sort by repeatedly taking the next item and inserting it into the final data structure in its
proper order with respect to items already inserted. Run time is O(n2) because of moves.

Quicksort

Pick an element from the array (the pivot), partition the remaining elements into those
greater than and less than this pivot, and recursively sort the partitions. There are many
variants of the basic scheme above: to select the pivot, to partition the array, to stop the
recursion on small partitions, etc.
UNIT – V
Topological order

A numbering of the vertices of a directed acyclic graph such that every edge from a
vertex numbered i to a vertex numbered j satisfies i<j.

Topological sort

To arrange items when some pairs of items have no comparison, that is, according to a
partial order.

Path

A list of vertices of a graph where each vertex has an edge from it to the next vertex.

Vertex

An item in a graph. Sometimes referred to as a node.

Graph

A set of items connected by edges. Each item is called a vertex or node. Formally, a
graph is a set of vertices and a binary relation between vertices, adjacency.

Edge

A connection between two vertices of a graph. In a weighted graph, each edge has an
number, called a "weight." In a directed graph, an edge goes from one vertex, the source,
to another, the target, and hence makes connection in only one direction.

Directed graph

A graph whose edges are ordered pairs of vertices. That is, each edge can be followed
from one vertex to another vertex.

Weighted, directed graph

A directed graph that has a weight, or numeric value, associated with each edge.

Weighted graph

A graph having a weight, or number, associated with each edge. Some algorithms require
all weights to be nonnegative, integral, positive, etc.

NP
The complexity class of decision problems for which answers can be checked by an
algorithm whose run time is polynomial in the size of the input. Note that this doesn't
require or imply that an answer can be found quickly, only that any claimed solution can
be verified quickly. "NP" is the class that a Nondeterministic Turing machine accepts in
Polynomial time.

NP-complete

The complexity class of decision problems for which answers can be checked for
correctness, given a certificate, by an algorithm whose run time is polynomial in the size
of the input (that is, it is NP) and no other NP problem is more than a polynomial factor
harder. Informally, a problem is NP-complete if answers can be verified quickly, and a
quick algorithm to solve this problem can be used to solve all other NP problems quickly.

NP-hard

The complexity class of decision problems that are intrinsically harder than those that can
be solved by a nondeterministic Turing machine in polynomial time. When a decision
version of a combinatorial optimization problem is proved to belong to the class of NP-
complete problems, then the optimization version is NP-hard.

Complexity class

Any of a set of computational problems with the same bounds (Θ(n)) on time and space,
for deterministic and nondeterministic machines.

Decision problem

A problem with a "yes" or "no" answer. Equivalently, a function whose range is two
values, such as {0,1}.

Minimum spanning tree

A minimum-weight tree in a weighted graph which contains all of the graph's vertices.
Dijkstra's algorithm

An algorithm to find the shortest paths from a single source vertex to all other vertices in
a weighted, directed graph. All weights must be nonnegative.

Shortest path

The problem of finding the shortest path in a graph from one vertex to another. "Shortest"
may be least number of edges, least total weight, etc.

You might also like