DSA Java Day1 Introduction
DSA Java Day1 Introduction
Recursion
Data Structures
DSA Introduction
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Part 2
Dynamic Programming
Greedy Algorithms
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Introduction
A computer program is a collection of instructions to perform a specific task. For this, a computer program may need to store
data, retrieve data, and perform computations on the data.
A data structure is a named location that can be used to store and organize data.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Good Computer
Program
Easy to debug.
Easy to modify.
Easy to maintain.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Good Computer
Program
a) Algorithms
b) Data Structures
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
DSA Introduction
A data structure represents the logical relationship that exists between individuals elements of data to carry out certain tasks.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Algorithm??
An algorithm states the actions to be executed and the order in which these actions are to be executed.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Algorithmic
Properties
It must be correct.
No ambiguity.
Must terminate.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
How to develop
algorithm?
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Efficiency of an
algorithm.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Efficiency of an
algorithm.
Efficiency of an algorithm denotes the rate at which an algorithm solves a problem of size n.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Characteristics of an
algorithm.
Unambiguous
Input
Output
Finiteness
Feasibility
Independent
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
How to write an
Algorithm?
Step 1 − START
Step 2 − declare three integers a, b & c
Step 3 − define values of a & b
Step 4 − add values of a & b
Step 5 − store output of step 4 to c
Step 6 − print c
Step 7 − STOP
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Time Complexity of
an algorithm.
Compilation Time
Run Time
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Time Complexity of
an algorithm.
Worst Case
Average Case
Best Case
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Time Complexity of
an algorithm.
Worst Case: Longest time that an algorithm will use to produce desired results.
Average Case : Average time that the algorithm will use. It depends upon probability distribution.
Best Case: Shortest time that the algorithm will use to produce desired results.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Space Complexity of
an algorithm.
Datatype Array[size];
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Space Complexity of
an algorithm.
There are 3 different spaces considered for determining the amount of memory used by the algo.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Problem Solving??
Frequency of processing
Detailed specifications
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Algorithm Analysis
Method 1: Code each algorithm and run them to see how long they take.
Method 2: Develop a model of the way computers work and compare how the algorithm behaves in the model.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
How to measure algorithm
performance?
Memory required
Running time
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Importance of studying
Algorithm?
“Practicing algorithms will increase your skill and your visibility at work”.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
TCS Exam
Example
There is a JAR full of candies for sale at a mall counter. JAR has the capacity N, that is JAR can contain maximum N candies when JAR is full. At any point of time. JAR can have M number of
Candies where M<=N. Candies are served to the customers. JAR is never remain empty as when last k candies are left. JAR if re filled with new candies in such a way that JAR get full. Write a code
to implement above scenario. Display JAR at counter with available number of candies. Input should be the number of candies o ne customer can order at point of time. Update the JAR after each
purchase and display JAR at Counter.
Output should give number of Candies sold and updated number of Candies in JAR.
If Input is more than candies in JAR, return: “INVALID INPUT”
Given,
N=10, where N is NUMBER OF CANDIES AVAILABLE
K =< 5, where k is number of minimum candies that must be inside JAR ever.
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video
Algorithmic Solution
Step1: START
2: DECLARE AND INITIALIZE VARIABLES…N=10 AND K<=5
3. ACCEPT INPUT FROM THE USER..
4. CHECK CONDITION..
5. IF TRUE: DISPLAY THE POSITIVE / ACCEPTED RESULTS
6. IF FASLE: DISPLAY THE NEGATIVE/ REJECTED RESULTS..”INVALID INPUT.
7. STOP
This video is sole property of Talent Battle Pvt. Ltd. Strict penal action will be taken against unauthorized piracy of this video