Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Hands-On Data Structures and Algorithms with Python – Third Edition
  • Table Of Contents Toc
  • Feedback & Rating feedback
Hands-On Data Structures and Algorithms with Python – Third Edition

Hands-On Data Structures and Algorithms with Python – Third Edition - Third Edition

By : Dr. Basant Agarwal
4.8 (26)
close
close
Hands-On Data Structures and Algorithms with Python – Third Edition

Hands-On Data Structures and Algorithms with Python – Third Edition

4.8 (26)
By: Dr. Basant Agarwal

Overview of this book

Choosing the right data structure is pivotal to optimizing the performance and scalability of applications. This new edition of Hands-On Data Structures and Algorithms with Python will expand your understanding of key structures, including stacks, queues, and lists, and also show you how to apply priority queues and heaps in applications. You’ll learn how to analyze and compare Python algorithms, and understand which algorithms should be used for a problem based on running time and computational complexity. You will also become confident organizing your code in a manageable, consistent, and scalable way, which will boost your productivity as a Python developer. By the end of this Python book, you’ll be able to manipulate the most important data structures and algorithms to more efficiently store, organize, and access data in your applications.
Table of Contents (17 chapters)
close
close
14
Other Books You May Enjoy
15
Index

Overview of data types and objects

Given a problem, we can plan to solve it by writing a computer program or software. The first step is to develop an algorithm, essentially a step-by-step set of instructions to be followed by a computer system, to solve the problem. An algorithm can be converted into computer software using any programming language. It is always desired that the computer software or program be as efficient and fast as possible; the performance or efficiency of the computer program also depends highly on how the data is stored in the memory of a computer, which is then going to be used in the algorithm.

The data to be used in an algorithm has to be stored in variables, which differ depending upon what kind of values are going to be stored in those variables. These are called data types: an integer variable can store only integer numbers, and a float variable can store real numbers, characters, and so on. The variables are containers that can store the values, and the values are the contents of different data types.

In most programming languages, variables and their data types must initially be declared, and then only that type of data can be statically stored in those variables. However, in Python, this is not the case. Python is a dynamically typed language; the data type of the variables is not required to be explicitly defined. The Python interpreter implicitly binds the value of the variable with its type at runtime. In Python, data types of the variable type can be checked using the function type(), which returns the type of variable passed. For example, if we enter the following code:

p = "Hello India"
q = 10
r = 10.2
print(type(p))
print(type(q))
print(type(r))
print(type(12+31j))

We will get an output like the following:

<class 'str'>
<class 'int'>
<class 'float'>
<class 'complex'>

The following example, demonstrates a variable that has a var float value, which is substituted for a string value:

var = 13.2
print(var)
 
print(type (var))
 
var = "Now the type is string"
print(type(var))

The output of the code is:

13.2
<class 'float'> 
<class 'str'>

In Python, every item of data is an object of a specific type. Consider the preceding example; here, when a variable var is assigned a value of 13.2, the interpreter initially creates a float object having a value of 13.2; a variable var then points to that object as shown in Figure 1.3:

Figure 1.3: Variable assignment

Python is an easy-to-learn object-oriented language, with a rich set of built-in data types. The principal built-in types are as follows and will be discussed in more detail in the following sections:

  • Numeric types: Integer (int), float, complex
  • Boolean types: bool
  • Sequence types: String (str), range, list, tuple
  • Mapping types: dictionary (dict)
  • Set types: set, frozenset

We will divide these into basic (numeric, Boolean, and sequence) and complex (mapping and set) data types. In subsequent sections, we will discuss them one by one in detail.

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Hands-On Data Structures and Algorithms with Python – Third Edition
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon