SlideShare a Scribd company logo
1 of 80
Download to read offline
Important Problem Types
Important Problem Types
ī‚§ Sorting
ī‚§ Searching
ī‚§ String Processing
ī‚§ Graph Problems
ī‚§ Combinatorial Problems
Sorting
ī‚§ The sorting problem is to rearrange the items of a given
list of non-decreasing order.
Sorting
ī‚§ List of Numbers
ī‚§ Characters from an alphabet
ī‚§ Character Strings
ī‚§ Records maintained by schools about their students
ī‚§ Libraries about their holdings
ī‚§ Companies about their employees
Sorting
ī‚§ In the case of records, we need to choose a piece of
information to guide sorting
ī‚§ Ex1: To sort student records in alphabetical order of
names or by student number or by student grade-point
average
ī‚§ Such a specially chosen piece of information is called a
Key
Why would we want a sorted list?
ī‚§ Sorted list can be required output of a task such as
Ranking Internet search results or Ranking students by
their GPA Scores
ī‚§ Sorting makes many questions about the list easier to
answer
ī‚§ The most important of them is Searching
ī‚§ Ex: Dictionaries, Telephone Books, Class list and so on
Why would we want a sorted list?
ī‚§ Sorting is used as an auxiliary step in several important
algorithms in other areas
ī‚§ Ex: Geometric algorithms and Data compression
ī‚§ Ex: Greedy approach – an important algorithm design
technique requires a sorted input
Performance
ī‚§ Some algorithms are indeed better than others
ī‚§ No algorithm that would be the best solution in all
situations
ī‚§ Some of the algorithms are simple but relatively slow
ī‚§ While others are faster but more complex
ī‚§ Some work better on randomly ordered inputs, while
others do better on almost-sorted lists
Performance
ī‚§ Some are suitable only for lists residing in the fast
memory, while others can be adopted for sorting large
files stored on a disk
Properties
ī‚§ First Property: A sorting algorithm is called Stable if it
preserves the relative order of any two equal elements in
its input
ī‚§ If an input list contains two equal elements in positions i
and j where i < j, then in the sorted list they have to be
in positions i’ and j’, respectively, such that i’< j’
Properties
ī‚§ Ex: List of students sorted alphabetically and we want to
sort it according to student GPA.
ī‚§ A stable algorithm will yield a list in which students with
the same GPA will still be sorted alphabetically
Properties
ī‚§ Second Property: Amount of extra memory the algorithm
requires
ī‚§ An algorithm is said to be in-place if it does not require
extra memory.
ī‚§ There are important sorting algorithms that are in-place
and those that are not.
Searching
ī‚§ The searching problem deals with finding a given value,
called a Search Key, in a given set (or a multiset, which
permits several elements to have the same value)
ī‚§ Ex: Sequential Search and Binary Search
ī‚§ Latter algorithms are of particular importance for real-
world applications because they are indispensable for
storing and retrieving information from large databases
Performance
ī‚§ No single algorithm that fits all situations best
ī‚§ Some algorithms work faster than others but require
more memory
ī‚§ Some are very fast but applicable only to sorted arrays
Issue
ī‚§ Specifically, in applications where the underlying data
may change frequently relative to the number of
searches, searching has to be considered in conjunction
with two other operations: an addition to and deletion
from the data set of an item
ī‚§ In such situations, data structures and algorithms should
be chosen to strike a balance among the requirements of
each operation
Issue
ī‚§ Organizing very large data sets for efficient searching
poses special challenges with important implications for
real-world applications
String Processing
ī‚§ A string is a sequence of characters from an alphabet
ī‚§ Text strings which comprise letters, numbers and special
characters
ī‚§ Bit Strings which comprise zeros and ones
ī‚§ Gene Sequences which can be modeled by strings of
characters from the four-character alphabet {A, C, G, T}
String Processing
ī‚§ String processing algorithms have been important for
computer science for a long time in conjunction with
computer languages and compiling issues
ī‚§ String Matching Algorithms
Graph Problems
ī‚§ One of the oldest and most interesting areas in
algorithmics is graph algorithms
ī‚§ A graph can be though as a collection of points called
Vertices, some of which are connected by line segments
called Edges
ī‚§ Graphs can be used for modeling a wide variety of
applications, including Transportation, Communication,
Social and Economic Networks, Project Scheduling, and
Games
Graph Problems
ī‚§ Basic graph algorithms
ī‚§ Graph-Traversal Algorithms (how can one reach all
the points in a network?)
ī‚§ Shortest-path Algorithms (what is the best route
between two cities?)
ī‚§ Topological Sorting for graphs with directed edges (is
a set of courses with their prerequisites consistent or
self-contradictory?)
Graph Problems
ī‚§ The Traveling salesman problem (TSP) is the problem of
finding the shortest tour through n cities that visits every
city exactly once
ī‚§ Ex: Route planning, circuit board and VLSI chip
fabrication, X-ray crystallography, and Genetic
engineering
Graph Problems
ī‚§ The graph-coloring problem seeks to assign the smallest
number of colors to the vertices of a graph so that no
two adjacent vertices are the same color.
ī‚§ Ex: Event Scheduling
ī‚§ If the events are represented by vertices that are
connected by an edge if and only if the corresponding
events cannot be scheduled at the same time
ī‚§ A solution to the graph-coloring problem yields an
optimal schedule
Combinatorial Problems
ī‚§ Ex: Traveling salesman problem and Graph coloring
problem
ī‚§ These are problems that ask, explicitly or implicitly, to
find a combinatorial object such as a permutation, a
combination, or a subset that satisfies certain constraints
ī‚§ A desired combinatorial object may also be required to
have some additional property such as a maximum value
or a minimum cost
Combinatorial Problems
ī‚§ Combinatorial problems are the most difficult problems
in computing from both a theoretical and practical
standpoint
ī‚§ First, the number of combinatorial objects typically
grows extremely fast with a problem’s size, reaching
unimaginable magnitudes even for moderate-sized
instances
ī‚§ Second, there are no known algorithms for solving most
such problems exactly in an acceptable amount of time
Fundamental Data Structures
Stack
ī‚§ Last-In-First-Out (LIFO)
ī‚§ A stack is a list in which insertions and deletions can be
done only at the end.
ī‚§ This end is called the top
ī‚§ They are indispensable for implementing recursive
algorithms
Queue
ī‚§ First-In-First-Out (FIFO)
ī‚§ A queue is a list from which elements are deleted from
one end of the structure, called the front (dequeue), and
new elements are added to the other end, called the
rear (enqueue)
ī‚§ Important applications include several algorithms for
graph problems
Queue
ī‚§ Many important applications require selection of an item
of the highest priority among a dynamically changing set
of candidates
ī‚§ A data structure that seeks to satisfy the needs of such
applications is called a Priority Queue
ī‚§ A Priority Queue is a collection of data items from a
totally ordered universe
Queue
ī‚§ The principal operations on a priority queue are finding
its largest element, deleting its largest element and
adding a new element.
ī‚§ Implementation of a priority queue is based on data
structure called the Heap
Graph
ī‚§ A Graph G = <V, E> is defined by a pair of two sets:
ī‚§ A finite nonempty set V of items called Vertices
ī‚§ A set E of pairs of these items called Edges
ī‚§ If these pair of vertices are unordered, i.e. a pair of
vertices (u, v) is the same as the pair (v, u), we say that
the vertices u and v are adjacent to each other and that
they are connected by the undirected edge (u, v).
Graph
ī‚§ A graph G is called undirected if every edge in it is
undirected
Graph
Graph
ī‚§ If a pair of vertices (u, v) is not the same as the pair (v,
u), we say that the edge (u, v) is directed from the
vertex u, called the edge’s tail, to the vertex v, called the
edge’s head. We also say that the edge (u, v) leaves u
and enter v
ī‚§ A graph whose every edge is directed is called directed
ī‚§ Directed graphs are also called Digraphs
Graph
Graph
ī‚§ A graph does not forbid loops, or edges connecting
vertices to themselves
ī‚§ Disallows multiple edges between the same vertices of
an undirected graph
ī‚§ We have the following inequality for the number of
edges |E| possible in an undirected graph with |V|
vertices and no loops:
Graph
ī‚§ A graph with every pair of its vertices connected by an
edge is called Complete
ī‚§ A standard notation for the complete graph with |V|
vertices is K|V|
ī‚§ A graph with relatively few possible edges missing is
called Dense
ī‚§ A graph with few edges relative to the number of its
vertices is called Sparse
Graph Representations
ī‚§ Adjacency Matrix
Graph Representations
ī‚§ The Adjacency matrix of a graph with n vertices is an
n x n Boolean matrix with one row and one column for
each of the graph’s vertices, in which the element in the
ith row and the jth column is equal to 1 if there is an
edge from the ith vertex to the jth vertex, and equal to 0
if there is no such edge
Graph Representations
ī‚§ Adjacency List
Graph Representations
ī‚§ The adjacency lists of a graph or a digraph is a collection
of linked lists, one for each vertex, that contain all the
vertices adjacent to the list’s vertex
Weighted Graphs
ī‚§ A weighted graph is a graph with numbers assigned to
its edges
ī‚§ These numbers are called weights or costs
ī‚§ Ex: Finding shortest path between two points in a
transportation or communication network or the
traveling salesman problem
Weighted Graphs
Path
ī‚§ A path from vertex u to vertex v of a graph G can be
defined as a sequence of adjacent vertices that starts
with u and ends with v
ī‚§ If all vertices of a path are distinct, the path is said to be
simple
ī‚§ The length of a path is the total number of vertices in
the vertex sequence defining the path minus 1, which is
the same as the number of edges in the path
Path
ī‚§ a, c, b, f is a simple path of length 3 from a to f
ī‚§ a, c, e, c, b, f is a path of length 5 from a to f
Directed Path
ī‚§ A directed path is a sequence of vertices in which every
consecutive pair of the vertices is connected by an edge
directed from the vertex listed first to the vertex listed
next
ī‚§ a, c, e, f is a directed path from a to f
Connected Graph
ī‚§ A graph is said to be connected if for any two vertices
(u, v) in v there is a path from u to v
ī‚§ That is to say that there are no isolated nodes in a
connected graph
Connected Graph
ī‚§ There is a path between each vertices
Connected Components of a Graph
ī‚§ If a graph is not connected, such a model will consist of
several connected pieces that are called Connected
Components of the Graph
ī‚§ A Connected Component is a maximal connected
subgraph of a given graph
Cycle
ī‚§ A cycle is a path of a positive length that starts and ends
at the same vertex and does not traverse the same edge
more than once.
ī‚§ Ex: f, h, i, g, f is cycle
ī‚§ A graph with no cycles is said to be Acyclic
Tree
ī‚§ A tree (more accurately, a free tree) is a connected
acyclic graph
Tree
ī‚§ Each of its connected components is a tree
Tree
ī‚§ A graph that has no cycles but is not necessarily
connected is called a Forest
Property
ī‚§ The no. of edges in a tree is always one less than the
number of its vertices
Rooted Tree
ī‚§ Every two vertices in a tree, there always exists exactly
one simple path from one of these vertices to the other
ī‚§ This property makes it possible to select an arbitrary
vertex in a free tree and consider it as the root of the so-
called Rooted Tree
ī‚§ A rooted tree is usually depicted by placing its root on
the top (level 0), the vertices adjacent to the root below
it (level 1), the vertices two edges apart from the root
still below (level 2) and so on.
Free Tree and its transformation into
a Rooted Tree
Ancestor Node
ī‚§ An ancestor of a node is any predecessor node on the
path from root to that node
ī‚§ The root node does not have any ancestors
ī‚§ Example: Nodes A, C, and G are the ancestors of node K
Ancestor Node
ī‚§ The vertex itself is usually considered its own ancestor
ī‚§ The set of ancestors that excludes the vertex itself is
referred to as the set proper ancestors
ī‚§ If (u, v) is the last edge of the simple path from the root
to vertex v (and u ≠ v), u is said to be the parent of v
and v is called a child of u
Sibling
ī‚§ The nodes with common parent are called Siblings or
brothers
ī‚§ Example : 10 & 11 are Siblings
Leaf Node
ī‚§ A node that has no children is called the Leaf Node or
the Terminal Node
ī‚§ Example: E, F, J, K, H and I
Descendant Node
ī‚§ A descendant node is any successor node on any path
from the node to a leaf node
ī‚§ Leaf nodes do not have any descendants
ī‚§ Example: C, G, J, and K are the descendants of node A
Descendant Node
ī‚§ All vertices for which a vertex v is an ancestor are said
to be descendants of v
ī‚§ The proper descendants exclude the vertex v itself
Subtree
ī‚§ All the descendants of a vertex v with all the edges
connecting them form the subtree of T rooted at that
vertex
Example
ī‚§ a is the root
ī‚§ d, g, f, h and i are
leaves
ī‚§ a, b, e and c are
parental
Example
ī‚§ Parent of b is a
ī‚§ Children of b are c
and g
ī‚§ Siblings of b are d
and e
ī‚§ Vertices of the
subtree rooted at b
are {b, c, g, h, i}
Depth of a Vertex
ī‚§ The depth of a vertex v is the length of the simple path
from the root to v
ī‚§ Ex: Depth for c is 2
Height of a Tree
ī‚§ The height of a tree is the length of the longest path
from the root to a leaf
ī‚§ Ex: Height of the tree is 3
Ordered Tree
ī‚§ An ordered tree is a rooted tree in which all the children
of each vertex are ordered
ī‚§ All the children are ordered left to right
Binary Tree
ī‚§ A binary tree can be defined as an ordered tree in which
every vertex has no more than two children
ī‚§ Each child is designated as either a left child or a right
child of its parent
ī‚§ A binary tree may also be empty
Binary Search Tree
ī‚§ Some numbers are assigned to vertices of the binary
tree
ī‚§ A number assigned to each parental vertex is larger than
all the numbers in its left subtree and smaller than all
the numbers in its right subtree
Standard Implementation of Binary
Search Tree
Binary Search Tree
ī‚§ The following inequalities for the height h of a binary
tree with n nodes are especially important for analysis of
such algorithms:
First child-next sibling
representation
ī‚§ The left pointer will point to the first child of the vertex
and the right pointer will point to its next sibling
ī‚§ This representation is called the first child-next sibling
representation
First child-next sibling
representation
First child-next sibling
representation
Sets
ī‚§ A set can be described as an unordered collection of
distinct items called elements of the set
ī‚§ A specific set is defined either by an explicit listing of its
elements (S = {2, 3, 5, 7}) or by specifying a property
that all the set’s elements and only they must satisfy
(S = {n: n is a prime number smaller than 10})
Sets
ī‚§ The most important set operations are:
ī‚§ Checking membership of a given item in a given set
ī‚§ Finding the union of two sets
ī‚§ Finding the intersection of two sets
Sets
ī‚§ Sets can be implemented in computer applications in two
ways:
ī‚§ The first considers only sets that are subsets of some
large set U, called the Universal set
ī‚§ If set U has n elements, then any subset S of U can be
represented by a bit string of size n, called a bit vector in
while the ith element is 1 if and only if the ith element of
U is included in set S
Sets
ī‚§ Ex: U = {1, 2, 3, 4, 5, 6, 7, 8, 9} S = {2, 3, 5, 7}
ī‚§ Bit String = 011010100
ī‚§ The second and more common way to represent a set
for computing purposes is to use the list structure to
indicate the set’s elements
ī‚§ Multiset or Bag
Dictionaries
ī‚§ For a set or a multiset:
ī‚§ Searching for a given item
ī‚§ Adding a new item
ī‚§ Deleting an item
ī‚§ A data structure that implements these three operations
is called the Dictionary
Set union problem
ī‚§ A number of applications in computing require a dynamic
partition of some n-element set into a collection of
disjoint subsets
ī‚§ After being initialized as a collection of n one-element
subsets, the collection is subjected to a sequence of
intermixed union and search operations
ī‚§ This problem is called the set union problem

