Lecture 1
Lecture 1
Analysis
The
Operating Systems (CS 140) Machine learning (CS 229) Cryptography (CS 255)
Algorithmic
Lens
Asymptotic
Analysis
MIDTERM
Dynamic
Greedy Algorithms Programming
Graphs!
FINAL
The
Future!
Aside: the bigger picture
Write programs
based on the
Use or design an algorithms
algorithm to
Turn a real- solve the
world problem problem
into a formal
problem
Some (potentially impactful) decisions:
• Introduction to Algorithms
3 • Analysis of Algorithms
1. Learn at least one Programming
language
• This should be your first step while starting to learn data
structure and algorithms. We as human beings, before
learning to write a sentence or an essay on a topic, first try
to learn that language: the alphabet, letters, and
punctuations in it, how and when to use them. The
same goes for programming also.
• Firstly, select a language of your choice, be it Java, C,
C++, Python, or any other language of your choice.
Before learning how to code in that language you should
learn about the building pieces of the language: the basic
syntax, the data types, variables, operators,
conditional statements, loops, functions, etc. You may
also learn the concept of OOP (Object Oriented
Programming).
2. Learn about Complexities
• Here comes one of the interesting and
important topics. The primary motive to use
DSA is to solve a problem effectively and
efficiently.
• How can you decide if a program written by
you is efficient or not? This is measured by
complexities. Complexity is of two types:
• Time Complexity: Time complexity is used to
measure the amount of time required to
execute the code.
• Space Complexity: Space complexity means
the amount of space required to execute
successfully the functionalities of the code.
Auxiliary Space Vs Space Complexity:
• The term Space Complexity is misused for Auxiliary
Space at many places. Following are the correct
definitions of Auxiliary Space and Space Complexity.
• Auxiliary Space is the extra space or temporary
space used by an algorithm.
• The space Complexity of an algorithm is the total
space taken by the algorithm with respect to the
input size. Space complexity includes both
Auxiliary space and space used by input.
• So how can we determine which one is efficient?
The answer is the use of asymptotic notation.
Example: Auxiliary Space Vs Space Complexity
• For example, if we want to compare standard
sorting algorithms on the basis of space, then
Auxiliary Space would be a better criterion than
Space Complexity. Merge Sort uses O(n) auxiliary
space, Insertion sort, and Heap Sort use O(1)
auxiliary space. The space complexity of all these
sorting algorithms is O(n) though.
• Space complexity is a parallel concept to time
complexity. If we need to create an array of size n,
this will require O(n) space. If we create a two-
dimensional array of size n*n, this will require
O(n2) space.
• In recursive calls stack space also counts.
How each call is added up in the
level of the stack?
Output:
Each of these
calls is added
to call stack
and takes up
actual
memory. So it
takes O(n)
space.
Asymptotic Notation:
• Asymptotic notation is a mathematical
tool that calculates the required time in
terms of input size and does not require
the execution of the code.
Asymptotic Notation:
• It neglects the system-dependent constants
and is related to only the number of modular
operations being performed in the whole
program. The following 3 asymptotic notations
are mostly used to represent the time
complexity of algorithms:
• Big-O Notation (Ο) – Big-O notation
specifically describes the worst-case scenario.
• Omega Notation (Ω) – Omega(Ω) notation
specifically describes the best-case scenario.
• Theta Notation (θ) – This notation represents
the average complexity of an algorithm.
3. Data Structures
• A data structure is a meaningful way of
arranging and storing data in a computer so as to
use it efficiently.
• More precisely, a data structure is a collection of
data values, the relationships among them, and
the functions or operations that can be applied
to the data.
• Data structures provides means for management of
large dataset such as databases or internet
indexing services.
• Though file system is a much more advanced data
structure, it does try to solve the fundamental issue
that any data structure tries to tackle i.e. efficient
way of storing, organizing, and maintaining data.
Basic Concepts
Data
Data
Structure
Algorithms
Analysis of
Algorithms
Asymptotic Complexity - determines how fast an algorithm can compute
(with respect to input) when applied over a data structure.
Types of the Data Structure
Non-primitive data structures,
The primitive data structure,
can store data of more than one
also known as built-in data
type. For example, array, linked
types can store the data of only
list, stack, queue, tree, graph, and
one type. You know the integers,
so on. These are often referred to
floating points, characters, pointers
as derived data types.
etc.
Linear Vs Non-linear