SS ZG519 - Data Structures and Algorithms Design: BITS Pilani
SS ZG519 - Data Structures and Algorithms Design: BITS Pilani
Content Structure
Contact Hour 2:
1.3 Correctness of Algorithms.
1.4 Analyzing Recursive Algorithms –
– Recurrence relations.
– Specifying runtime of recursive algorithms.
– Solving recurrence equations.
1.5 Case Study: Analyzing Algorithms.
3
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Contact Hour 3 :
2.1 Stacks –
– Stack ADT and Implementation.
– Applications.
Contact Hour 4 :
2.2 Queues –
– Queue ADT and Implementation.
– Applications.
Contact Hour 5 – 6 :
2.3 List –
– Notion of position in lists.
– List ADT and Implementation
4
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Contact Hour 7 – 13 :
3.1 Trees.
3.2 Binary Trees.
3.3 Binary Search Trees.
3.4 Height Balanced Trees / AVL Trees.
3.5 Multi way Tree.
3.6 Heaps.
Contact Hour 14 - 15 :
4.1 Unordered Dictionary.
4.2 Hash Tables.
4.3 Ordered Dictionary.
5
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Contact Hour 16 - 21 :
5.1 Greedy Method.
5.2 Divide & Conquer Method.
5.3 Dynamic Programming.
5.4 Graph Algorithms.
Contact Hour 22 :
6. Complexity Classes.
Course Review.
6
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Pilani | Dubai | Goa | Hyderabad
8
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Pilani | Dubai | Goa | Hyderabad
Evaluation Scheme
Syllabus for Comprehensive Exam (Open Book): All topics (Session Nos. 1 to 22)
10
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Pilani | Dubai | Goa | Hyderabad
12
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Evaluation Guidelines:
For Closed Book tests: No books or reference material of any kind will be
permitted.
For Open Book exams: Use of books and any printed / written reference
material (filed or bound) is permitted. However, loose sheets of paper will
not be allowed. Use of calculators is permitted in all exams.
Laptops/Mobiles of any kind are not allowed. Exchange of any material is
not allowed.
13
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
If a student is unable to appear for the Regular Test/Exam due to
genuine exigencies, the student should follow the procedure to
apply for the Make-Up Test/Exam which will be made available on
the Elearn portal. The Make-Up Test/Exam will be conducted only at
selected exam centres on the dates to be announced later.
14
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Pilani | Dubai | Goa | Hyderabad
16
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Algorithm Criteria -
Finiteness : Algorithm terminates after finite number of steps for all test
cases.
17
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Algorithm Descriptions -
18
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
19
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
20
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Pseudocode -
21
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Pseudocode Details -
22
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Primitive Operations (time unit) -
23
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Problems and Algorithms -
24
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Problems and Algorithms -
25
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Algorithm Analysis -
The main focus of algorithm analysis in this course will be upon the
“quality” of algorithms already known to be correct.
This analysis proceeds in two dimensions:
• Time complexity: The amount of time which execution of the
algorithm takes, usually specified as a function of the size of the
input
• Space complexity: The amount of space (memory) which
execution of the algorithm takes, usually specified as a function
of the size of the input.
Such analyses may be performed both experimentally and
analytically.
26
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Pilani | Dubai | Goa | Hyderabad
Algorithm Classification
28
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Classification by implementation -
29
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Serial or parallel or distributed: Algorithms are usually discussed with the assumption that computers
execute one instruction of an algorithm at a time. Those computers are sometimes called serial
computers. An algorithm designed for such an environment is called a serial algorithm. Parallel
algorithms take advantage of computer architectures where several processors can work on a
problem at the same time, whereas distributed algorithms utilize multiple machines connected with a
network. Parallel or distributed algorithms divide the problem into sub problems and collect the
results back together. Sorting algorithms can be parallelized efficiently, but their communication
overhead is expensive. Iterative algorithms are generally parallelizable. Some problems have no
parallel algorithms, and are called inherently serial problems.
Deterministic or non-deterministic: Deterministic algorithms solve the problem with exact decision at
every step of the algorithm whereas non-deterministic algorithm solves problems via guessing
although typical guesses are made more accurate through the use of heuristics.
Exact or approximate: While many algorithms reach an exact solution, approximation algorithms seek
an approximation that is close to the true solution. Approximation may use either a deterministic or a
random strategy.
30
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Classification by Design Paradigm -
31
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Dynamic programming : When a problem shows optimal substructure, meaning the
optimal solution to a problem can be constructed from optimal solutions to sub problems,
and overlapping sub problems, meaning the same sub problems are used to solve many
different problem instances, a quicker approach called dynamic programming avoids
recomputing solutions that have already been computed. For example, the shortest path
to a goal from a vertex in a weighted graph can be found by using the shortest path to the
goal from all adjacent vertices.
The main difference between dynamic programming and divide and conquer is that sub
problems are more or less independent in divide and conquer, whereas sub problems
overlap in dynamic programming.
32
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Greedy method : A greedy algorithm is similar to a dynamic programming algorithm,
but the difference is that solutions to the sub problems do not have to be known at
each stage; instead a "greedy" choice can be made of what looks best for the
moment. The greedy method extends the solution with the best possible decision
(not all feasible decisions) at an algorithmic stage based on the current local
optimum and the best decision (not all possible decisions) made in previous stage. It
does not give accurate answer to many problems. But when it works, it will be the
fastest method. The most popular greedy algorithm is finding the minimal spanning
tree as given by Kruskal.
33
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Reduction - This technique involves solving a difficult problem by
transforming it into a better known problem for which we have (hopefully)
asymptotically optimal algorithms. The goal is to find a reducing algorithm
whose complexity is not dominated by the resulting reduced algorithm's. For
example, one selection algorithm for finding the median in an unsorted list
involves first sorting the list (the expensive portion) and then pulling out the
middle element in the sorted list (the cheap portion). This technique is also
known as transform and conquer.
34
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Probabilistic and heuristic paradigm - Algorithms belonging to this class fit the
definition of an algorithm more loosely.
Probabilistic algorithms are those that make some choices randomly (or pseudo-
randomly); for some problems, it can in fact be proven that the fastest solutions must
involve some randomness.
Heuristic algorithms, whose general purpose is not to find an optimal solution, but an
approximate solution where the time or resources are limited. They are not practical to
find perfect solutions. An example of this would be local search, or simulated
annealing.
35
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Pilani | Dubai | Goa | Hyderabad
Analysis of Algorithms
37
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Running Time -
Write a program
implementing the algorithm
Run the program with inputs
of varying size and
composition
Use a method like
System.currentTimeMillis() to
get an accurate measure
of the actual running time
Plot the results
39
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Limitations of Experiments -
40
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Random Access
Machine(RAM) Model -
41
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Instead of trying to determine the specific execution time of each primitive
operation, we will simply count how many primitive operations are executed,
and use this number as a high-level estimate of the running time of the
algorithm.
42
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Counting Primitive Operations -
46
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Growth Rate of Running Time -
47
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The Growth Rate of the Six Popular
functions -
n logn n nlogn n2 n3 2n
4 2 4 8 16 64 16
8 3 8 24 64 512 256
49
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Consider the three program segments:
x = x + 1;
50
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
❖In the first program segment, we assume that
the statement x = x + 1 is not contained within
any loop. Then its frequency count is one.
51
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Hence, 1 , n and n2 are said to be different and increasing
orders of magnitude.
52
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Pilani | Dubai | Goa | Hyderabad
References
53
54
SS ZG519 : Data Structures and
3/23/2019
Algorithms Design
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
BITS Pilani
Pilani | Dubai | Goa | Hyderabad
THANKS
55