More Related Content

Similar to Unit-I-DAA.pdf

Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureRai University
 
L01 intro-daa - ppt1
L01 intro-daa - ppt1L01 intro-daa - ppt1
L01 intro-daa - ppt1sankaran L
 
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.pptDATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.pptyarotos643
 
a581a6a2cb5778045788f0b1d7da1c0236f.pptx
a581a6a2cb5778045788f0b1d7da1c0236f.pptxa581a6a2cb5778045788f0b1d7da1c0236f.pptx
a581a6a2cb5778045788f0b1d7da1c0236f.pptxchristinamary2620
 
Bca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureBca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureRai University
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringRAJASEKHARV8
 
Lec01-Algorithems - Introduction and Overview.pdf
Lec01-Algorithems - Introduction and Overview.pdfLec01-Algorithems - Introduction and Overview.pdf
Lec01-Algorithems - Introduction and Overview.pdfMAJDABDALLAH3
 
Introductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, QueueIntroductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, QueueGhaffar Khan
 
data structures module I & II.pptx
data structures module I & II.pptxdata structures module I & II.pptx
data structures module I & II.pptxrani marri
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdNimmi Weeraddana
 
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdfChapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdfAxmedcarb
 
Intro to DS.pptx
Intro to DS.pptxIntro to DS.pptx
Intro to DS.pptxUsman Ahmed
 
