Fundamental Algorithms in Java
Fundamental Algorithms in Java
Algorithms in Java
Sorting, Searching, Greedy Algorithms, and
Dynamic Programming
Content
▪ Definition
– set of instructions to solve a problem or
perform a task.
▪ Why are algorithms important?
– efficient problem solving
– optimized code
– scalability
– better performance
Common Algorithm Categories
▪ Sorting
▪ Searching
▪ Greedy Algorithms
▪ Dynamic Programming
Sorting
Popular Sorting Algorithms
Bubble Sort
• Time Complexity:
• O(n²)
• Time Complexity:
• O(1)
Bubble Sort Example
Quicksort
• What is Quicksort?
• is a divide-and-conquer algorithm. It picks a pivot element and partitions the array
around the pivot. Recursively sorts the subarrays.
• Time Complexity
• O(n log n) on average, O(n²) in the worst case
• Space Complexity
• O(log n)
Quicksort Example
Merge Sort
• Time Complexity
• O(n log n)
• Space Complexity
• O(n)
Merge Sort Example
Searching
Popular Searching Algorithms
Linear Search
• Time Complexity
•O(n)
Linear Search Example
Add a Slide Title - 4
Add a Slide Title - 5