Skip to content

Learn Data Structures And Algorithms (An Ultimate Guide For Beginners)

Notifications You must be signed in to change notification settings

DevDasPratap/Learn-Data-Structures-And-Algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

Learn-Data-Structures-And-Algorithms

Learn Data Structures And Algorithms (An Ultimate Guide For Beginners)

Mindset As my previous article elaborated, data structure and algorithms are the ultimate basis for a programmer. I strongly believe that a good knowledge of these two topics is also key to become a better programmer because an engineer who has a good understanding of algorithms and data structures can make thoughtful choices and write programs that can handle changes better and perform well.

I come, I conquer Some beginners will be discouraged and be frustrated at the beginning, feel that the data structure and algorithm are very abstract and obscure.

How to learn data structures and algorithms (An ultimate guide for beginners) 2

Don’t worry, that is very normal for beginners. I also got the same feeling when started learning. The real reason is that you did not find your own learning method, and haven’t built confidence for it. This is my roadmap and tips for you, Keep patience and keep moving.

Don’t be afraid of the mathematical part. Data structure and algorithms do involve some mathematical reasoning and proof, especially when analyzing the time and space complexity of an algorithm.

The big-O complexity analysis is important, but you don’t need to worry about it too much. You don’t need a high IQ or abstract mathematical knowledge. You can master it as long as you have a high school mathematics level.

You will have more confidence after months of practice and learning.

What is data structure and algorithm essentially? Generally speaking, the data structure is a storage structure for a set of data, an algorithm is a method and pattern for solving problems.

I will help you understand these two concepts from examples.

Take an example How to learn data structures and algorithms (An ultimate guide for beginners) 3

How do you find a book from a library?

Method #1: You can check each book one by one until you find the wanted book.

Method #2: You can first locate the bookshelf according to the category of a book, whether it is humanity, or science, or computer science, and then you search in the specific bookshelf.

In general terms, these two methods for finding a book are both algorithms, so we get the definition of an algorithm is: The methods for solving problems, which could be implemented in programming.

In detail, when we talk about data structures and algorithms, we are talking queues, stacks, heaps, binary search, dynamic programming and so on.

These are patterns for abstraction and solving problems, which invented by computer pioneers. We can effectively learn them and use them to solve many practical development problems.

The relationship between data structures and algorithm Data structures and algorithms complement each other. The data structure is for the algorithm, and the algorithm is applied to a specific data structure. Therefore, we can’t isolate the data structure and algorithms.

How to learn data structures and algorithms (An ultimate guide for beginners) 4

For example, because arrays have the characteristics of random access, the commonly used binary search algorithm requires an array to store data. But if we chose a data structure like a linked list, the binary search algorithm will not work because the linked list does not support random access.

The Steps Get good books and resources There are some really good textbooks for data structure and algorithms, but at the beginning, you maybe need the books which are coded in a programming language you have mastered.

C: Algorithms is your choice Java: Data Structures and Abstractions with Java Python: Problem Solving with Algorithms and Data Structures Using Python Visualizations will help you understand how data structure and algorithms works, you can find awesome animations of this kind from the site: visualgo.net.

How to learn data structures and algorithms (An ultimate guide for beginners) 5

Learning the basics data structures Many advanced data structures and algorithms, such as bipartite graphs, maximum streams, etc., are rarely used in our usual development. So, you don’t have to look at them at the beginning.

Here are 11 basic data structures for your starting: array, linked list, stack, queue, hash table, map, heap, binary tree, trie tree, graph, skip list You should learn these data structure APIs and also the complexity of their operations.

GeeksforGeeks summarized many good practices for data structures.

Learning basic algorithm design pattern From my experience, studying algorithms should not try to remember the steps and details of algorithms, but try to reinvent, reason and reimplement the algorithm by ourselves.

Why?

If you didn't understand how it works, you could not remember the details and will forget it later. Implied ideas in algorithms are more important than details.

My recommended flow for learning classic algorithms is:

How to learn data structures and algorithms (An ultimate guide for beginners) 6

Repeat this procedure will make you learn more effectively.

