Book Image

Applied Computational Thinking with Python

By : Sofía De Jesús, Dayrene Martinez
Book Image

Applied Computational Thinking with Python

By: Sofía De Jesús, Dayrene Martinez

Overview of this book

Computational thinking helps you to develop logical processing and algorithmic thinking while solving real-world problems across a wide range of domains. It's an essential skill that you should possess to keep ahead of the curve in this modern era of information technology. Developers can apply their knowledge of computational thinking to solve problems in multiple areas, including economics, mathematics, and artificial intelligence. This book begins by helping you get to grips with decomposition, pattern recognition, pattern generalization and abstraction, and algorithm design, along with teaching you how to apply these elements practically while designing solutions for challenging problems. You’ll then learn about various techniques involved in problem analysis, logical reasoning, algorithm design, clusters and classification, data analysis, and modeling, and understand how computational thinking elements can be used together with these aspects to design solutions. Toward the end, you will discover how to identify pitfalls in the solution design process and how to choose the right functionalities to create the best possible algorithmic solutions. By the end of this algorithm book, you will have gained the confidence to successfully apply computational thinking techniques to software development.
Table of Contents (21 chapters)
1
Section 1: Introduction to Computational Thinking
9
Section 2:Applying Python and Computational Thinking
14
Section 3:Data Processing, Analysis, and Applications Using Computational Thinking and Python
20
Other Books You May Enjoy

Learning about data types and structures

In computer science, data types and structures are two distinct things:

  • A data type is a basic classification. Some data types include integers, float, and strings.
  • Data structures use multiple types of data types. They can organize the information into the memory and determine how we access the information.

Let's look at these in more detail in the following sections.

Data types

As mentioned, data types are basic classifications. They are variables that are used throughout a program and can only exist with one classification. There are different classes of data type. We will focus on primitive and abstract data types for now, but we will revisit this topic as we move through problems and design solutions.

Primitive data types include byte, short, int, long, float, double, Boolean, and char:

  • A byte can store numbers from -128 to 127. While these numbers can be stored as integers, or int, a byte uses less storage, so if we know the number is between those values, we can use a byte data type instead.
  • A short is a number between -32,768 and 32,767.
  • An integer, int, is used to store numbers between -2,147,483,648 and 2,147,483,647.
  • Long is used to store numbers from -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807.
  • A float allows us to save a decimal number.
  • Decimal numbers can also be saved as double, which has more precision than a float.
  • Boolean values are data types that are either True or False. So, a variable can be saved such that when its value is printed, the result will be saved as true or false.
  • Char is used to save a variable as a single character.

We'll look at data structures in the next section.

Data structures

As mentioned under the Coding theory section earlier in this chapter, data structures are used to collect and organize data in the most efficient and effective way possible. Data structures can be primitive, such as the built-in data structures in software, or abstract. Primitive data structures can also be defined using programming languages, but they are pre-defined. Some of the primitive data structures include the data types listed in the previous section, such as chars and Boolean structures.

Abstract data types (ADTs) include the information for the structure and design of data types. Abstract data structures include arrays and two-dimensional arrays, stacks, trees and binary trees, linked lists, queues, and more, as mentioned in the Coding theory section earlier in this chapter. Lists can contain multiple instances of the same data values. These lists are countable, so we can find how many elements are in the list, reorder them, remove items, add items, and so on. Lists are widely used as linked lists, arrays, or dynamic arrays:

  • A linked list means that each data element in the list is connected, or points, to the next one, regardless of where they are stored within the memory.
  • An array is ordered. The elements are read in order to be able to make sense. Think of an array as reading this sentence. You don't read the sentence as "array an think reading as this of sentence." We read the sentence in order, from left to right, not in a jumbled order.
  • Dynamic arrays can be resized, which is important when choosing a data type.

A stack ADT is a collection of elements and has two operations – push and pop. A push is used to add an element to the collection while a pop removes the most recent element.

A queue ADT is a linear data structure. As with a stack, we can add or remove elements. However, in a queue ADT, the point of deletion and the point of insertion are done at two different ends.

As mentioned before, the data structures are concrete implementations of data types. How we add or remove elements from a collection, for example, is the data structure.

This can all be slightly confusing, but we will be learning more about them through examples in later chapters. For now, understanding the definitions and simple examples is enough.