0% found this document useful (0 votes)
9 views4 pages

Decap538 Algorithm Design and Analysis4

The document provides an introduction to various data structures including trees, binary trees, binary search trees, dictionaries, and graphs, along with their properties and algorithms for manipulation. It also discusses computational models and algorithms, emphasizing the importance of efficiency and space complexity in algorithm design. Key concepts such as the RAM model and the distinction between fixed and variable space requirements are highlighted.

Uploaded by

senior4helpu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Decap538 Algorithm Design and Analysis4

The document provides an introduction to various data structures including trees, binary trees, binary search trees, dictionaries, and graphs, along with their properties and algorithms for manipulation. It also discusses computational models and algorithms, emphasizing the importance of efficiency and space complexity in algorithm design. Key concepts such as the RAM model and the distinction between fixed and variable space requirements are highlighted.

Uploaded by

senior4helpu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Notes

Unit 01: Introduction

}
else
{
q[rear] := item;// Insert new item.
return true;
}
}

Algorithm Delete Q (item)


{
if (front= rear) then
{
write ("Queue is empty!”);
return false;
}
else
{
front:=(front+ 1) mod n; // Advance front clockwise.
item:=q[front]; //Set item to front of queue.
return true;
}}

1.3 Trees
A tree is a finite set of one or more nodes such that there is a specially designated node called the
root and the remaining nodes are partitioned into n > 0 disjoint sets T 1,…,Tn, where each of these
sets is a tree. The sets T1,...,Tn are called the subtrees of the root. The below figure represents the
tree which has 13 nodes. Here the root node contains A.The number of subtrees of a node is called
its degree. The degree of A is 3, of C is 1, and of F is 0.Nodes that have degree zero are called leaf or
terminal nodes. The set {K,L,F,G,M,I,J} is the set of leaf node.The other nodes are referred to as non-
terminals.Thus, the children of D are H, I, and J, and the parent of D is A. The children of the same
parent are said to be siblings. For example, H, I, and J are siblings.The degree of a tree is the
maximum degree of the nodes in the tree.The ancestors of a node are all the nodes along the path
from the root to that node.The ancestors of M are A, D, and H.The level of a node is defined by
initially letting the root be at level one.If a node is at level p, then its children are at level p + 1.The
height or depth of a tree is defined to be the maximum level of any node in the tree.A forest is a set
of n >0 disjoint trees. The notion of a forest is very close to that of a tree because if we remove the
root of a tree, we get a forest.

LOVELY PROFESSIONAL UNIVERSITY 5


Notes

Algorithm Analysis and Design

Binary Trees
A binary tree is a finite set of nodes that is either empty or consists of a root and two disjoint binary
trees called the left and right subtrees. In a binary tree any node can have at most two children; that
is, there is no node with degree greater than two.For binary trees we distinguish between the
subtree on the left and that on the right.Furthermore, a binary tree is allowed to have zero nodes
whereas any other tree must have at least one node. Thus, a binary tree is really a different kind of
object than any other tree.The binary trees can be of type left skewed and right skewed. One
example of left skewed is shown in below figure. If we follow the concept of sequential placing of
elements, then a block will be left empty in place of missing element.

First A is placed, then B is placed. As there is no right child of A, then this place will be left empty.
Then C is placed. Following the same manner, we will keep on placing the elements and leaving the
empty spaces for missing elements.

This example shows the complete binary tree. A complete binary tree is a binary tree in which all
the levels are filled except possibly the lowest one, which is filled from the left. A complete binary
tree is just like a full binary tree, but with two major differences. All the leaf elements must lean
towards the left. The same way is used to place the elements in arrays and lists.

6 LOVELY PROFESSIONAL UNIVERSITY


Notes

Unit 01: Introduction

Binary Search Tree


A binary search tree is a binary tree. It may be empty. If it is not empty, then it satisfies the
following properties:1. Every element has a key and no two elements have the same key (i.e., the
keys are distinct).2. The keys (if any) in the left subtree are smaller than the key in the root.3. The
keys (if any) in the right subtree are larger than the key in the root.4. The left and right subtrees are
also binary search trees.A binary search tree can support the operation search, insert, and delete
among others.

1.4 Dictionaries
A dictionary is a general-purpose data structure for storing a group of objects. A dictionary has a
set of keys, and each key has a single associated value. When presented with a key, the dictionary
will return the associated value.An abstract data type that supports the operations insert, delete,
and search is called a dictionary.Dictionaries have found application in the design of numerous
algorithms.Example:Consider the database of books maintained in a library system. When a user
wants to check whether a particular book is available, a search, operation is called for. If the book is
available and is issued to the user, a delete operation can be performed to remove this book from
the set of available books. When the user returns the book, it can be inserted back into the set.

1.5 Graphs
A graph G consists of two sets V and E. The set V is a finite, nonempty set of vertices. The set E is a
set of pairs of vertices; these pairs are called edges.The notations V(G) and E(G) represent the sets of
vertices and edges, respectively, of graph G. We also write G = (V, E) to represent a graph.In an
undirected graph the pair of vertices representing any edge is unordered.Thus, the pairs(u, v) and
(v, u) represent the same edge.In a directed graph each edge is represented by a directed pair (u, v);
u is the tail and v the head of the edge. Therefore,(v, u) and (u, v) represent two different edges.
Few examples of graphs are shown below.

LOVELY PROFESSIONAL UNIVERSITY 7


Notes

Algorithm Analysis and Design

Adjacency matrices of graphs: We can also form the adjacency matrices of graphs.

1.6 Computational Model


A computational model is a mathematical model in computational science that requires extensive
computational resources to study the behavior of a complex system by computer simulation. The
goal of computational modeling is to use precise mathematical models to make better sense of
data.The common basis of programming language and computer architecture is known as
computational model. It provides higher level of abstraction than the programming language and
the architecture. Computational model is the combination of the above two things.

1.7 Algorithms
It a step-by-step procedure for solving a computational problem.Algorithms are most important
and durable part of computer science because they can be studied in a language- and machine-
independent way. This means that we need techniques that capable us to compare the efficiency of
algorithms without implementing them. The two most important tools are: The RAM model of
computation and, The asymptotic analysis of worst-case complexity.

RAM Model
RAM stands for Random Access Machine. It is not R.A. Memory. An idealized notion of how the
computer works, each "simple" operation (+, -, =, if) takes exactly 1 step.Each memory access takes
exactly 1 step. Loops and method calls are not simple operations but depend upon the size of the
data and the contents of the method. It measures the run time of an algorithm by counting the
number of steps. The program for RAM is not stored in memory. Thus, we are assuming that the
program does not modify itself.A Random-Access Machine (RAM) consists of: a fixed program, an
unbounded memory, a read-only input tape, a write-only output tape, each memory register can
hold an arbitrary integer (*) and each tape cell can hold a single symbol from a finite alphabet s.

Space Complexity
The amount of memory required by an algorithm to run to completion.
• Fixed part: The size required to store certain data/variables, that is independent of the size
of the problem: Such as int a (2 bytes, float b (4 bytes) etc.
• Variable part: Space needed by variables, whose size is dependent on the size of the
problem: Dynamic array a[ ].
S(P) = c + S(instance characteristics)
c = constant. Constant Space: one for n, one for a [passed by reference!], one for s, one for I ,
constant space=c=4

8 LOVELY PROFESSIONAL UNIVERSITY

You might also like