Chapter3.pptx
Chapter3.pptxChapter3.pptx
Chapter3.pptxASMAALWADEE2
 
Datastructures using c++
Datastructures using c++Datastructures using c++
Datastructures using c++Gopi Nath
 

Similar to Unit-I-DAA.pdf (20)

Q
QQ
Q
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structure
 
L01 intro-daa - ppt1
L01 intro-daa - ppt1L01 intro-daa - ppt1
L01 intro-daa - ppt1
 
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.pptDATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
 
a581a6a2cb5778045788f0b1d7da1c0236f.pptx
a581a6a2cb5778045788f0b1d7da1c0236f.pptxa581a6a2cb5778045788f0b1d7da1c0236f.pptx
a581a6a2cb5778045788f0b1d7da1c0236f.pptx
 
Bca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureBca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structure
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
 
1597380885789.ppt
1597380885789.ppt1597380885789.ppt
1597380885789.ppt
 
Lec01-Algorithems - Introduction and Overview.pdf
Lec01-Algorithems - Introduction and Overview.pdfLec01-Algorithems - Introduction and Overview.pdf
Lec01-Algorithems - Introduction and Overview.pdf
 
Introductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, QueueIntroductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, Queue
 
CSE 443 (1).pptx
CSE 443 (1).pptxCSE 443 (1).pptx
CSE 443 (1).pptx
 