The most used algorithms come to these categories, some harder problems need some variants, you need to combine several algorithms to solve one problem.

Follow the principle of deliberate practice, you should focus on one specific category in a short time, try to learn them one after another: sorting, binary search, search, string matching, recursion, hash algorithm, greedy algorithm, divide and conquer algorithm, backtracking algorithm, dynamic programming Learn by doing There are many websites for deliberate practicing data structures and algorithms, I recommend these two, which both contain excellent online judge system:

Leetcode: which contains almost all the interview questions frequently asked by big companies(like Facebook, Google, Amazon), it's a very helpful resource for interviewing. HackerRank: which has very clean categories for data structures and algorithms, even contains problems of mathematics, database, and security. And you can also enter the programming contest for fun. Another good practice is finishing some trivial projects which using one specific data structure or algorithm.

For example, this project creates a Maze with the data structure of “union-set” and also tries to implement pathfinding algorithms. Finish this kind of projects will build your confidence, and also lets you realize it’s useful for creating real applications.

Get deeper More books Introduction to Algorithms, 3rd Edition is for your deeper studying, the algorithm reason part is awesome and also has more details on complexity analysis and mathematical tools.

And the final book is: The Art of Computer Programming, very few programmers have finished reading all this book. This is the ultimate and authoritative reference for you to dig deeper, this book almost covers all the corners of programming, especially about data structures and algorithms.

Learn from real projects Knowledge and skill will only prove the value when they are applied to products.

You could learn much from existing products and applications.

For instance, are you curious about what data structure or algorithm used for Google’s search suggestion?

learn from real applications

Some great open-source projects will be the most useful resources for your learning.

Redis contains many mostly used data structures and has many optimizations on performances. The Linux Kernel also used many data structures like link list, red-black tree, hash, etc.

After more years of practice, data structures will be yous tools for abstraction and algorithms designing will be the natural pattern for your problem-solving.

Keep curiosity and practice!

or

Types of data structures as well as their applications and significance of an algorithm

It is vital to understand the concepts of data structures and algorithms before learning to write a code in any programming language. These are the basic concepts that constitute in making the code efficient by helping in designing optimized solution. Algorithms are ‘scripts’ for writing the code in a particular language. What is a data structure? Nature loves organization and patterns. If we look inside a molecule atoms are packed in the most efficient way together. Even if we look at life around us all components seem to be arranged as per a system. And due to those arrangements they support the application of laws of nature.

Living beings inherit genes from their parents. The information is packed beautifully in small cellular components. The genetic code carried to an offspring from a parent carries enormous data, making it a marvellous ‘data structure’ and then the ‘algorithm’ of life plays out, using genetic data and turning offspring into a replica of its parents. This arrangement is so magnificent that genetic data gets passed on safely for generations without being lost. Here we can say that “A data structure is a format for storing, organizing and managing data in an addresable way that facilitates efficient execution of any process including that data.”

What is an Algorithm? The solution to the problem can written in text or mathematical form or explained verbally for humans. But machines understand programming language. In order to write a code in that language first the blue print has to be written which will accept the input data, process it and fetch the output. For utilising this data stored safely in our data structures we need a procedure, a ‘recipe’ in order to obtain required outputs. These procedures are called algorithms which are, “An unambiguous, finite sequence of instructions to solve a well defined problem.”

Solution Vs Algorithm Vs code An algorithm is not a code. Also a solution is not an algorithm. A problem is solved by the progrmmer first, this is called a solution. Then he writes a sequence of instructions that can be followed by machines called an algorithm . That set of instructions is then translated in a programming language understood by the computer and is termed as a code. Solution----》 Algorithm -----》code In practice, many such codes are integrated together to form a project. Thus, before learning a programming language one must be thorough with the concepts of data structures, their efficient use and solutions turned into algorithms. Only after this one can become an efficient programmer. Types of data structures Generally theses data structures are used by programmers Array — this is the simplest data structure supporting linear data storing in a sequential manner. Each element has an index indicating it’s position from the first element of the array.

Source — geeksforgeeks.com The indexing in an array can be done starting from 0, 1 or ‘n’.

