This book provides complete coverage of reactive and functional data structures
Based on the latest version of Java 9, this book illustrates the impact of new features on data structures
Gain exposure to important concepts such as Big-O Notation and Dynamic Programming
Book Description
Java 9 Data Structures and Algorithms covers classical, functional, and reactive data structures, giving you the ability to understand computational complexity, solve problems, and write efficient code. This book is based on the Zero Bug Bounce milestone of Java 9.
We start off with the basics of algorithms and data structures, helping you understand the fundamentals and measure complexity. From here, we introduce you to concepts such as arrays, linked lists, as well as abstract data types such as stacks and queues. Next, we’ll take you through the basics of functional programming while making sure you get used to thinking recursively.
We provide plenty of examples along the way to help you understand each concept. You will get the also get a clear picture of reactive programming, binary searches, sorting, search trees, undirected graphs, and a whole lot more!
What you will learn
Understand the fundamentals of algorithms, data structures, and measurement of complexity
Find out what general purpose data structures are, including arrays, linked lists, double ended linked lists, and circular lists
Get a grasp on the basics of abstract data types—stack, queue, and double ended queue
See how to use recursive functions and immutability while understanding and in terms of recursion
Handle reactive programming and its related data structures
Use binary search, sorting, and efficient sorting—quicksort and merge sort
Work with the important concept of trees and list all nodes of the tree, traversal of tree, search trees, and balanced search trees
Apply advanced general purpose data structures, priority queue-based sorting, and random access immutable linked lists
Gain a better understanding of the concept of graphs, directed and undirected graphs, undirected trees, and much more
Pages in Print ...2015-6-17 10:20 - Nicolle - Forum
DataStructures and Algorithms with JavaScript
0 个回复 - 800 次查看As an experienced JavaScript developer moving to server-side programming, you need to implement classic data structures and algorithms associated with conventional object-oriented languages like C# an ...2015-6-28 09:27 - nelsoncwlee - 量化投资
Inserting an element at the beginning of a list is very similar to appending it at the end. The only difference is that you need to update the first reference instead of the last reference:
Insertion at the beginning is very similar to that of a singly linked list, except that we must now update the next node's reference for its previous node. The node being inserted does not have a previous node in this case, so nothing needs to be done:
The problem with an array-based implementation is that since arrays are fixed in size, the stacks cannot grow beyond a fixed-size. To resolve this, we have to do what we did to fix the same problem for an array, that is, use a linked list instead. We start such an implementation with the following bare bone class. The linked list will store the values. Instead of assigning a new linked list to it, we do so using an overridable method getNewLinkedList(). This will be useful in the class that extends from this one:
public class StackImplLinkedList<E> implements Stack<E> {
protected LinkedList<E> list = getNewLinkedList();
As I have already pointed out, recursive algorithms are a different way of thinking about solving a problem. For example, say our problem is to write a program that, given a positive integer n, returns the sum of numbers from zero to n. The known imperative way of writing it is simple:
public int sum_upto(int n){
int sum=0;
for(int i=0;i<=n;i++){
sum+=i;
}
return sum;
}
The following would be the functional version of the problem:
public int sum_upto_functional(int n){
return n==0?0:n+sum_upto_functional(n-1);
}
That's it–just a one-liner! This is probably nothing new to Java programmers, as they do understand recursive functions.
So, what happens if we have a functional interface? We can provide an inline implementation of it using a cool syntax called lambda, as follows:
SampleFunctionalInterface sfi = (x)->x+1;
int y = sfi.modify(1);
Take note of the parentheses and the arrow sign. The parentheses contain all the parameters. The types of parameters are not specified because they are already specified in the interface method. There can be zero or more parameters.
There are two kinds of lambda syntax–one that has an expression as the body and one that has one or more steps as the body. These lambdas look a bit different from each other. A lambda that is implemented as a one liner looks like the one we just saw. This is called an expression syntax. The expression syntax can be used if the lambda expression is a one liner. For multi-line code, we use the block syntax as shown below:
Thread t = new Thread(()->{for(int i=0;i<500;i++) System.out.println(i);});
One can use block syntax for functions that return a value as well, especially when using multiple lines of code. In that case, one just needs to use a return statement to return a value.
The forEach() method on a linked list would do something for each element of the list. This something would be passed as a lambda. For this purpose, we will first create a functional interface that consumes one parameter but does not return anything:
@FunctionalInterface
public interface OneArgumentStatement<E> {
void doSomething(E argument);
}
With this interface available, we will define the forEach() method for a list, as follows:
public class LinkedList<E> {
…
public static class EmptyList<E> extends LinkedList<E>{
…
@Override
public void forEach(OneArgumentStatement<E> processor) {}
}
…
public void forEach(OneArgumentStatement<E> processor){