data structures module I & II.pptx
data structures module I & II.pptxdata structures module I & II.pptx
data structures module I & II.pptx
 
M v bramhananda reddy dsa complete notes
M v bramhananda reddy dsa complete notesM v bramhananda reddy dsa complete notes
M v bramhananda reddy dsa complete notes
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
 
intr_ds.ppt
intr_ds.pptintr_ds.ppt
intr_ds.ppt
 
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdfChapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdf
 
Intro to DS.pptx
Intro to DS.pptxIntro to DS.pptx
Intro to DS.pptx
 
Chapter3.pptx
Chapter3.pptxChapter3.pptx
Chapter3.pptx
 
Datastructures using c++
Datastructures using c++Datastructures using c++
Datastructures using c++
 

More from AdityaKumar993506

Hidden Markov Model (HMM).pptx
Hidden Markov Model (HMM).pptxHidden Markov Model (HMM).pptx
Hidden Markov Model (HMM).pptxAdityaKumar993506
 
Fragments In Android.pptx
Fragments In Android.pptxFragments In Android.pptx
Fragments In Android.pptxAdityaKumar993506
 
Prediction of Parkinson Disease using Autoencoder Convolutional Neural.pptx
Prediction of Parkinson Disease using Autoencoder Convolutional Neural.pptxPrediction of Parkinson Disease using Autoencoder Convolutional Neural.pptx
Prediction of Parkinson Disease using Autoencoder Convolutional Neural.pptxAdityaKumar993506
 
