Data Structures and
Algorithms
By Prasanna Jatla
Sr Software Engineer
American Express
Basic Data Structures
• Overview of Arrays
• Overview of Linked Lists
• Overview of Stacks and Queues
What is
Recursion
• Recursionis a programming technique where a function calls itself directly or
indirectly.
• The function keeps calling itselfuntil a base case is reached, which stops the
recursion.
• Each recursive call typically creates a newactivation recordon the call stack.
• Recursionallows us to break down complex problems into smaller, self-similar
subproblems.
Advantages ofRecursion:
• Elegant solutions: Recursioncan provide elegantandconcise solutions to
problems that might be cumbersome with iterative approaches (using loops).
• Self-similar problems: Recursionshines when dealing with problems that
exhibitself-similarity, where the solution involves solving smaller versions ofthe
originalproblem.
• Improved readability: In some cases, recursive code canbe more readable
and easier tounderstandcompared to iterative solutions, especiallyfor
problems with inherentself-similarity.
Real-world
Applications
of Recursion
• Factorials: Calculating factorials of numbers is a
classic example of recursion.
• Tree traversals: Recursion is commonly used to
traverse tree data structures (like binary trees) in
a depth-firstmanner.
• File system navigation: Recursioncan be used
to navigate throughdirectory structureswithin a
file system.
• Maze solving algorithms: Several maze-solving
algorithms, like backtracking,utilize recursionto
explore differentpaths within the maze.
• Divide and conquer algorithms: Many divide-
and-conqueralgorithms, like merge sort and
quick sort, rely on recursionto break down
problems into smaller subproblems.
Analyzing time complexity
• Definition of AsymptoticNotation
• Importancein AnalyzingAlgorithm
Efficiency
• Definition of Big O Notation
• Analyzetime complexity of below code.
Dynamic Programming
• Core Idea: Breaks down a complex problem into smaller, overlapping
subproblems.
• Solves subproblems: Computes the optimal solutions for each
subproblem and stores them for reuse.
• Bottom-up approach: Builds solutions for larger subproblems using
previously solved smaller ones.
• Suitable for: Optimization problems with overlapping subproblems
(e.g., shortest path, edit distance).
Solving some Interview coding problems
• Generate all subsets , given an array of numbers
• K sum problem
• Check number of uni-value sub nodes in a tree.
Greedy Algorithms
• Core Idea: Makes the locally optimal choice at
each step with the hope of achieving a globally
optimal solution.
• Heuristic approach: Employs a set of rules to
make seemingly optimal choices at each step.
• Simpler implementation: Often easier to
understand and implement compared to
Dynamic Programming.
• No guarantee of global optimality: The locally
optimal choice at each step might not lead to the
overall best solution.
Q & A

Introduction to Algorithms And DataStructure

  • 1.
    Data Structures and Algorithms ByPrasanna Jatla Sr Software Engineer American Express
  • 2.
    Basic Data Structures •Overview of Arrays • Overview of Linked Lists • Overview of Stacks and Queues
  • 3.
    What is Recursion • Recursionisa programming technique where a function calls itself directly or indirectly. • The function keeps calling itselfuntil a base case is reached, which stops the recursion. • Each recursive call typically creates a newactivation recordon the call stack. • Recursionallows us to break down complex problems into smaller, self-similar subproblems. Advantages ofRecursion: • Elegant solutions: Recursioncan provide elegantandconcise solutions to problems that might be cumbersome with iterative approaches (using loops). • Self-similar problems: Recursionshines when dealing with problems that exhibitself-similarity, where the solution involves solving smaller versions ofthe originalproblem. • Improved readability: In some cases, recursive code canbe more readable and easier tounderstandcompared to iterative solutions, especiallyfor problems with inherentself-similarity.
  • 4.
    Real-world Applications of Recursion • Factorials:Calculating factorials of numbers is a classic example of recursion. • Tree traversals: Recursion is commonly used to traverse tree data structures (like binary trees) in a depth-firstmanner. • File system navigation: Recursioncan be used to navigate throughdirectory structureswithin a file system. • Maze solving algorithms: Several maze-solving algorithms, like backtracking,utilize recursionto explore differentpaths within the maze. • Divide and conquer algorithms: Many divide- and-conqueralgorithms, like merge sort and quick sort, rely on recursionto break down problems into smaller subproblems.
  • 5.
    Analyzing time complexity •Definition of AsymptoticNotation • Importancein AnalyzingAlgorithm Efficiency • Definition of Big O Notation • Analyzetime complexity of below code.
  • 6.
    Dynamic Programming • CoreIdea: Breaks down a complex problem into smaller, overlapping subproblems. • Solves subproblems: Computes the optimal solutions for each subproblem and stores them for reuse. • Bottom-up approach: Builds solutions for larger subproblems using previously solved smaller ones. • Suitable for: Optimization problems with overlapping subproblems (e.g., shortest path, edit distance).
  • 7.
    Solving some Interviewcoding problems • Generate all subsets , given an array of numbers • K sum problem • Check number of uni-value sub nodes in a tree.
  • 8.
    Greedy Algorithms • CoreIdea: Makes the locally optimal choice at each step with the hope of achieving a globally optimal solution. • Heuristic approach: Employs a set of rules to make seemingly optimal choices at each step. • Simpler implementation: Often easier to understand and implement compared to Dynamic Programming. • No guarantee of global optimality: The locally optimal choice at each step might not lead to the overall best solution.
  • 9.