Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
PHP 7 Data Structures and Algorithms

You're reading from   PHP 7 Data Structures and Algorithms Implement linked lists, stacks, and queues using PHP

Arrow left icon
Product type Paperback
Published in May 2017
Publisher Packt
ISBN-13 9781786463890
Length 340 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Mizanur Rahman Mizanur Rahman
Author Profile Icon Mizanur Rahman
Mizanur Rahman
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Introduction to Data Structures and Algorithms FREE CHAPTER 2. Understanding PHP Arrays 3. Using Linked Lists 4. Constructing Stacks and Queues 5. Applying Recursive Algorithms - Recursion 6. Understanding and Implementing Trees 7. Using Sorting Algorithms 8. Exploring Search Options 9. Putting Graphs into Action 10. Understanding and Using Heaps 11. Solving Problems with Advanced Techniques 12. PHP Built-In Support for Data Structures and Algorithms 13. Functional Data Structures with PHP

Solving a problem - algorithmic approach

So far we have discussed different types of data structures and their usage. But, one thing we have to remember is that just putting data in a proper structure might not solve our problems. We need to find solutions to our problems using the help of data structures or, in other words, we are going to solve problems using data structures. We need algorithms to solve our problem.

An algorithm is a step by step process which defines the set of instructions to be executed in a certain order to get a desired output. In general, algorithms are not limited to any programming language or platform. They are independent of programming languages. An algorithm must have the following characteristics:

  • Input: An algorithm must have well-defined input. It can be 0 or more inputs.
  • Output: An algorithm must have well-defined output. It must match the desired output.
  • Precision: All steps are precisely defined.
  • Finiteness: An algorithm must stop after a certain number of steps. It should not run indefinitely.
  • Unambiguous: An algorithm should be clear and should not have any ambiguity in any of the steps.
  • Independent: An algorithm should be independent of any programming language or platforms.

Let us now create an algorithm. But in order to do that, we need a problem statement. So let us assume that we have a new shipment of books for our library. There are 1000 books and they are not sorted in any particular order. We need to find books as per the list and store them in their designated shelves. How do we find them from the pile of books?

Now, we can solve the problem in different ways. Each way has a different approach to find out a solution for the problem. We call these approaches algorithms. To keep the discussion short and precise, we are going to only consider two approaches to solve the problem. We know there are several other ways as well but for simplicity let us keep our discussion only for one algorithm.

We are going to store the books in a simple row so that we can see the book names. Now, we will pick a book name from the list and search from one end of the row to the other end till we find the book. So basically, we are going to follow a sequential search for each of the books. We will repeat these steps until we place all books in their designated places.

You have been reading a chapter from
PHP 7 Data Structures and Algorithms
Published in: May 2017
Publisher: Packt
ISBN-13: 9781786463890
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image