Researc-paper_Project Work Phase-1 PPT (21CS09).pptx
Researc-paper_Project Work Phase-1 PPT (21CS09).pptxResearc-paper_Project Work Phase-1 PPT (21CS09).pptx
Researc-paper_Project Work Phase-1 PPT (21CS09).pptxAdityaKumar993506
 

More from AdityaKumar993506 (6)

Hidden Markov Model (HMM).pptx
Hidden Markov Model (HMM).pptxHidden Markov Model (HMM).pptx
Hidden Markov Model (HMM).pptx
 
Fragments In Android.pptx
Fragments In Android.pptxFragments In Android.pptx
Fragments In Android.pptx
 
Find-S Algorithm
Find-S AlgorithmFind-S Algorithm
Find-S Algorithm
 
Prediction of Parkinson Disease using Autoencoder Convolutional Neural.pptx
Prediction of Parkinson Disease using Autoencoder Convolutional Neural.pptxPrediction of Parkinson Disease using Autoencoder Convolutional Neural.pptx
Prediction of Parkinson Disease using Autoencoder Convolutional Neural.pptx
 
template.pptx
template.pptxtemplate.pptx
template.pptx
 
Researc-paper_Project Work Phase-1 PPT (21CS09).pptx
Researc-paper_Project Work Phase-1 PPT (21CS09).pptxResearc-paper_Project Work Phase-1 PPT (21CS09).pptx
Researc-paper_Project Work Phase-1 PPT (21CS09).pptx
 

Recently uploaded

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoÃŖo Esperancinha
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...Call Girls in Nagpur High Profile
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 

Recently uploaded (20)

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 

