-
Book Overview & Buying
-
Table Of Contents
Applied Computational Thinking with Python - Second Edition
By :
In computer science, data types and structures are two distinct things:
We’ll look at these in more detail in the following sections.
As mentioned previously, 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 types. We will focus on primitive and abstract data types for now, but we will revisit this topic as we consider problems and design solutions.
Primitive data types include byte, short, int, long, float, double, Boolean, and char:
True or False. So, a variable can be saved so that when its value is printed, the result will be saved as true or false.As mentioned in the Coding theory section earlier, data structures are used to collect and organize data efficiently and effectively. 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 predefined. Some primitive data structures include the data types listed in the previous section, such as chars and Boolean structures.
Abstract data types (ADTs) include information that can help structure and design 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 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 previously, 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 learn more about them throughout this book. For now, understanding the definitions and simple examples is enough.