PHP 7 Data Structures and Algorithms
eBook - ePub

PHP 7 Data Structures and Algorithms

Mizanur Rahman

Condividi libro
  1. 300 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

PHP 7 Data Structures and Algorithms

Mizanur Rahman

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

Increase your productivity by implementing data structuresAbout This Book• Gain a complete understanding of data structures using a simple approach• Analyze algorithms and learn when you should apply each solution• Explore the true potential of functional data structuresWho This Book Is ForThis book is for those who want to learn data structures and algorithms with PHP for better control over application-solution, efficiency, and optimization.A basic understanding of PHP data types, control structures, and other basic features is requiredWhat You Will Learn• Gain a better understanding of PHP arrays as a basic data structure and their hidden power• Grasp how to analyze algorithms• Implement linked lists, double linked lists, stack, queues, and priority queues using PHP• Work with sorting, searching, and recursive algorithms• Make use of greedy, dynamic, and pattern matching algorithms• Implement tree, heaps, and graph algorithms• Apply PHP functional data structures and built-in data structures and algorithmsIn DetailPHP has always been the the go-to language for web based application development, but there are materials and resources you can refer to to see how it works. Data structures and algorithms help you to code and execute them effectively, cutting down on processing time significantly.If you want to explore data structures and algorithms in a practical way with real-life projects, then this book is for you.The book begins by introducing you to data structures and algorithms and how to solve a problem from beginning to end using them. Once you are well aware of the basics, it covers the core aspects like arrays, listed lists, stacks and queues. It will take you through several methods of finding efficient algorithms and show you which ones you should implement in each scenario. In addition to this, you will explore the possibilities of functional data structures using PHP and go through advanced algorithms and graphs as well as dynamic programming.By the end, you will be confident enough to tackle both basic and advanced data structures, understand how they work, and know when to use them in your day-to-day workStyle and approachAn easy-to-follow guide full of examples of implementation of data structures and real world examples to solve the problems faced. Each topic is first explained in general terms and then implemented using step by step explanation so that developers can understand each part of the discussion without any problem.

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
PHP 7 Data Structures and Algorithms è disponibile online in formato PDF/ePub?
Sì, puoi accedere a PHP 7 Data Structures and Algorithms di Mizanur Rahman in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Informatik e Programmierung in PHP. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
2017
ISBN
9781786463579
Edizione
1
Argomento
Informatik

Solving Problems with Advanced Techniques

We have explored different data structures and algorithms so far in this book. We are yet to explore some of the most exciting areas of algorithms. There are many efficient ways of doing things in computer programming. We will focus on some of the key advanced techniques and concepts in this chapter. These topics are so important that a separate book could be written about them. However, we will keep our focus on the very basic understanding of these advanced topics. When we say advanced topics, we are referring to memoization, dynamic programming, greedy algorithm, backtracking, puzzle solving, machine learning, and so on. Let's learn some new and exciting topics in the following sections.

Memoization

Memoization is an optimization technique where we the store results of previous expensive operations and use them without repeating the operation. It helps us speed up the solution significantly. When we have problems where we can have repetitive sub problems, we can easily apply this technique to store those results and use them later on without repeating the steps. Since PHP has a great support for associative arrays and dynamic array properties, we can cache the results without any problems. One thing we have to remember is that though we are saving time by caching the results, we will require more memory to store these results in the cache. So, we have to make the trade-off between space and memory. Now, let's revisit Chapter 5, Applying Recursive Algorithms - Recursion, for our recursive example of generating Fibonacci numbers. We will just modify that function with a counter to know how many times the function is called and the running time of the function to get the thirtieth Fibonacci number. Here is the code for this:
$start Time = microtime(); 
$count = 0;

function fibonacci(int $n): int {
global $count;
$count++;
if ($n == 0) {
return 1;
} else if ($n == 1) {
return 1;
} else {
return fibonacci($n - 1) + fibonacci($n - 2);
}
}

echo fibonacci(30) . "\n";
echo "Function called: " . $count . "\n";
$endTime = microtime();
echo "time =" . ($endTime - $startTime) . "\n";
This will have the following output in the command line. Note that timing and results may vary from one system to the other or from one version of PHP to the other. It completely depends on the where the program is running:
1346269
Function called: 2692537
time =0.531349
The first number 1346269 is the thirtieth Fibonacci number, and the next line shows that the fibonacci function was called 2692537 times during the generation of the thirtieth number. The whole process took 0.5 seconds (we are using the microtime function of PHP). If we were generating the fiftieth Fibonacci number, the function call count would be more than 40 billion times. That is one big number. However, we know from our Fibonacci formula that when we are calculating n. We are doing it through n-1 and n-2; those are already calculated in the previous steps. So, we are repeating the steps, and hence, it is costing us time and efficiency. Now, let's store the Fibonacci results in an indexed array, and we will check whether the Fibonacci number we are looking for is already calculated or not. If it is calculated, we will use it; otherwise, we will calculate that and store the result. Here is the modified code for generating Fibonacci numbers using the same recursive process, but with help of memorization:
$startTime = microtime(); 
$fibCache = [];
$count = 0;

function fibonacciMemoized(int $n): int {
global $fibCache;
global $count;
$count++;
if ($n == 0 ...

Indice dei contenuti