Book Image

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

By : Dr. Basant Agarwal
Book Image

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

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)
14
Other Books You May Enjoy
15
Index

Setting up a Python development environment

Once you have installed Python successfully for your respective OS, you can start this hands-on approach with data structures and algorithms. There are two popular methods to set up the development environment.

Setup via the command line

The first method to set up the Python executing environment is via the command line, after installation of the Python package on your respective operating system. It can be set up using the following steps.

  1. Open the terminal on Mac/Linux OS or Command Prompt on Windows.
  2. Execute the Python 3 command to start Python, or simply type py to start Python in the Windows Command Prompt.
  3. Commands can be executed on the terminal.
Text, letter  Description automatically generated

Figure 1.1: Screenshot of the command-line interface for Python

The User Interface for the command-line execution environment is shown in Figure 1.1.

Setup via Jupyter Notebook

The second method to run the Python program is through Jupyter Notebook, which is a browser-based interface where we can write the code. The User Interface of Jupyter Notebook is shown in Figure 1.2. The place where we can write the code is called a “cell.”

Figure 1.2: Screenshot of the Jupyter Notebook interface

Once Python is installed, on Windows, Jupyter Notebook can be easily installed and set up using a scientific Python distribution called Anaconda by taking the following steps.

  1. Download the Anaconda distribution from https://www.anaconda.com/products/individual.
  2. Install it according to the installation instructions.
  3. Once installed, on Windows, we can run the notebook by executing the jupyter notebook command at the Command Prompt. Alternatively, following installation, the Jupyter Notebook app can be searched for and run from the taskbar.
  4. On Linux/Mac operating systems, Jupyter Notebook can be installed using pip3 by running the following code in the terminal:
    pip3 install notebook
    
  5. After installation of Jupyter Notebook, we can run it by executing the following command at the Terminal:
    jupyter notebook
    

    On some systems, this command does not work, depending upon the operating system or system configuration. In that case, Jupyter Notebook should start by executing the following command on the terminal.

    python3 -m notebook
    

It is important to note that we will be using Jupyter Notebook to execute all the commands and programs throughout the book, but the code will also function in the command line if you’d prefer to use that.