-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Applied Computational Thinking with Python
By :
In computer science, data types and structures are two distinct things:
Let's look at these in more detail in the following sections.
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:
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.We'll look at data structures in the next section.
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 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.