• Complain

James Cutajar [James Cutajar] - Beginning Java Data Structures and Algorithms

Here you can read online James Cutajar [James Cutajar] - Beginning Java Data Structures and Algorithms full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2018, publisher: Packt Publishing, genre: Home and family. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

James Cutajar [James Cutajar] Beginning Java Data Structures and Algorithms

Beginning Java Data Structures and Algorithms: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Beginning Java Data Structures and Algorithms" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

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. Youll 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.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

James Cutajar [James Cutajar]: author's other books


Who wrote Beginning Java Data Structures and Algorithms? Find out the surname, the name of the author of the book and a list of all author's works by series.

Beginning Java Data Structures and Algorithms — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Beginning Java Data Structures and Algorithms" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Activity: Writing an Algorithm to Convert Numbers from Octal To Decimal

Scenario

In aviation, the aircraft's transponders transmit a code so that they can identify one another. This code uses the octal system, a number system which has a base of 8. We have been asked to write a method to convert octal numbers into decimals. For example, the octal number 17 is represented as 15 in the decimal system.

Aim

To be able to adapt the algorithm shown in the previous section to be used in a different scenario.

Prerequisites

  • Ensure that you have a class available on the following path:

https://github.com/TrainingByPackt/Data-Structures-and-Algorithms-in-Java/blob/master/src/main/java/com/packt/datastructuresandalg/lesson1/activity/octaltodecimal/OctalToDecimal.java

  • You will find the following method that needs implementing:
public int convertToDecimal (String octal)
  • If you have your project set up, you can run the unit test for this activity by running the following command:
gradlew test --tests com.packt.datastructuresandalg.
lesson1.activity.octaltodecimal*

Steps for Completion

  1. The algorithms shown in Snippet 1.1 the preceding snippets of code can be adapted to work with octal numbers instead of binary.
  2. Change the base from two to eight. This can be done by changing the conversion multiplier variable in Snippet 1.1.
  3. Parse the digit being processed to convert it into an integer. This integer can then be multiplied by the conversion variable or result of the power function.

In this first section, we introduced the idea of algorithms by working on a simple example. It's important to note that for every problem multiple solutions exist. Choosing the right algorithm to solve your problem will depend on several metrics, such as performance and memory requirements.

Calculating Shortest Paths

The shortest path is a path between two vertices so that the sum of the weights of the edges that constitute the path is minimized. The shortest path problem has many applications in the real world, from finding directions on mapping applications to minimizing the moves to solve a puzzle.

In this section, we shall look at two different strategies for computing shortest paths: one that finds the shortest paths from a single source to every other vertex in the graph, and another that finds shortest paths between all pairs of vertices in a graph.

Hash Tables and Binary Search Trees

In the preceding chapter, we introduced the concept of data structures by looking at arrays, linked lists, queues, and stacks. In this chapter, we will use some of these primitive structures to build more complex ones. We'll start the chapter by looking at hash tables, which are useful data structures for fast key-value lookup. In the second part of the chapter, we will learn about a more complex data structure that supports range queries, called binary trees.

By the end of this chapter, you will be able to:

  • Describe how hash tables work
  • Implement two main techniques to deal with hash collisions
  • Characterize different hashing choices
  • Explain the terminology, structure, and operations of binary trees
  • Demonstrate various tree traversal techniques
  • Define balanced binary search trees
Adjacency List Representation

The adjacency list representation of a graph consists of an array of |V| lists, one for each vertex in V . For each vertex u in V , there's a list containing all vertices v so that there is an edge connecting u and v in E . Figure 6.3 shows the adjacency list representation of the directed graph in Figure 6.1:

Figure 63 Adjacency list representation of the directed graph in Figure 61 - photo 1

Figure 6.3: Adjacency list representation of the directed graph in Figure 6.1

For undirected graphs, we follow a similar strategy and build the adjacency list as if it were a directed graph with two edges between each pair of vertices u and v , which are (u, v) and (v, u) .

Figure 6.4 shows the adjacency list representation of the undirected graph in Figure 6.2:

Figure 64 Adjacency list representation of the undirected graph in Figure 62 - photo 2

Figure 6.4: Adjacency list representation of the undirected graph in Figure 6.2

If G is a directed graph, the sum of the lengths of all the adjacency lists is |E|, as each edge constitutes a single node in one of the adjacency lists.

If G is an undirected graph, the sum of the lengths of all the adjacency lists is 2*|E|, since each edge (u, v) appears twice, that is, once in u's and once in v's adjacency list.

For both types of graphs, the adjacency list representation has the property of requiring an amount of memory equal to O(V + E).

The following code snippet shows how to create a graph using the adjacency list representation in Java:

public class AdjacencyListGraph {
ArrayList[] adj;
public AdjacencyListGraph(int nodes) {
this.adj = new ArrayList[nodes];
for (int i = 0; i < nodes; i++)
this.adj[i] = new ArrayList<>();
}
public void addEdge(int u, int v) {
adj[u].add(v);
}
}
Snippet 6.1: Implementation of an adjacency list representation of a graph. Source class name: Adjacencylistgraph

Go to https://goo.gl/Jrb2jH to access this code.

It is common for one to have weighted graphs, that is, graphs in which each edge has an associated weight. The adjacency list representation is robust enough to support different graph variants, since we can store different edge representations in the adjacency lists.


We can store different edge representations in adjacency lists because we store the edges themselves, thereby allowing customizable representations.
Logarithmic Complexity

Logarithmic complexity algorithms are very fast, and their performance hardly degrades as you increase the problem size. These types of algorithm scale really well. Code that has a runtime complexity of O(log n) is usually recognizable since it systematically divides the input in several steps. Common examples that operate in logarithmic times are database indexes and binary trees. If we want to find an item in a list, we can do it much more efficiently if the input list is sorted in some specific order. We can then use this ordering by jumping to specific positions of our list and skipping over a number of elements.

Snippet 1.7 shows an implementation of the binary search in Java. The method uses three array pointersa start, an end, and a midpoint. The algorithm starts by checking the middle element in the array. If the element is not found and is less than the value at the middle, we choose to search in the lower half; otherwise, we choose the upper half. Figure 1.3 shows the steps involved when doing a binary search. The code snippet is as follows:

public boolean binarySearch(int x, int[] sortedNumbers) {
int end = sortedNumbers.length - 1;
int start = 0;
while (start <= end) {
int mid = (end - start) / 2 + start;
if (sortedNumbers[mid] == x) return true;
else if (sortedNumbers[mid] > x) end = mid - 1;
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Beginning Java Data Structures and Algorithms»

Look at similar books to Beginning Java Data Structures and Algorithms. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Beginning Java Data Structures and Algorithms»

Discussion, reviews of the book Beginning Java Data Structures and Algorithms and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.