Anyone Can Code: Algorithmic Thinking

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

As the second book in the Anyone Can Code series, Algorithmic Thinking focuses on the logic behind computer programming and software design. With a data-centred approach, it starts with simple algorithms that work on simple data items and advances to more complex ones covering data structures and classes. Examples are given in C/C++ and Python and use both plain text and graphics applications to illustrate the concepts in different languages and forms. With the advances in Artificial Intelligence and automated code generators, it is essential to learn about the logic of what a code needs to do, not just how to write the code. Anyone Can Code: Algorithmic Thinking is suitable for anyone who aims to improve their programming skills and go beyond the simple craft of programming, stepping into the world of algorithm design. This book is independent of the first one in the series but assumes some basic familiarity with programming such as language syntax. Most code examples in this book are either in Python or C/C++, as they are very common and typical languages programmers use these days. Python and C/C++ examples are tested on Python version 3.7 and Microsoft Visual Studio 2019, respectively. C and C++ are two different languages, but C++ is considered an object-oriented extension to C. While almost any C program can be compiled with a C++ compiler, C++ offers new ways of doing things such as input/output and memory management, and there are some behind-the-scenes or syntax differences in the way C and C++ compilers work. For example, struct keyword is used in both languages to define a structure. In C, your structure cannot include functions but in C++ it can. C++ structures are basically classes, but their members are public by default. Also, in C, struct is not a regular type, so if you have defined one, to define a variable you still need to use the keyword struct.

Author(s): Ali Arya
Publisher: Independently Published
Year: 2023

Language: English
Pages: 289

Signage and Numbering ................................................................................................... 11
Chapter 1: Introduction ........................................................................................................ 12
1.1. At the Restaurant ...................................................................................................... 12
1.2. Algorithms ................................................................................................................. 15
1.3. Programs ................................................................................................................... 17
1.4. Programming and Algorithmic Thinking .................................................................... 21
1.5. Modularization ........................................................................................................... 25
Highlights .......................................................................................................................... 28
Chapter 2: Algorithmic Thinking in Daily Life ....................................................................... 29
Overview .......................................................................................................................... 29
2.1. Sequential Execution ................................................................................................. 29
2.2. Selection .................................................................................................................... 31
2.3. Iteration ..................................................................................................................... 33
2.4. Combining Iteration and Selection ............................................................................ 36
2.5. Functions ................................................................................................................... 38
Highlights .......................................................................................................................... 41
Chapter 3: Algorithmic Thinking in Simple Programs........................................................... 42
Overview .......................................................................................................................... 42
3.1. Representing Algorithms ........................................................................................... 42
4
3.2. Getting Started .......................................................................................................... 45
3.2.1. Iteration with Definite Loops ............................................................................... 45
3.2.2. Indefinite Loops .................................................................................................. 47
3.2. Search Algorithms ..................................................................................................... 49
3.2.1. Linear Search ..................................................................................................... 49
3.2.2. Binary Search ..................................................................................................... 50
3.3. Sorting Data .............................................................................................................. 52
3.4. Notes on Problem-Solving ......................................................................................... 55
Highlights .......................................................................................................................... 57
Chapter 4: Data-Centred and Modular Algorithm Design .................................................... 58
Overview .......................................................................................................................... 58
4.1. Simple Games ........................................................................................................... 58
4.1.1. Simple Text-based Games ................................................................................. 59
4.1.2. Simple Graphics Game ....................................................................................... 61
4.2. Data-Centred Algorithm Design ................................................................................ 70
4.2.1. Attacking Enemy ................................................................................................. 71
4.2.2. Collision Detection .............................................................................................. 75
4.3. Nested Loops ............................................................................................................ 76
4.4. Modularization ........................................................................................................... 80
4.5. Algorithmic Thinking Toolbox .................................................................................... 88
Highlights .......................................................................................................................... 92
Chapter 5: Data Structures .................................................................................................. 93
Overview .......................................................................................................................... 93
5.1. Arrays ........................................................................................................................ 94
5.1.1. Array Indexing ..................................................................................................... 95
5.1.2. Array Matching .................................................................................................... 99
5
5.1.3. Array Shifting .................................................................................................... 101
5.2. Records ................................................................................................................... 106
5.2.1. Encapsulation ................................................................................................... 107
5.2.2. Spawn ............................................................................................................... 110
5.2.3. Tables ............................................................................................................... 113
5.3. Queues .................................................................................................................... 115
5.3.1. Simple Queue Implementation ......................................................................... 116
5.3.2. Transaction Processing .................................................................................... 120
5.4. Stacks ...................................................................................................................... 124
5.4.1. Undo ................................................................................................................. 127
5.4.2. Tower of Hanoi ................................................................................................. 129
5.5. Linked Lists ............................................................................................................. 132
5.5.1. References and Pointers .................................................................................. 134
5.5.2. Simple Linked List ............................................................................................. 136
5.5.3. Game Player List .............................................................................................. 144
5.5.4. Trees and Graphs ............................................................................................. 149
5.6. Simple Game: Revisited .......................................................................................... 150
Highlights ........................................................................................................................ 161
Chapter 6: Objects and Classes ........................................................................................ 163
Overview ........................................................................................................................ 163
6.1. Encapsulation: Revisited ......................................................................................... 163
Note on Multiple Files .............................................................................................. 168
6.1.1 Simple Object-Oriented Game ........................................................................... 171
6.1.2. Initializing Data ................................................................................................. 176
6.1.3. Using and Changing Data ................................................................................. 187
Scrolling Screen and Coordinate Systems .............................................................. 188
6
Physics of Jump and Fall ........................................................................................ 195
6.1.4. Controlling the Access to Class Members ........................................................ 201
6.1.5. Sharing Data between Instances of a Class ..................................................... 214
6.1.6. Using Functions ................................................................................................ 218
6.2. Inheritance ............................................................................................................... 222
6.2.1. Class Hierarchies .............................................................................................. 232
New Class vs. a Type Data ..................................................................................... 233
Object Cross-referencing ........................................................................................ 235
6.2.2. Multiple Inheritance ........................................................................................... 248
Classes with Selected Features .............................................................................. 253
Inheritance Ambiguity .............................................................................................. 259
6.3. Polymorphism .......................................................................................................... 262
6.3.1. Virtual Functions and Abstract Classes ............................................................ 265
6.3.2. Rendering Multiple Types of GameObjects ...................................................... 268
Visual Effects and Image Filters .............................................................................. 272
6.4. Object-Oriented Algorithm Design ........................................................................... 276
Highlights ........................................................................................................................ 277
7. Where do we go from here? .......................................................................................... 279
Appendix A. C/C++ Review ............................................................................................... 283
A.1. Installation ............................................................................................................... 283
A.2. Basic Programming ................................................................................................. 283
A.3. Object-Oriented Programming ................................................................................ 285
A.4. Graphics .................................................................................................................. 285
Appendix B. Python Review ............................................................................................... 287
B.1. Installation ............................................................................................................... 287
B.2. Basic Programming ................................................................................................. 287
7
B.3. Object-Oriented Programming ................................................................................ 288
B.4. Graphics .................................................................................................................. 288