Unit-I-DAA.pdf

  • 2. Important Problem Types ī‚§ Sorting ī‚§ Searching ī‚§ String Processing ī‚§ Graph Problems ī‚§ Combinatorial Problems
  • 3. Sorting ī‚§ The sorting problem is to rearrange the items of a given list of non-decreasing order.
  • 4. Sorting ī‚§ List of Numbers ī‚§ Characters from an alphabet ī‚§ Character Strings ī‚§ Records maintained by schools about their students ī‚§ Libraries about their holdings ī‚§ Companies about their employees
  • 5. Sorting ī‚§ In the case of records, we need to choose a piece of information to guide sorting ī‚§ Ex1: To sort student records in alphabetical order of names or by student number or by student grade-point average ī‚§ Such a specially chosen piece of information is called a Key
  • 6. Why would we want a sorted list? ī‚§ Sorted list can be required output of a task such as Ranking Internet search results or Ranking students by their GPA Scores ī‚§ Sorting makes many questions about the list easier to answer ī‚§ The most important of them is Searching ī‚§ Ex: Dictionaries, Telephone Books, Class list and so on
  • 7. Why would we want a sorted list? ī‚§ Sorting is used as an auxiliary step in several important algorithms in other areas ī‚§ Ex: Geometric algorithms and Data compression ī‚§ Ex: Greedy approach – an important algorithm design technique requires a sorted input
  • 8. Performance ī‚§ Some algorithms are indeed better than others ī‚§ No algorithm that would be the best solution in all situations ī‚§ Some of the algorithms are simple but relatively slow ī‚§ While others are faster but more complex ī‚§ Some work better on randomly ordered inputs, while others do better on almost-sorted lists
  • 9. Performance ī‚§ Some are suitable only for lists residing in the fast memory, while others can be adopted for sorting large files stored on a disk
  • 10. Properties ī‚§ First Property: A sorting algorithm is called Stable if it preserves the relative order of any two equal elements in its input ī‚§ If an input list contains two equal elements in positions i and j where i < j, then in the sorted list they have to be in positions i’ and j’, respectively, such that i’< j’
  • 11. Properties ī‚§ Ex: List of students sorted alphabetically and we want to sort it according to student GPA. ī‚§ A stable algorithm will yield a list in which students with the same GPA will still be sorted alphabetically
  • 12. Properties ī‚§ Second Property: Amount of extra memory the algorithm requires ī‚§ An algorithm is said to be in-place if it does not require extra memory. ī‚§ There are important sorting algorithms that are in-place and those that are not.
  • 13. Searching ī‚§ The searching problem deals with finding a given value, called a Search Key, in a given set (or a multiset, which permits several elements to have the same value) ī‚§ Ex: Sequential Search and Binary Search ī‚§ Latter algorithms are of particular importance for real- world applications because they are indispensable for storing and retrieving information from large databases
  • 14. Performance ī‚§ No single algorithm that fits all situations best ī‚§ Some algorithms work faster than others but require more memory ī‚§ Some are very fast but applicable only to sorted arrays
  • 15. Issue ī‚§ Specifically, in applications where the underlying data may change frequently relative to the number of searches, searching has to be considered in conjunction with two other operations: an addition to and deletion from the data set of an item ī‚§ In such situations, data structures and algorithms should be chosen to strike a balance among the requirements of each operation
  • 16. Issue ī‚§ Organizing very large data sets for efficient searching poses special challenges with important implications for real-world applications
  • 17. String Processing ī‚§ A string is a sequence of characters from an alphabet ī‚§ Text strings which comprise letters, numbers and special characters ī‚§ Bit Strings which comprise zeros and ones ī‚§ Gene Sequences which can be modeled by strings of characters from the four-character alphabet {A, C, G, T}
  • 18. String Processing ī‚§ String processing algorithms have been important for computer science for a long time in conjunction with computer languages and compiling issues ī‚§ String Matching Algorithms
  • 19. Graph Problems ī‚§ One of the oldest and most interesting areas in algorithmics is graph algorithms ī‚§ A graph can be though as a collection of points called Vertices, some of which are connected by line segments called Edges ī‚§ Graphs can be used for modeling a wide variety of applications, including Transportation, Communication, Social and Economic Networks, Project Scheduling, and Games
  • 20. Graph Problems ī‚§ Basic graph algorithms ī‚§ Graph-Traversal Algorithms (how can one reach all the points in a network?) ī‚§ Shortest-path Algorithms (what is the best route between two cities?) ī‚§ Topological Sorting for graphs with directed edges (is a set of courses with their prerequisites consistent or self-contradictory?)
  • 21. Graph Problems ī‚§ The Traveling salesman problem (TSP) is the problem of finding the shortest tour through n cities that visits every city exactly once ī‚§ Ex: Route planning, circuit board and VLSI chip fabrication, X-ray crystallography, and Genetic engineering
  • 22. Graph Problems ī‚§ The graph-coloring problem seeks to assign the smallest number of colors to the vertices of a graph so that no two adjacent vertices are the same color. ī‚§ Ex: Event Scheduling ī‚§ If the events are represented by vertices that are connected by an edge if and only if the corresponding events cannot be scheduled at the same time ī‚§ A solution to the graph-coloring problem yields an optimal schedule
  • 23. Combinatorial Problems ī‚§ Ex: Traveling salesman problem and Graph coloring problem ī‚§ These are problems that ask, explicitly or implicitly, to find a combinatorial object such as a permutation, a combination, or a subset that satisfies certain constraints ī‚§ A desired combinatorial object may also be required to have some additional property such as a maximum value or a minimum cost
  • 24. Combinatorial Problems ī‚§ Combinatorial problems are the most difficult problems in computing from both a theoretical and practical standpoint ī‚§ First, the number of combinatorial objects typically grows extremely fast with a problem’s size, reaching unimaginable magnitudes even for moderate-sized instances ī‚§ Second, there are no known algorithms for solving most such problems exactly in an acceptable amount of time
  • 26. Stack ī‚§ Last-In-First-Out (LIFO) ī‚§ A stack is a list in which insertions and deletions can be done only at the end. ī‚§ This end is called the top ī‚§ They are indispensable for implementing recursive algorithms
  • 27. Queue ī‚§ First-In-First-Out (FIFO) ī‚§ A queue is a list from which elements are deleted from one end of the structure, called the front (dequeue), and new elements are added to the other end, called the rear (enqueue) ī‚§ Important applications include several algorithms for graph problems
  • 28. Queue ī‚§ Many important applications require selection of an item of the highest priority among a dynamically changing set of candidates ī‚§ A data structure that seeks to satisfy the needs of such applications is called a Priority Queue ī‚§ A Priority Queue is a collection of data items from a totally ordered universe
  • 29. Queue ī‚§ The principal operations on a priority queue are finding its largest element, deleting its largest element and adding a new element. ī‚§ Implementation of a priority queue is based on data structure called the Heap
  • 30. Graph ī‚§ A Graph G = <V, E> is defined by a pair of two sets: ī‚§ A finite nonempty set V of items called Vertices ī‚§ A set E of pairs of these items called Edges ī‚§ If these pair of vertices are unordered, i.e. a pair of vertices (u, v) is the same as the pair (v, u), we say that the vertices u and v are adjacent to each other and that they are connected by the undirected edge (u, v).
  • 31. Graph ī‚§ A graph G is called undirected if every edge in it is undirected
  • 32. Graph
  • 33. Graph ī‚§ If a pair of vertices (u, v) is not the same as the pair (v, u), we say that the edge (u, v) is directed from the vertex u, called the edge’s tail, to the vertex v, called the edge’s head. We also say that the edge (u, v) leaves u and enter v ī‚§ A graph whose every edge is directed is called directed ī‚§ Directed graphs are also called Digraphs
  • 34. Graph
  • 35. Graph ī‚§ A graph does not forbid loops, or edges connecting vertices to themselves ī‚§ Disallows multiple edges between the same vertices of an undirected graph ī‚§ We have the following inequality for the number of edges |E| possible in an undirected graph with |V| vertices and no loops:
  • 36. Graph ī‚§ A graph with every pair of its vertices connected by an edge is called Complete ī‚§ A standard notation for the complete graph with |V| vertices is K|V| ī‚§ A graph with relatively few possible edges missing is called Dense ī‚§ A graph with few edges relative to the number of its vertices is called Sparse
  • 38. Graph Representations ī‚§ The Adjacency matrix of a graph with n vertices is an n x n Boolean matrix with one row and one column for each of the graph’s vertices, in which the element in the ith row and the jth column is equal to 1 if there is an edge from the ith vertex to the jth vertex, and equal to 0 if there is no such edge
  • 40. Graph Representations ī‚§ The adjacency lists of a graph or a digraph is a collection of linked lists, one for each vertex, that contain all the vertices adjacent to the list’s vertex
  • 41. Weighted Graphs ī‚§ A weighted graph is a graph with numbers assigned to its edges ī‚§ These numbers are called weights or costs ī‚§ Ex: Finding shortest path between two points in a transportation or communication network or the traveling salesman problem
  • 43. Path ī‚§ A path from vertex u to vertex v of a graph G can be defined as a sequence of adjacent vertices that starts with u and ends with v ī‚§ If all vertices of a path are distinct, the path is said to be simple ī‚§ The length of a path is the total number of vertices in the vertex sequence defining the path minus 1, which is the same as the number of edges in the path
  • 44. Path ī‚§ a, c, b, f is a simple path of length 3 from a to f ī‚§ a, c, e, c, b, f is a path of length 5 from a to f
  • 45. Directed Path ī‚§ A directed path is a sequence of vertices in which every consecutive pair of the vertices is connected by an edge directed from the vertex listed first to the vertex listed next ī‚§ a, c, e, f is a directed path from a to f
  • 46. Connected Graph ī‚§ A graph is said to be connected if for any two vertices (u, v) in v there is a path from u to v ī‚§ That is to say that there are no isolated nodes in a connected graph
  • 47. Connected Graph ī‚§ There is a path between each vertices
  • 48. Connected Components of a Graph ī‚§ If a graph is not connected, such a model will consist of several connected pieces that are called Connected Components of the Graph ī‚§ A Connected Component is a maximal connected subgraph of a given graph
  • 49. Cycle ī‚§ A cycle is a path of a positive length that starts and ends at the same vertex and does not traverse the same edge more than once. ī‚§ Ex: f, h, i, g, f is cycle ī‚§ A graph with no cycles is said to be Acyclic
  • 50. Tree ī‚§ A tree (more accurately, a free tree) is a connected acyclic graph
  • 51. Tree ī‚§ Each of its connected components is a tree
  • 52. Tree ī‚§ A graph that has no cycles but is not necessarily connected is called a Forest
  • 53. Property ī‚§ The no. of edges in a tree is always one less than the number of its vertices
  • 54. Rooted Tree ī‚§ Every two vertices in a tree, there always exists exactly one simple path from one of these vertices to the other ī‚§ This property makes it possible to select an arbitrary vertex in a free tree and consider it as the root of the so- called Rooted Tree ī‚§ A rooted tree is usually depicted by placing its root on the top (level 0), the vertices adjacent to the root below it (level 1), the vertices two edges apart from the root still below (level 2) and so on.
  • 55. Free Tree and its transformation into a Rooted Tree
  • 56. Ancestor Node ī‚§ An ancestor of a node is any predecessor node on the path from root to that node ī‚§ The root node does not have any ancestors ī‚§ Example: Nodes A, C, and G are the ancestors of node K
  • 57. Ancestor Node ī‚§ The vertex itself is usually considered its own ancestor ī‚§ The set of ancestors that excludes the vertex itself is referred to as the set proper ancestors ī‚§ If (u, v) is the last edge of the simple path from the root to vertex v (and u ≠ v), u is said to be the parent of v and v is called a child of u
  • 58. Sibling ī‚§ The nodes with common parent are called Siblings or brothers ī‚§ Example : 10 & 11 are Siblings
  • 59. Leaf Node ī‚§ A node that has no children is called the Leaf Node or the Terminal Node ī‚§ Example: E, F, J, K, H and I
  • 60. Descendant Node ī‚§ A descendant node is any successor node on any path from the node to a leaf node ī‚§ Leaf nodes do not have any descendants ī‚§ Example: C, G, J, and K are the descendants of node A
  • 61. Descendant Node ī‚§ All vertices for which a vertex v is an ancestor are said to be descendants of v ī‚§ The proper descendants exclude the vertex v itself
  • 62. Subtree ī‚§ All the descendants of a vertex v with all the edges connecting them form the subtree of T rooted at that vertex
  • 63. Example ī‚§ a is the root ī‚§ d, g, f, h and i are leaves ī‚§ a, b, e and c are parental
  • 64. Example ī‚§ Parent of b is a ī‚§ Children of b are c and g ī‚§ Siblings of b are d and e ī‚§ Vertices of the subtree rooted at b are {b, c, g, h, i}
  • 65. Depth of a Vertex ī‚§ The depth of a vertex v is the length of the simple path from the root to v ī‚§ Ex: Depth for c is 2
  • 66. Height of a Tree ī‚§ The height of a tree is the length of the longest path from the root to a leaf ī‚§ Ex: Height of the tree is 3
  • 67. Ordered Tree ī‚§ An ordered tree is a rooted tree in which all the children of each vertex are ordered ī‚§ All the children are ordered left to right
  • 68. Binary Tree ī‚§ A binary tree can be defined as an ordered tree in which every vertex has no more than two children ī‚§ Each child is designated as either a left child or a right child of its parent ī‚§ A binary tree may also be empty
  • 69. Binary Search Tree ī‚§ Some numbers are assigned to vertices of the binary tree ī‚§ A number assigned to each parental vertex is larger than all the numbers in its left subtree and smaller than all the numbers in its right subtree
  • 70. Standard Implementation of Binary Search Tree
  • 71. Binary Search Tree ī‚§ The following inequalities for the height h of a binary tree with n nodes are especially important for analysis of such algorithms:
  • 72. First child-next sibling representation ī‚§ The left pointer will point to the first child of the vertex and the right pointer will point to its next sibling ī‚§ This representation is called the first child-next sibling representation
  • 75. Sets ī‚§ A set can be described as an unordered collection of distinct items called elements of the set ī‚§ A specific set is defined either by an explicit listing of its elements (S = {2, 3, 5, 7}) or by specifying a property that all the set’s elements and only they must satisfy (S = {n: n is a prime number smaller than 10})
  • 76. Sets ī‚§ The most important set operations are: ī‚§ Checking membership of a given item in a given set ī‚§ Finding the union of two sets ī‚§ Finding the intersection of two sets
  • 77. Sets ī‚§ Sets can be implemented in computer applications in two ways: ī‚§ The first considers only sets that are subsets of some large set U, called the Universal set ī‚§ If set U has n elements, then any subset S of U can be represented by a bit string of size n, called a bit vector in while the ith element is 1 if and only if the ith element of U is included in set S
  • 78. Sets ī‚§ Ex: U = {1, 2, 3, 4, 5, 6, 7, 8, 9} S = {2, 3, 5, 7} ī‚§ Bit String = 011010100 ī‚§ The second and more common way to represent a set for computing purposes is to use the list structure to indicate the set’s elements ī‚§ Multiset or Bag
  • 79. Dictionaries ī‚§ For a set or a multiset: ī‚§ Searching for a given item ī‚§ Adding a new item ī‚§ Deleting an item ī‚§ A data structure that implements these three operations is called the Dictionary
  • 80. Set union problem ī‚§ A number of applications in computing require a dynamic partition of some n-element set into a collection of disjoint subsets ī‚§ After being initialized as a collection of n one-element subsets, the collection is subjected to a sequence of intermixed union and search operations ī‚§ This problem is called the set union problem