# How to start with Data Structures and Algorithms

## What platforms to use and resources, How to learn with AI Probably!

Learning **data structures and algorithms** allow us to write efficient ๐ and optimized computer programs. It is also the first step towards a career as a software engineer ๐จโ๐ป or any core software-related job in general. Data structures and algorithms are also important when it comes to ๐ค ** Artificial Intelligence ** and ** Machine Learning ** as we need to know which algorithm to use in order to create dynamic ๐ and effective machine learning models.

**What are Data Structures?**

๐ก **Data structures** provide a means to efficiently manage **large amounts** ๐ฎ of data for various scenarios, such as large databases and internet indexing services. Usually, efficient data structures are essential in designing dynamic algorithms. Data structures are used to organize the storage and retrieval of information stored in both main memory and secondary memory. Data structures have a broad and diverse scope ๐คฏ of usage across **Computer Science** and **Software Engineering**. Data structures have found their use in almost every program or software system that has been developed. ๐ญ Hence as developers, one must have good knowledge about data structures. On the other hand, an algorithm is a collection of steps to solve a particular problem.

**What are Algorithms?**

๐ก An algorithm is a step-by-step method that defines instructions to be executed in a specific order to get the desired output. Algorithms are self-sufficient and remain independent from underlying languages, i.e. the same algorithm can be performed in more than one programming language ๐จโ๐ป.

source: 123RF

From the data structure point of view, given below are some significant categories of algorithms โ

- ๐
**Sort:**Sorting items in a specific order. - ๐
**Search:**Searching an item in a data structure. - ๐
**Update:**Updating an existing item in a data structure. - ๐
**Insert:**Inserting an item in a data structure. - ๐
**Delete:**Deleting an existing item from a data structure.

**Characteristics of an Algorithm**

Not all styles or functions in a program can be called an algorithm. An algorithm should have the following features โ

**Unambiguous:**The algorithm should be straightforward. Each of its phases or steps and inputs/outputs should be clear and lead to only one meaning.**Finiteness:**An algorithm must terminate after a finite number of steps.**Input:**An algorithm should have 0 or more well-defined inputs.**Output**: An algorithm should have one or more well-defined outputs and should match the desired result.**Independent:**An algorithm should have step-by-step commands, which should be independent of any programming code.**Feasibility:**Algorithms must be feasible with the available resources.

Given the breadth of the topics in data structures and algorithms, it is often a **daunting task** ๐ฅบ for many to decide how and from where to start studying DSA.

**So, how to start with learning Data Structures and Algorithms? **

Knowing that data structures and algorithms are the base for every program, let us learn how we can start with our knowledge journey of data structures and algorithms.

โจThe first and foremost step is to start with learning the basic data structures such as **Arrays, Linked Lists, Stacks, and Queues**. Then, begin with **searching and sorting algorithms** such as Binary Search and Bubble Sort as they are the most prominent types of algorithms which will be used in the coming advanced topics in data structures and algorithms. Here is a roadmap on which topics to learn:

### Arrays and Lists

An array is a structure of **fixed size**, which can hold items ๐๏ธ of the same data type. It can be an array of integers, floating-point numbers, strings, or even an array of arrays (for example, 2-dimensional arrays). **Random access** is possible since arrays are indexed, meaning that an element in an array can be accessed by using a specific index for each element. As usual, the index starts from 0.

*Applications of arrays*

They are used as the building blocks to build other data structures such as array lists, heaps, hash tables, vectors, and matrices.

Used for different sorting algorithms such as insertion sort, quick sort, bubble sort, and merge sort.

### Linked Lists

A linked list is a **consecutive structure** consisting of a sequence of linear order items linked to each other. Linked lists provide a flexible and straightforward illustration of **dynamic sets**. Hence, you have to obtain data sequentially, and random access is not possible. Elements contained in a linked list are called **nodes**. Every node contains a key and a pointer to its successor node, known as next โญ๏ธ, and the attribute defined as "head" points to the first element of the linked list. The last element of a linked list is known as the tail.

*Applications of linked lists*

They are used for implementing stack and queue.

