Data Structures Interview Questions And Answers 2026 | Data Structures And Algorithms | Simplilearn
Key Takeaways
This video teaches data structures and algorithms for interview questions and answers
Full Transcript
If you're wondering what's the secret behind acing technical interviews at top companies like Google, Amazon, and Microsoft, it's simple. It's about data structures and algorithms. These are the building blocks that every coder needs to master in order to tackle complex problems and impress the interviewers. But what exactly are data structures and algorithms? Data structures are ways to store and organize data so that it can be accessed and manipulated efficiently. Think of them like different types of containers that help you manage data in a way that makes sense for your tasks. For example, an array is like a list of items where each item has an index. And a link list is like a chain of connected items where each item points to the next one. Algorithms on the other hand are stepbystep instructions or procedures for solving a problem. They tell you how to process data in order to achieve a desired results. For instance, quick sort is an algorithm for sorting data quickly and breath first search is an algorithm used to explore all the nodes in a graph. In this video, we'll be discussing the 10 most important data structures and 10 key algorithms that you need to prepare for coding interviews. These topic are just not essential for interviews but are the foundations for becoming a skilled efficient problem solver in software development. We'll be diving into how each data structure works, why it's important, and how it is implemented, followed by the algorithms you need to understand to manipulate these structures efficiently. From arrays and link list to binary search trees and heaps algorithms like quick sort, breath first search and dynamic programming, we'll cover everything you need to know. By the end of this video, you'll have tools to approach any coding challenge with confidence, making you not just ready for interviews, but ready to excel in them. So, let's get started. Before we start, here's a small question and answer segment for you to answer. What do you think is most important for coding interviews? writing code quickly, organizing and managing data, knowing many languages or memorizing answers. Let me know your answers in the comment section below. First, let's talk about data structures. As we discussed earlier, they are the ways to store and manage data. In this category, the first and most important one are arrays. Now, what are arrays? Arrays are like list where you can store multiple items in an orderly way. Imagine you have a row of boxes and each box has number which is index that I'll be letting you know that lets you find an item inside it easily. However, if you want to add or remove something from the middle, it can take time since all the other items need to be moved around. So here to explain the code, data structures and algorithms, I'm using an online compiler. You can use whichever Python installation you are having. So the first thing is how do you declare or assign it? So it's very simple. It's a ar r. Give it a name if you would like to and a ar r is the name I'm going for so it's easy for your understanding and give it the data that you want to store in. So we have 10 20 30 40 and 50. So this is the assigning of the array. Consider this as a box of data that is stored one after the other. So this is the first box, second box, third, fourth and fifth. Now indexing is kind of a thing in an array. So if I say a r r zero which is the 10th place. So always the starts with zero to how muchever the data is available. Now if I want to print suppose say second element. So second element in indexing is 0 1 2. So this number I want to get. So we will type in print. Let's say element at index 2 and let's give a r r and two. Now let's run it and see the output. So here you can see element index 2 is 30. So let's count 0 1 and 2. It is 30 and showing 30. Now how do you insert data in middle? So here's the code for this. You can say a r insert 2 comma 25. Now 2 is the index and 25 is the data. Now I need in index 2. 25 should be there instead of 30. So let's just run this and next we'll print the same sentence and see what appears. So here you can see first it was 30. Now since we have added it it is 25. Now how do you delete the data from the array? So you can just say d e l from the array and which index the number is. It's a very simple command. So let's just run it and uh a r r3 is gone which is let me just print the array for you. So now you can see the 30 which was shifted to the third position and I have deleted that number and now the array is 10 20 25 40 and fifth. So this is about an array. Moving on to linked lists. A linked list is like a chain of nodes where each node holds some data and point to the next one. Unlike arrays, linked lists don't need all elements to be in an row. This makes them flexible when adding or removing elements in the middle. So let's design a program for it. Now here's a simple code for the explanation of link list. Firstly, we are defining class node and we are giving it df in itself do data. Here it initializes the node with the piece of data and a reference to the next node. And then we have given self dot data is equal to data which stores the data passed as an argument. And next we have self.next. next which sets the next pointer to none indicating the node is not pointing to anything yet. Then again we have declared a class linked list and again we have df in itself which initializes the link list with a head pointer and then again we have self dot head is equal to none. The head of the link list is initial none meaning the list is empty for now. Next in the same class we are assigning one more function which is def append self, data. Append a new node with given data to a link list. And then we have new data and then we have new node is equal to node data which creates a new node with a provided data and then we have an if else loop. So here if node self dot head this is checking if the list is empty and then what is the condition here? self dot head is equal to new node. So if the list is empty the new node becomes the head which is the first node and then we are returning in the sense we are exiting from the function after seeing that head. So if the if condition is false it'll come here which is last is equal to self do head. This sets the last pointer to the head of the list which is the first node. Then we have while last do next which is looping through the list until we find the last node where the next is none. And then again we have last is equal to last do next. This moves the last pointer to the next node. And then we have last do next is equal to new node after the loop is done which sets the next pointer of the last node to the new node adding it to the end of the list. And now the next function will be df display cells. This displays all the nodes in the link list. And then we have current is equal to self do head. This starts from the head of the list. And then we have while current. Again we are starting a loop which is transfers the list until we reach the end. And inside the loop we have print current data. End is equal to whatever data is printed. And then we have current is equal to current dot next. This moves the next node in the list. And lastly, we will print none to signify the end of the list. Now, let's just run this and check for an error. There is no error as of now. Now, how do you start with giving a link list? So, you can just name it LL is equal to linked list and call the function and again LL.append. So this l is equal to link list. This creates a new linked list object initially empty. So this is an empty list which is created. And then we have ll is equal to append 10. Now this adds a node with a data of 10 to the link list. And let's add more data. Append 20. So here I list out is equal to and 20. And I'll be adding another. And now let's call the function and see there's a spelling error that now just let's just run it. Okay. So instead of is equal to it is dot append. So the array name dot append and the values. So let's just run it now. And it has no errors. Now at last we'll just display the repeat. Now at last we'll just display the link list. So it's just display with no values. So now let's just run it. So as you can see the first value that was pushed was 10 then 20 then 30 then it'll give you the value of none. So this is all about linked lists. Next we have hush tables. Now a hush table is like super fast lookup table. It maps keys like names to values like phone numbers. Instead of going through each item one by one, it directly jumps to the right spot using special functions. It's like looking up someone's name in a phone book and instantly finding their number. So let's see how to create a hash table. Now we've already created a small program of how to declare hush table. So let's go through each of the sentence. The first one we have hash table is equal to a1, b2 and c3. So here we are accessing an element by key. Now if you tell print value for key B hash table B. So here let's see what will be the value of calling it by a particular position which here it is B. So let's just run it. Ideally the B value what is the B value? Two. Two should be there. So you can see value for key B is two. So for key A it will be one. For B it will be two. For C it will be three. Now next we have hush table. And next we'll see how to push in other values. Here again I'm giving hush table and I'm pushing D as a key and the value as four. Now let's print what's there in four. So as you can see hush table after adding D is A B C and the D1 which we just pushed in is already here. Now how to delete the data again we have very simple code which is d hash table the key value of the entire data. So ideally this should drop the value of a1. So after deleting we as you can see after deleting we have hash table b it starts from the key b 2 c3 and d4. [snorts] So this is all about hash tables. The fourth most important one is binary search trees which is BST. A binary search tree is like an organized collection of numbers where every number on the left side of the node is smaller and every number on the right side is bigger. It allows us to search for a number quickly. So let's create a DST node. Now here I have already created a BST node with classes and functions. So let me just explain this basic code. Firstly, we have class BST node and df init self.key key. So this defines the class for a BST node which will hold the data and pointers to the left and the right child nodes. And then we have self.left is equal to none, self.right is equal to none and self dot value is equal to key. And coming to the self dot value key, it stores the value of the key of the node. Then we have a function under that which is df insert root.key. This defines a function to insert a new key to the BST. Next, we have a if else root. Now, we have a if else format. So, if root is equal to none, which is if the root is none, we have found an empty spot to insert the new node. So, we are giving a return value of BST node key. So, here we are creating a new BST node with the given key and return it to the new node. And in the else we have if key is less than root value that is if the key to insert is smaller than the root values it should go to the left sub tree or else it should go to the right sub tree and then we are giving return root which is returning the root node to ensure the tree structure remains intact after insection. Next another function that I have described here is def in order transversal root. This defines the functions for in order transversal which prints the nodes in sorted order. So we have if root which is again if the current node is none meaning the tree is not empty. In that case we have in order transpose root. Which is like recursively transfers the left sub tree to go to the left child first and then we are printing root dot value end with a space in it. So this prints the value of the current node with a space after that. So let's call this function and see the output. So firstly we have to call. So let's call the first function which is BST node as we have given and let's say 50 is the value that I'm passing and let's say insert what is the name of the function root, 30. Let me give a couple of more. So 30 40 70 random values. So here we have given a random numbers. So let's see what will be the output. Let's just print it. So we'll be calling the function which is in order. So let's just run it. So there's a so there is an extra s. So just run it. And here you can see it is 30 40 50 and 70. it is arranged in a ascending order. So this is all about BST node. Let's move on to the next one. The next one is heaps which is priority query. A heap is like a priority list. For example, in a max heap, the highest priority item which is the largest number is always at the top. You can quickly remove or add the highest priority item. So for example, I have a code here. So let's go through it. So firstly we have to create a mini heap. So I've given here heap is equal to 10 20 15 20 and 40. Before that we'll have to import heap q. And then next we have heap q dot heapify heap which is basically creating a mini heap version. And then here we have to insert a new element we have heap q dot heap push head file. So for popping the smallest element print smallest element popped. So let's run this. We have 10 20 15 30 and 40. So here the smallest element is popped which is five which we had added. So for the current heap we have print current heap heap. So what is the remaining heap one? We'll just print it. You can see it is 10 20 15 30 and 40. So this is all about heaps. Next we have graphs. Now a graph is a collection of points which is vertices connected by lines which are edges. It uses for showing how things are connected like people and social network or cities in transformational maps. So to create a graph using a aensary list we have given graph which is a pointers a which has a loop of b and c then b has a d e c has some points and f has some points. Now let's print the neighbors of a in graph a. So the neighbors of a are b and c. It is printed here. It's a very simple concept. You can use it for locations etc. So the seventh important structures are tries which is perfect trees. A tree is a treel like structure that helps you quickly search for words that starts with the same letters like autocomplete features and search engines. It's perfect for handling large collections of strings. For example, let's create a demo of this particular data structure. We'll be starting with class try node and df in itself and we have self dot children is equal to an empty array. This initializes an empty dictionary to store the child nodes and then we have self dot is end of word is equal to false which is a boolean flag to mark the end of a word. Then we are declaring a class of tree where again we have df entity and self and then we have self.root root is equal to try node. Here we create the root note of a try which is an empty try node and then we have df and the next we have df insert again we are passing self, word and then we have none is equal to self.root and we have a for loop here. So for car in word it iterates through each character in a word. If car not in node dot children that is if the character is not already in the children of the current node. What is the condition for that? We have note dot children care is equal to try node which creates a new try node for this character node. And then we have node is equal to node dot children with care after from the loop which is moving the child node corresponding to the current character node. And then we have node dot is end of the world which is equal to true. This marks the current node as the end of the word after the last character. And lastly we have df search function which again has self word as parameters through it. And we have node is equal to self dot root which starts the root node for care in word. And then we have an if loop which iterates through each character in the word. Now if the character is not found in the word it will end off word. It will stop the search and return the false statement. And then we have node dot children care which moves the child node to corresponding to the current character. And again we are returning note dot is end of the word which is return whether the current node marks the end of a valid word in a tire. So here we are creating a new trio objects as try e is equal to try and then we are inserting a word called hello and let's printing is hello in the try and then the next question will be is hell in the try. So the first answer should be yes and the second should be no. So this is statement returned as true value since it is there in the try and false because hell is not there in the try. So this is all about try. Let's move on to the next one. Now moving on to the eighth one. We have stacks and cues. A stack word like a stack of plates you add on the top and you also take from the top. We have a concept called last in first out. So whichever element goes in first will be called out first. A Q is like a line to tackle counter. You join the line and back and you leave from the front which is f I fo which is first in first out. So here again I have uh given a small program to explain this concept. We are initializing stack which is an array and empty list to represent the stack and then we have stack dot append 10 2030. So here we are giving the values of 10 2030 to the stack array and then we are printing popped from stack which is stack dot pop. So we'll see the result here. Next we have Q again assigned with an empty list and given it values of 10 20 30 and we are printing the Q and popping the first value. So stack is supposed to give last in first out and Q is supposed to give first in first out. So in stack this 30 should have been popped and in Q the 10 should have been popped. So let's check for the results. So as you can see pop from the stack is 30 and dqed from the queue is 10. This is a very simple concept. So let's move on to the next one. So the next one is segment trees which is segmented trees help in situations where you need to answer range queries quickly like finding the sum or minimum of subrange in an array. They are efficient for programmers involving raj data sets. For example, here in a demo, I'll be showing how to assign a class and a function. So here there is a class of segment trees where again we have df in it self dot data and next we have self n length of the data. We're calculating the length and we have self dot tree is equal to 0 into 2 into self.n. So here it creates an array which is a tree of size 2n initially filled with zeros. Next we have self dot build data which calls the build method to construct the tree. Next we have df build self data which is building a segment tree based on the input data. Next we have to initialize the leaves which is the second half of the tree. So for that we have for i in range self n self dot tree self dot n plus i is equal to data do i and we have for i in range self n -1 0 - one. So here it will loop through the input data and then copy the input data to the second half of the tree array and then it will move on to building the segmented tree by calculating the parent node. So next function we have df query which passes data of self l and r. Here the query of the sum of elements from index to r. So we have res is equal to zero. This initializes the results to zero. And then we have l plus is equal to self. N which is a left index to correct position in the tree of array which is a second half. And next we have incrementing r also to self. n which is adjusting the right index similarity while l is less than or equal to r value. So while the left index is less than or equal to the right index is the condition for here. Now we'll start with the if loop under the while loop. So here we have if l modulus 2 is equal to equal to 1. This is if the l is an odd index it's right child. So we add it to the results. Next we have plus is equal to self dot tree which is moving to the next node and then we have r modulus 2 is equal to is equal to0 that is if r is an even index it's left child so we add to the result. Next we are incrementing r to move to the previous node and then we have l divided by is equal to 2 and r / 2. This is moving the parent node to the right node. The final result is also printed here which is return RDS. Now let's pass some data which here randomly I've taken 1 3 5 7 9 and 11. We're calling the function and let's print the sum of index 1 to 3 and also the query is also there. So let's run it. So from index 1 to 3 is 15. So here it is 3 + 5 + 7 which will be equal to 15. So for the 10th data structure we have union which is also called as disjoint set union. Union find helps you manage groups that don't overlap like checking if two people belong to the same group. It is a fast and efficient when dealing with connections between elements such as detecting cycles in graphs. So here again there is a program for that understanding. The first class is union find under which we have three of the functions. So the first one is again we are passing in self dot size. This defines the class union find for managing disjoint sets and we have self.tparent is equal to list range size which initializes the parent list. Each element is its own parental initialization and we have self.trank at one which is size. This initializes the rank list all the nodes. Then we are starting with rank one. Then we have df find set.x which defines the find function to find the root node and set the containing element as x. Then we have if set.tp parent x what is the condition then? So if the element x is not shown to the parent what is the condition here I have passed is to update the path compression which is update the parent of the x to the root and return the self do. parent x which is returning the root of the set containing x. Next we have df union which is self x y. This defines the union function to merge sets containing elements as x and y. Then we have rootx is equal to self dot find x which is finding the root of the set containing x. And similarly we have root y and we have a if else. So if root x is not equal to root y, if the two elements are in different sets, we need to merge them. And the next element is to attach smaller tree under the root of larger trees to keep the tree balanced. Again we have another if statement which is if self dot rank rootx is greater than self rank root y that is if the root has higher rank make root x the parent of root y. Next we have self.tar parent root y which is equal to rootx and we have else if self dot rank which is rootx is less than self dotrank root y. So here if the root y has a higher rank make the root y the parent and rootx as a child. Now what if these both conditions fails if both the roots have the same rank make one root of the parent the other and increment the rank. So here we have self do.t dot parent root y is equal to x and self.trank rootx incremented. So let's initialize and call the function. So I've initialized uf union fine. So I'm calling it I'm giving it a value of five and we have uf dot union 0a 1 and uf dot union 1a 2 and we are printing zero and two connected. So let's just run. So this is a true value. Now let's move on to the most important algorithms. At number one, we have binary search. Binary search is a fast way to find an element in a sorted list by dividing the list into halves. It starts in the middle and checks if the element is greater or smaller than the middle one. Narrowing the search until the item is found. Now let's see how binary search works by implementing it in Python. So here in this program the first thing that I'm doing is defining a class which is binary search and then we are passing the array and target and here we are assigning values of left right which is initially zero and then length of the array minus one and then we are using a while loop. So if the value of the left is less than or equal to right then the middle will be left plus right divided by two. Or else if the array in the mid is equal to is equal to target. That is if the middle one is the number that we are searching for then it will return the mid value. Else if the array of the mid is less than the target it will be left is equal to mid + one. So each part it will cross check first part mid part and the third part which is the last part. In which range will the number lie and then for that we have a if else loop here. And then we are returning minus one. if none of the conditions are true which is not likely to happen and here I'm assigning an array of the numbers with random numbers 1 3 5 7 9 and here I'm printing the index of seven which is I'm searching for the array where the number is 7. So what should be the position or index of seven? It should be 0 1 2 3. So let's run this program and see if the output is three. So as you can see we got index of seven is three. Now when you're assigning the array make sure that the array is ascending order for this kind of problems. Else you can create a if else loop to sort that out too. The second most important one is the quick sort. Quick sort algorithm is an efficient sorting algorithm that selects a poot element and rearranges the array so that smaller elements are on the left and larger elements are on the right. then recursively applies the same logic to the subarrays. Now let's take a look at how to quick sort words with simple array. So here the first sentence is defining a function which is df quick sort r. This defines a function to implement quick sort. Then we have if length r which is the array is less than or equal to 1. That is if the array has one or fewer element it's already sorted and then we are returning the array. So this is checking if the array is already sorted or not. Next we have P is equal to a ar r length of ar r divided by two. This selects the middle element as the p. Then we are initializing left mid and right. So for left we have x for in r if x is less than p. So this creates a list of elements which are smaller than the p element. And for the middle we have to create a list of elements equal to the p right. And then we have write which is x for x in a ar r if x is greater than pword. This creates a list of elements greater than the pw return quick sort which is the left plus middle quick sort which is the right recursive sort the left and the right subarrays and combine them together. And then lastly we are returning the quick sort. So here I've given an array of 3 6 8 10 1 2 3. So this 3 6 8 part is sorted 1 2 1 and two value should be sorted and displayed over here. So let's check the output. So here the sorted array is 1 comma 1 comma 2 3 6 8 and 10. So this is how you sort the arrays. The third most important algorithms is the merge sort. Now merge sort is stable, divided and concurrent sorting algorithms that guarantees O N log N performances in all cases. It divides the array into progressively smaller halves until reaching individual elements then systematically merges them back together in sorted order. Now let's see how to merge sort divides the array and merges it back together. So here we are starting with defining a function which is df mod sort and passing a element which is arr. This defines the functions to implement mod. Then we have an if loop if length of the array is greater than one. That is we are checking if the array has more than one element so that it can be split. And then we are calculating the mid of the entire array. So we have length r divided by two. And then we are assigning left half and right half. The left half of the array and the right of the array is assigned. Then we have merge sort left half and merge sort right half. And then here we are initializing few values so that it will be useful for the if and else loop. So we are giving it initially zero as the value. So we are taking i, j and k as the values. Now before starting the if loop we need a while loop so it iterates through the entire loop. For that we have given i which is less than the length of left half and j is less than the length of the right half. That means we are merging two of the sorted halves into one original array. Next we have the if loop. We have if left half of i which is initially zero then it'll get incremented. And then J which is less than length of right half which is again in the position of the zero right now we'll be assigning a ar r of k is equal to left half i and incrementing i. So if the right element is smaller add it to the original array. Whereas if the left half if that's not the condition you can just increment the j and assign it to the left half. Next coming down here we have another while loop while I is less than length of left half and we are again calculating the ar r of k which is equal to left half of i and similarly assigning the right half which is while j is less than length of right half a r of k is equal to right half and incrementing both the values so it can iterate here. Now here I've given an array which is 12 11 13 5 6 7 and passing this array through the function of merge sort and let me print the array and show. So as you can see it is already sorted it is 5 6 7 11 12 13. The fourth most important algorithm will be the breadth first search which is BFS. Now BFS explores a graph by visiting all the vertices level by level starting from the source. It's a great finding the shortest path and unweighted graphs. So let's now look at how this works in graph transversal for example. So here before that I'm importing collections for the graph purposes and then we have dfbf graph starts which defines a function for bfs transversal and then we have visited is equal to set. This creates the set to keep track of visiting nodes. And then we have Q which is equal to DQ which is creating a Q and add the start node. And we have a while loop as well. Here starting while there are nodes to visit in the query, we have vertices which are the nodes Q dot pop left. So here pop the first node from the que. If the node is not invisited, we are marking the visited dot add one. So here mark the node as visited and then print vertex end. This is printing the node for neighbor in the graph vertex. Then you can add all the neighbor of the current node to the Q. And lastly we have Q dot append neighbor. Then we need to assign the values of the graph here. So as you can see we have assigned the graph values and neighbors of A as B and C and we are calling the function here BFS graph A. So we are printing the BFS start from and printing it. So let's take a look. So here you can see BF is starting from A and then we have A B C D E and F as you can see. Next we'll move on to first search which is DFS. So DFS explores as far down the branch as possible before backtracking. It uses a stack to keep track of the nodes. It's good for problem solving like detecting cycles in a graph. So now let's see how DFS works in simple graph transversal. So firstly here I'm initializing a function which is DFS and passing values which is graph start and visited is equal to none. This defines a recursive DFS function. And then we have if visited is equal to none. This means it initializes the visited set if it's none. And then we have visited is equal to set. So we have added visited dot add start which marks the current node as visited. And at last we are printing the start and the end points which is printing the node basically. And then we have for loop which is for neighbor and graph start which recurs for all neighbors of the current node. Then we have if neighbor not in visited which is if the neighbor has not been visited. What is the condition then? We have dfs graph neighbor comm, visited and then finally we are calling the graph which is dfs graph a but we have not assigned the graph. So let me just quickly assign the graph. Again I've assigned the same graph as given in the previous algorithm. Now let's run this and you can see df is starting from a and what are the values or the points here? We have A, B, C, D, E, and F. Next, we have Distar's algorithms. Now, Dickistar's algorithm finds the shortest path from the source to all other nodes in a weighted path. So, if repeatedly selects the node with the smallest known distance and updates the distance to its neighbors. So, let's implement Distra's algorithm to find the shortest path in the graph. So here we are starting by importing heap Q which is the module to implement the priority Q and then we are moving on to defining a function which is dictitas and next we are moving on to a function which is dicras and then we are passing the parameters which is graph comma. This defines a function for the algorithm and then inside that we have distance is equal to node float if for node in graph. This initializes the distance as infinity of all other nodes and then again we are initializing that distance start with zero value. Next we are updating the priority Q which is zero to the start node. Next we have a while loop. Here we have while priority Q. So which is not a empty Q. We have current distance current node which is equal to heap Q dot heap priority Q. So here Bob the node with the smallest distance is simple words. Then we have if current distance is greater than distance current node we can skip nodes that have been already processed and continue with it. And then for neighbor weight in graph which is the current node dot items we have to update the distance to the neighbors. So we have added this for loop and under which we have distance is equal to current distance plus weight. So if the distance neighbor which is if the shorter path is found we can replace the distance neighbor to the distance and lastly we have heap q head push priority q distance comma neighbor. This push the updated neighbor to the que and then we are returning the distance and as usual here we have the graph initialized and printing the shortest distance from a. Now what should be the shortest distance from a? It should be so you can see here the shortest distance from a will be a 0, b1, c3 and d4. Next we have dynamic programming explanation which is dynamic programming solves problems by breaking them into smaller overlapping subpros and sorting the results to avoiding recomputation. Then it is useful for optimization problems. So let's explore the dynamic programming and how to do it. We'll use a simple Fibonacci sequence for example. So first as you can see we have df fib n comma memo which is assigned with a empty array which defines a recursive function with memorization dictionary and if n in memo return memo n which is the fibonaki number for n is already calculated and sorted and then we are returning the memo value. Then if n is less than or equal to 1 which is base case if n is zero or 1 return the n value and then we have memo n is equal to fib n minus one memo plus fib n minus 2a memo. This stores the results of the current n by summing the previous two fiboni numbers and then we're returning it. So let's run this program here. We are calling for 10 fiboni numbers. So as you can see the 10th Fibonacci number will be 55. So this is a simple example of this algorithm. Next we have the algorithm. KMP is an efficient string matching algorithm that pre-processes the pattern to avoid unnecessary rechecks improving performance on large text. So let's now look at how KMP efficiently matches patterns in given string. This approach eliminates unnecessary comparisons making it much faster for larger strings. So firstly we are giving a function which is kmp search and passing parameters which is text and pattern and then we have lps is equal to0 into length pattern where initializes the longest prefix suffix arrays and then we have j is equal to0 which is computer lps array system pattern lps which preprocess the pattern to create the lps array and then we have i is equal to0 it's a initialized pointer for the text and then while i is less than length of text we have transfers the text if pattern J is equal to is equal to text I this is a condition format if the characters match move the next character and then we are incrementing both I and J and coming to the if loop here we have if J is equal to is equal to length of the pattern that is if we have matched the whole pattern print pattern found at index I minus J and also we use LPS array to avoid redundant checks so for that we have reassigned J as LPS J minus one. Now in the else if loop we have I is less than length of the text and pattern J which is not equal to text. So if the character don't match J is not zero we can skip comparison using the LPS array. So again here we have J is again reassigned to LPS J minus one else we are incrementing the I. Next here we have DF computer LPS array and also passing pattern and LPS back again. Here this is a helper function to compute the LPS array which is length is equal to zero. This initializes the length of the largest prefix which is also suffix and then again we have I is equal to 1 and a while loop will start. Now while I is less than length pattern we have if pattern I is equal to is equal to pattern length which is if the characters match extend the length which is length incremented by one and we have LPS of I is equal to length which is update the LPS array and again after that again we are incrementing the I and again back in the else loop we have another if condition which is length is not equal to zero. What happens then? length is LPS length minus one. LPS is equal to zero. So if no match LPS back to LPS to zero to move to the next character and increment the I value. Now again here we are passing the values. Let's say KMP search this is the array and what to be search is a b a c a b a c. So here this is the entire word search. So we'll see if it is found. So there's an error. So let's just check with the error. So yeah, I think we are good to go. So here you can see pattern found at the index 10. So it'll be 0 1 2 3 4 5 6 7 8 9 10. From here the same pattern will be there as given the search value. Next we'll be talking about algorithm. Krushkar's algorithm is used to find minimum spanning tree which is MST in a graph. It sorts the edges by weights and adds them to the MST making sure no cycles are found. So let's implement crucial algorithm to find minimum spanning tree in a graph. So firstly for crucial we have a class defined which is union find and then under that we have assigned a function. This is the usual normal one in itself. N which initializes the union find data structures with n elements. And then we have self.t parent list range n which each element is its own parental initialization and then we have self.trank at one into n each element has rank of one initially. So due to that we have always multiplied the value by n and coming to we have another function which is define find self dox. So here find the root of the set containing x under which we have a condition of if. So if self do.t parent x is not equal to x we have if x is not its own parent find its root and then under that we have self.tparent x is equal to self dot find self.parent x. So this is path comparison which updates the parent of the x to the root and then we have return self.parent x which is returns the root value. Next we have another function called union. So here you can see we're passing the values of self x and y. So union the sets containing X and Y and then we have root X and root Y also initialize. This is for finding the root of the set container X and Y. Now what is the if condition here? We have given if root of X is not equal to root of Y which is they belong to a different sets of union then what is the condition here? If self dotrank rootx is less than self do.rank root Y. So here it increments the rank if both trees have the same ranking for this entire loop. So then here we have edges is equal to we have named some of the edges defines the edges with weights and then we are sorting the edges here edges dots sort key lambda xx2 in ascending order and then lastly we have mst with an empty array list to store the edges of minimum spanning. Next we have another for loop. So we have for uv weight in edges here it iterates through the sorted array and if uf dot find u we are calling find if not equal to uf dot find v that is if u and v are not already connected add the edges which is how do you add the edges we have msdappend uv and weight and then we also have uf dot union u comma v this union is the set of containing u and v and lastly we are printing minimum spanning tree which is msd tree. So let's take a look at the result. So as you can see minimum spinning tree will be 2a 3a 4 1a 2a 5 and 0a 2a 6. And that brings us to the end of this journey through top 10 data structures and algorithms you need to master for coding interviews. By now you should have solid understanding of the core concept and how to implement them in Python. These algorithms are not just interview essentials. They are the tools that make you more efficient and confident problem solver in your coding career. But remember, practice is key. The more you work with these data structures and algorithms, the faster and more intuitive they'll become. Whether you're preparing for your next interview or looking to improve your coding skills, these foundation concepts are your stepping stones to success. If you found this video helpful, make sure to like, share, and subscribe for more in-depth content. Until next time, keep learning with Simply Learn.
Original Description
🔥Full Stack Java Developer Program (Discount Code - YTBE15) - https://www.simplilearn.com/automation-testing-masters-program-certification-training-course?utm_campaign=3JyAPsAGfY0&utm_medium=DescriptionFirstFold&utm_source=Youtube
🔥AI-Powered Full Stack Developer Program - https://www.simplilearn.com/full-stack-developer-course-mern-certification-training?utm_campaign=3JyAPsAGfY0&utm_medium=DescriptionFirstFold&utm_source=Youtube
This video on 'Data Structures Interview Questions and Answers 2026 by Simplilearn will help you learn the critical concepts and strategies to excel in data structures and algorithms interviews. We’ll cover the most commonly asked interview questions, focusing on essential data structures such as arrays, linked lists, trees, and graphs, and algorithms like quick sort, breadth-first search, and dynamic programming. Through clear explanations and practical examples, you’ll gain the skills needed to tackle real-world problems efficiently. Whether you're preparing for top tech interviews or just looking to improve your problem-solving skills, this video is designed to give you the edge in mastering data structures and algorithms for 2026.
Following are the topics covered in the topic Data Structures Interview Questions And Answers 2026
00:03:09 arrays
00:06:24 linked lists
00:11:06 hash tables
00:16:17
00:18:18 trie
00:21:26 stacks and queues
00:22:55 segment trees
00:26:21 union find
00:29:30 binary search
00:31:50 quick sort
00:33:30 mrge sort
00:36:21 breath first search
00:38:10 deapth first search
00:39:45 dikistras algorithm
00:42:02 dynamic programming
00:43:21 KMP
00:45:57 krushal algorithm
Related Videos:
✅ 1. https://youtu.be/M_JSNj-Tcg0
✅ 2. https://youtu.be/n5XQkv5mAao
✅ 3.https://youtu.be/X4Uofzjk1uU
✅ 4. https://youtu.be/OQnvWsYl9rc
✅ 5.https://youtu.be/axd4UQg9vPw
✅ Subscribe to our Channel to learn more about the top Technologies: https://bit.ly/2VT4WtH
⏩ Check out More Videos By Simplilearn: https://www.youtube.com/pla
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Simplilearn · Simplilearn · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Ethical Hacking Full Course 2026 | Ethical Hacking Course for Beginners | Simplilearn
Simplilearn
AWS Full Course 2026 | AWS Cloud Computing Tutorial for Beginners | AWS Training | Simplilearn
Simplilearn
Data Structures And Algorithms Full Course | Data Structures and Algorithms Tutorial | Simplilearn
Simplilearn
SQL Full Course 2026 | SQL Tutorial for Beginners | SQL Beginner to Advanced Training | Simplilearn
Simplilearn
Microsoft Azure Full Course 2026 | Azure Tutorial for Beginners | Azure Training | Simplilearn
Simplilearn
Shopify Tutorial For Beginners 2026 | Shopify Course | shopify dropshipping | Simplilearn
Simplilearn
Six Sigma Full Course 2026 | Six Sigma Green Belt Training | Six Sigma Training | Simplilearn
Simplilearn
🔥Feeling Stuck? How Upskilling Can Boost Your Career! #shorts #simplilearn
Simplilearn
Growth Hacking In Marketing | Learn Growth Hacking Marketing Strategies | Simplilearn
Simplilearn
🔥Cracked 3 Job Offers with One AIML Course! | 20–30% Salary Hike #shorts #simplilearn
Simplilearn
Top 10 Must-Have Figma Plugins for UI/UX Designers in 2026 | Figma Plugins | Simplilearn
Simplilearn
Business Analytics Full Course 2026 | Business Analytics Tutorial For Beginners | Simplilearn
Simplilearn
Simplilearn Reviews | Getting future-ready with course in Artificial Intelligence | Roopam’s story
Simplilearn
Generative AI Full Course 2026 | Gen AI Tutorial for Beginners | Gen AI Explained | Simplilearn
Simplilearn
Full Stack Developer Course 2026 | Full Stack Java Developer Tutorial for Beginners | Simplilearn
Simplilearn
Simplilearn Reviews | How David Went From Seasoned Engineer to AI Innovator #GetCertifiedGetAhead
Simplilearn
Complete Social Media Marketing Strategy for 2026 | Social Media Marketing Strategy | Simplilearn
Simplilearn
🔥Top 4 Cybersecurity Certifications You Need! #simplilearn #shorts
Simplilearn
🔥Cloud Engineer Salary in India 2026 | City-Wise Breakdown #shorts #simplilearn
Simplilearn
Digital Marketing Full Course 2026 | Digital Marketing Tutorial For Beginners | Simplilearn
Simplilearn
Full Stack Java Developer Course | Full Stack Java Developer Tutorial for Beginners | Simplilearn
Simplilearn
Social Media Marketing Full Course | Social Media Marketing Tutorial For Beginners | Simplilearn
Simplilearn
How To Create LLM Chatbot Demo 2026 | Build a LLM Chatbot From Scratch | Simplilearn
Simplilearn
Digital Supply Chain Management Certification | Supply Chain Management Course | Simplilearn
Simplilearn
AI Agents Full Course 2026 | AI Agents Tutorial for Beginners | How to Build AI Agents | Simplilearn
Simplilearn
ITIL Full Course 2026 | ITIL 4 Foundation Course | ITIL Tutorial For Beginners | Simplilearn
Simplilearn
Generative AI Full Course 2026 | Gen AI Tutorial for Beginners | Gen AI Explained | Simplilearn
Simplilearn
ITIL Full Course 2026 | ITIL 4 Foundation Course | ITIL Tutorial For Beginners | Simplilearn
Simplilearn
Simplilearn Reviews | Integrating AI & Music | Diego's Story
Simplilearn
Digital Marketing Full Course 2026 | Digital Marketing Tutorial For Beginners | Simplilearn
Simplilearn
SEO Full Course 2026 | SEO Tutorial for Beginners | SEO Training | SEO Explained | Simplilearn
Simplilearn
PMP Vs CAPM: Which Certification Should You Choose? | PMP Vs CAPM | Simplilearn
Simplilearn
Complete Data Analyst Roadmap 2026 | How To Become A Data Analayst In 2026 | Simplilearn
Simplilearn
Generative AI Full Course 2026 | Gen AI Tutorial for Beginners | Gen AI Explained | Simplilearn
Simplilearn
🔥5 Jobs That Are Most Likely Safe from Layoffs in Today’s Market #shorts #simplilearn
Simplilearn
🔥Git vs GitHub – What's the Difference?
Simplilearn
What Goes Behind Building the Likes of Uber and Netflix? | Product Management Tutorial | Simplilearn
Simplilearn
AI Agents Full Course 2026 | AI Agents Tutorial for Beginners | How to Build AI Agents | Simplilearn
Simplilearn
Full Stack Developer Course 2026 | Full Stack Java Developer Tutorial for Beginners | Simplilearn
Simplilearn
Product Life Cycle 2025 | Stages Of Product Life Cycle | Product Life Cycle Tutorial | Simplilearn
Simplilearn
Project Management Full Course 2026 | Project Management Tutorial | PMP Course | Simplilearn
Simplilearn
PCB Design Course 2025 | PCB Designing Explained | How To Make PCBs | Simplilearn
Simplilearn
Python Full Course 2026 | Python Data Analytics Tutorial For Beginners | Simplilearn
Simplilearn
🔥Top Product Management Skills You Need to Succeed in 2026 #shorts #simplilearn
Simplilearn
SQL For Data Analytics 2026 | Essential SQL Commands | SQL Tutorial For Beginners | Simplilearn
Simplilearn
Simplilearn Reviews | Paving Way To Success With AI & ML Course | Soumik’s Upskilling Journey
Simplilearn
Six Sigma Full Course 2026 | Six Sigma Green Belt Training | Six Sigma Training | Simplilearn
Simplilearn
Learn Snowflake In 45 Mins | Snowflake Tutorial | What Is Snowflake | Snowflake Explained
Simplilearn
🔥ML Career Tip – How to Start Learning Machine Learning in 60 Seconds! #shorts#simplilearn
Simplilearn
🔥Agile vs Waterfall in 60 Seconds #shorts #simplilearn
Simplilearn
Excel Full Course 2026 | Excel Tutorial For Beginners | Microsoft Excel Course | Simplilearn
Simplilearn
What Are AI Agents? | Types Of AI Agents | AI Agents Explained | AI Agents Tutorial | Simplilearn
Simplilearn
How To Create a Product Roadmap In 2026 | Product Roadmap | What Is Product Roadmap | Simplilearn
Simplilearn
SQL Full Course 2026 | SQL Tutorial for Beginners | SQL Beginner to Advanced Training | Simplilearn
Simplilearn
🔥What Is Phishing? #shorts #simplilearn
Simplilearn
Cloud Computing Full Course 2026 | Cloud Computing Tutorial | Cloud Computing Course | Simplilearn
Simplilearn
Simplilearn Reviews | Overcoming Rejection & career plateau to finding a New Job : Bhaskar Banerji
Simplilearn
Six Sigma Full Course 2026 | Six Sigma Green Belt Training | Six Sigma Training | Simplilearn
Simplilearn
Generative AI Full Course 2026 | Gen AI Tutorial for Beginners | Gen AI Explained | Simplilearn
Simplilearn
VLSI Design Course 2026 | VLSI Tutorial For Beginners | VLSI Physical Design | Simplilearn
Simplilearn
Related Reads
📰
📰
📰
📰
O(N) Manacher's Algorithm with Mirror Boundary Optimization
Dev.to · Dipaditya Das
Building a Power Grid Inside Minecraft with BFS Algorithms
Dev.to · Carlos Cortez 🇵🇪 [AWS Hero]
The Run-Length Encoding Trick: How Simple Strings Get Compressed
Medium · Programming
75 Days of Leetcode — Day 4: #238 — Product of Array Except Self
Medium · AI
Chapters (16)
3:09
arrays
6:24
linked lists
11:06
hash tables
18:18
trie
21:26
stacks and queues
22:55
segment trees
26:21
union find
29:30
binary search
31:50
quick sort
33:30
mrge sort
36:21
breath first search
38:10
deapth first search
39:45
dikistras algorithm
42:02
dynamic programming
43:21
KMP
45:57
krushal algorithm
🎓
Tutor Explanation
DeepCamp AI