Beginning Java Data Structures and Algorithms
Sharpen your problem solving skills by learning core computer science concepts in a pain-free manner
James Cutajar
- 202 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Beginning Java Data Structures and Algorithms
Sharpen your problem solving skills by learning core computer science concepts in a pain-free manner
James Cutajar
About This Book
Though your application serves its purpose, it might not be a high performer. Learn techniques to accurately predict code efficiency, easily dismiss inefficient solutions, and improve the performance of your application.
Key Features
- Explains in detail different algorithms and data structures with sample problems and Java implementations where appropriate
- Includes interesting tips and tricks that enable you to efficiently use algorithms and data structures
- Covers over 20 topics using 15 practical activities and exercises
Book Description
Learning about data structures and algorithms gives you a better insight on how to solve common programming problems. Most of the problems faced everyday by programmers have been solved, tried, and tested. By knowing how these solutions work, you can ensure that you choose the right tool when you face these problems.
This book teaches you tools that you can use to build efficient applications. It starts with an introduction to algorithms and big O notation, later explains bubble, merge, quicksort, and other popular programming patterns. You'll also learn about data structures such as binary trees, hash tables, and graphs. The book progresses to advanced concepts, such as algorithm design paradigms and graph theory. By the end of the book, you will know how to correctly implement common algorithms and data structures within your applications.
What you will learn
- Understand some of the fundamental concepts behind key algorithms
- Express space and time complexities using Big O notation.
- Correctly implement classic sorting algorithms such as merge and quicksort
- Correctly implement basic and complex data structures
- Learn about different algorithm design paradigms, such as greedy, divide and conquer, and dynamic programming
- Apply powerful string matching techniques and optimize your application logic
- Master graph representations and learn about different graph algorithms
Who this book is for
If you want to better understand common data structures and algorithms by following code examples in Java and improve your application efficiency, then this is the book for you. It helps to have basic knowledge of Java, mathematics and object-oriented programming techniques.
Frequently asked questions
Information
Sorting Algorithms and Fundamental Data Structures
- Describe how bubble sorting works
- Implement faster sorting with quick sort
- Characterize merge sorting
- Build a linked list data structure
- Implement queues
- Describe the stack data structure
Introducing Bubble Sorting
Understanding Bubble Sorting
bubbleSort(array)
n = length(array)
for (k = 1 until n)
for (j = 0 until -1)
if(array[j] > array[j + 1])
swap(array, j, j + 1)
The swap function in the Snippet 2.1 switches the values of the two array pointers j and j+1 using a temporary variable.
Implementing Bubble Sort
- Apply the pseudocode shown in Snippet 2.1 in Java. Create a class and a method, accepting an array to sort as follows:
public void sort(int[] numbers)
- The slightly tricky part of this algorithm is the swapping logic. This is done by assigning one of the elements to be swapped to a temporary variable, as shown in Snippet 2.2:
public void sort(int[] numbers) {
for (int i = 1; i < numbers.length; i++) {
for (int j = 0; j < numbers.length - 1; j++) {
if (numbers[j] > numbers[j + 1]) {
int temp = numbers[j];
numbers[j] = numbers[j + 1];
numbers[j + 1] = temp;
}
}
}
}
Go to https://goo.gl/7atHVR to access the code.
Improving Bubble Sorting
public void sortImprovement1(int[] numbers) {
for (int i = 1; i < numbers.length; i++) {
for (int j = 0; j < numbers.length - i; j++) {
if (numbers[j] > numbers[j + 1]) {
swap(numbers, j, j + 1);
}
}
}
}
Go to https://goo.gl/vj267K to access the code.