They are used in switching between programs using Alt + Tab (implemented using Circular Linked List).

### Stack and Queue

A stack ๐ is a **LIFO** (Last In First Out โ the element placed at last can be accessed at first) structure, commonly found in many programming languages. This structure is named as โstackโ because it resembles a real-world stack โ a **stack of plates.**

A queue ๐ง๐พโ๐คโ๐ง๐ผ๐ง๐พโ๐คโ๐ง๐ผ๐ง๐พโ๐คโ๐ง๐ผ is a **FIFO** (First In First Out โ the element placed at first can be accessed at first) structure commonly found in many programming languages. This structure is called โqueueโ because it resembles a real-world queue โ **people waiting in a queue.
**

*Applications of stacks*

Used for expression evaluation (e.g., the shunting-yard algorithm for parsing and evaluating mathematical ๐งฎ expressions).

Used to implement function calls in recursion programming.

*Applications of queues*

Used to handle threads in multithreading.

It is used to implement queuing systems (e.g., priority queues).

### Hash Tables

๐A Hash Table is a data structure that contains values that have keys ๐ associated with them. It is very effective in searching and inserting, regardless of the size of the data. Moreover, it supports item lookup efficiently if we know the key related to the value.

*Applications of hash tables*

They are used to implement database ๐๏ธ indexes.

Used to implement associative arrays.

Used to implement the โsetโ data structure.

### Trees

A tree ๐ณ is a **hierarchical structure** where data is arranged hierarchically and are linked together. This structure is distinct from a linked list, whereas items are connected in a linear order in a linked list. Various trees have been developed throughout the past decades to suit specific applications and meet certain limitations. Few examples are binary search trees, red-black trees, B trees, AVL trees, splay trees, and n-ary trees.

*Applications of trees*

Binary Search Tree: These are used in many search applications where data is constantly entering and leaving.

Binary Trees: These are used to execute expression solvers and expression parsers.

### Searching Algorithms

Searching algorithms are of utmost importance ๐ as these are the class of algorithms that allow us to efficiently retrieve information from various data structures. These mainly include, **Linear Search, Binary Search, and Interpolation Search**.

### Sorting Algorithms

Sorting algorithms are another important category of algorithms as they allow us to **sort data** in a particular order for efficient functioning. Also, sorted data is a prerequisite for other algorithms such as Binary Search.

### Recursion and Backtracking

The process in which a **function calls itself** ๐ indirectly or directly is called recursion, and the corresponding function is called a **recursive function**. A lot of problems can be solved quite easily by using recursive functions.

source: dev.to

Backtracking is an algorithmic technique used to solve problems recursively by building a solution incrementally, one piece 1๏ธโฃ at a time. It does this by removing those solutions that fail to satisfy the problem's constraints at any given point of time (by time, we mean the time passed till reaching any level of the search tree).

## Let us now look at the resources and platforms that can be used for learning DSA

You can either choose to learn from videos on YouTube, start formal training by enrolling ๐จโ๐ซ in a course from websites such as **AI Probably**, or by reading books. Besides, you can also check out coding platforms such as:

You can also check out these popular books ๐ฐ for DSA:

- ๐
**Introduction to Algorithms :**Thomas H. Cornen - ๐
**Cracking the Coding Interview :**Gayle Laakmann McDowell - ๐
**Algorithms :**Sedgwick - ๐
**Data Structures and Algorithms Made Easy :**Narasimha Karumanchi - ๐
**The Art of Computer Programming :**Donald E. Knuth

Other than these, you can also enroll in this course on **DSA: Data Structures and Algorithms with Python by AI Probably** ๐. This course takes you from the very **basics** of data structures and algorithms to an **advanced** ๐ level in just a few weeks. Also, the course is going to be live soon!

Also read - Data Structure & Algorithms interview questions

Most of the other courses you would encounter while searching for a course on DSA would be in JAVA or C++ language. But considering the popularity ๐ and ease of use of Python, this course will teach you all the things you need to know about DSA in Python, from data structures like arrays, trees, and heaps to searching and sorting algorithms to multithreading. โ This comprehensive course is all you need to become a master of Data Structures and Algorithms!