THE MYSTERY OF ALGORITHMS : LEARN HOW ALGORITHMS WORK by FADOUL MOUBACHIR MADANI

THE MYSTERY OF ALGORITHMS : LEARN HOW ALGORITHMS WORK by FADOUL MOUBACHIR MADANI

Author:FADOUL, MOUBACHIR MADANI [FADOUL, MOUBACHIR MADANI]
Language: eng
Format: azw3
Published: 2020-05-13T16:00:00+00:00


1

George Washington

2

John Adams

3

Thomas Jefferson

4

James Madison

5

George Washington

For example, the element at index 2 in this table is John Adams. This table is considered as five separate entities, but as one table with five entries. An array is similar. The indices into an array are consecutive numbers that can start anywhere, but we will usually start them at 1 (Java, C, or C++, start arrays at 0).

Given the name of an array and an index into the array, we combine them with square brackets to indicate a particular array element. For example, we denote the i th element of an array A by A[i].

Arrays in computers have one other important characteristic: it takes equally long to access any element of an array. Once you give the computer an index i into an array, it can access the i th element as quickly as it can access the first element, regardless of the value of i.

Let’s see our first algorithm: searching an array for a particular value. if any, holds a given value. For any given array values, if we want to know the array entries. How do we search an array, let’s consider the array as a long bookshelf full of books, and imagine that you want to know where on the shelf you can find a book by the author “Moubachir Madani”. Now, the books on the shelf might be organized in some way, perhaps author alphabetically, alphabetically by title, or, by call number in a library. Or perhaps the bookshelf is like my bookshelf at home, messy and my books not organized in any particular way. If the books were not organized on the shelf, how do you find the book by Moubachir Madani? Here’s the algorithm I would follow. I would start at the right end of the shelf and look at the leftmost book. If it’s by Moubachir, I have located the book. Otherwise, I would look at the next book to the left, and if that book is by Moubachir, I have located the book. If not, I would keep going to the left, examining book after book, until either I find a book by Moubachir or I run off the left-hand end of the shelf, in which case I can conclude that the bookshelf does not contain any book by Moubachir Madani.

Here is how we can describe this searching problem in terms of computing. Let’s think of the books on the bookshelf as an array of books. The leftmost book is in position 1, the next book to its right is in position 2, and so on. If we have n books on the shelf, then the leftmost book is in position n. We want to find the position number on the shelf of any book by Moubachir Madani. As a general computing problem, we are given an array A (the entire shelf full of books to search through) of n elements (the individual books), and we want to find whether a value x (a book by Moubachir Madani) is present in the array A.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.