Advantage — easy and quick implementation Disadvantage- memory allocation or size has to be mentioned in advance Application — arrays are used to implement more complex non-linear data structures like list, hash tables , heap etc. Linked list — It is a linear storage of data, where each element points towards the next element. That being said, it is not actually a linear allocation of physical memory to accommodate data continuously.

It is linear because the data can be inserted or removed only in one dimension- lengthwise, making the list either longer or shorter. The elements are called ‘nodes’ and consist of two parts : data and link (address of next node). It should be viewed as

Source- w3schools.com Here a pointer stores the address of the first node or element of the list, and that element points to the next node and so on. The last element doesn’t point to any address indicating the end of the list. 2. While adding or removing a node other elements are not required to be shifted. Only the pointer of last node is needed to be change to the address of new node while addition. And only change in the link portion of previous node has to be done while deleting a node. 3. We only allocate memory for the nodes we require, this causes an efficient memory utilisation. Disadvantages — 1. Accessing a node is time taking, as it is needed to be started from the head and go up to the required node. 2. Going reverse in a linked list is not possible. This is rectified in a doubly linked list, where pointer to both previous and next nodes are stored with data in each node. Application- browsing web pages, going previous and next Stacks — it can be viewed as a ‘vertical’ arrangement of data where the last inserted data is at top and first inserted data is at bottom.

Two main functions are performed on this data structure Push — to add data to the stack Pop — to take out last inserted data

Source — wikipedia The norm of LIFO (last in first out) is applicable to stacks. In order to get last item we can directly go to the top of the stack. But if we have to take out data any deeper than that then we will have to remove all data entries prior to it. Advantages- 1.easy to implement 2. Easy to perform reverse operations Disadvantage- the size of the stack has to be allocated before hand and cannot be changed Application- In practice, it can be applied to store the results of past operations such as command ‘undo’ in a Word document file etc. When a stack has reached its maximum potential and cannot accept more data that is referred to as a situation called “stack overflow". Queues — it is also a linear arrangement of data where new data is added from one end (rear) while old data is deleted from other end (front).

Source — www.geeksforgeeks.com Unlike stacks, the norm of FIFO (first in first out) works here, i.e. the element inserted first will be removed first.

The end used for insertion is not used for removal. While in stack, same end is used for both purposes. Advantage — both insertion and deletion become fast as are done at separate ends. Disadvantage- if we have to add new data while queue is full, so we may delete the first data for that purpose. Now, the front of the queue deleted and second element is the new front but the rear is still the last element i.e. the deletion did not fetch any new free space . Application- serving customer for online ticket booking. First come first serve. Tree — A non linear data structure that stores data in hierarchical manner i.e. data is at various ranks or levels. Here data is stored in nodes connected to the previous and next levels by edges.

Source — wikipedia First node is called “root” , node out which branches are coming out to connect other nodes is called parent node while the nodes connected to the parent are called child node. In figure above, 2 is the root. 7 is the parent node of {2,10,6} , these three are also sibling nodes. 5, 11 and 4 having no child nodes are called leaf nodes signifying the last level of a subtree. Advantage — 1.useful in storing hierarchical data as opposed to linear structures. 2. Efficient searching and accessing Disadvantage- the data cannot be unrelated or independent of each other. There must be some hierarchical relation. Application- used in storing hierarchical data like, file system in a computer. Graph — it is a data structure consisting of nodes connected by edges. It is different from tree as no hierarchy is present. It is a network structure and not a hierarchical structure.

Source — geeksforgeeks.com It consists of a set of vertices V = {0, 1, 2 , 4} Set of edges E = { 0e1, 1e2, 2e3, 3e4, 4e0, 1e4, 1e3} Advantage — helpful in storing non related data , non linearly Disadvantage- many edges are included which require memory space Application — in Facebook a person and all his friends are considered to be vertices while ‘friends’ status are the edges. There are many complex data structures used by the programmers in practice. For real world programmes will require real data which can only be stored by these — Hash tables Heap Trie Binary search tree Segment tree Binary indexed tree Suffix tree And so on.

About

Learn Data Structures And Algorithms (An Ultimate Guide For Beginners)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published