Saturday, 5 October 2024
Monday, 8 July 2024
Foundations of Data Structures and Algorithms Specialization
Python Coding July 08, 2024 Course, Coursera, Data Strucures No comments
In the realm of computer science, data structures and algorithms are the backbone of efficient programming and software development. They form the fundamental concepts that every aspiring software engineer, data scientist, and computer scientist must master to solve complex problems effectively. Coursera's "Data Structures and Algorithms" Specialization, offered by the University of Colorado Boulder, provides an in-depth journey into these essential topics, equipping learners with the skills needed to excel in the tech industry.
Why Data Structures and Algorithms Matter
Data structures and algorithms are the building blocks of all software applications. They enable programmers to handle data efficiently, optimize performance, and ensure that applications run smoothly. Understanding these concepts is crucial for:
- Problem Solving: Algorithms provide a set of instructions to solve specific problems, while data structures organize and store data for efficient access and modification.
- Efficiency: Efficient algorithms and data structures improve the speed and performance of applications, making them scalable and robust.
- Competitive Programming: Mastery of these topics is essential for acing technical interviews and excelling in competitive programming contests.
- Software Development: From simple applications to complex systems, every software development project relies on the principles of data structures and algorithms.
Course Overview
The Coursera Specialization on Data Structures and Algorithms consists of several courses designed to take learners from basic to advanced levels. Here's a glimpse of what each course offers:
Algorithmic Toolbox:
- Introduction to the basic concepts of algorithms.
- Study of algorithmic techniques like greedy algorithms, dynamic programming, and divide-and-conquer.
- Practical problem-solving sessions to reinforce learning.
Data Structures:
- Comprehensive coverage of fundamental data structures such as arrays, linked lists, stacks, queues, trees, and graphs.
- Exploration of advanced data structures like heaps, hash tables, and balanced trees.
- Hands-on exercises to implement and manipulate various data structures.
Algorithms on Graphs:
- Detailed study of graph algorithms including breadth-first search (BFS), depth-first search (DFS), shortest paths, and minimum spanning trees.
- Real-world applications of graph algorithms in networking, web search, and social networks.
Algorithms on Strings:
- Techniques for string manipulation and pattern matching.
- Algorithms for substring search, text compression, and sequence alignment.
- Applications in bioinformatics, data compression, and text processing.
Advanced Algorithms and Complexity:
- Exploration of advanced topics such as NP-completeness, approximation algorithms, and randomized algorithms.
- Analysis of algorithmic complexity and performance optimization.
Key Features
- Expert Instruction: The courses are taught by experienced professors from the University of Colorado Boulder, ensuring high-quality instruction and guidance.
- Interactive Learning: Each course includes a mix of video lectures, quizzes, programming assignments, and peer-reviewed projects to enhance learning.
- Flexibility: Learners can progress at their own pace, making it convenient to balance studies with other commitments.
- Certification: Upon completion, participants receive a certificate that can be shared on LinkedIn and added to their resumes, showcasing their proficiency in data structures and algorithms.
Who Should Enroll? Foundations of Data Structures and Algorithms Specialization
This specialization is ideal for:
- Aspiring Programmers: Beginners looking to build a strong foundation in data structures and algorithms.
- Software Engineers: Professionals seeking to improve their problem-solving skills and prepare for technical interviews.
- Computer Science Students: Individuals aiming to deepen their understanding of core computer science concepts.
- Tech Enthusiasts: Anyone with a passion for technology and a desire to learn how to solve complex problems efficiently.
Conclusion
Mastering data structures and algorithms is a crucial step towards becoming a proficient software engineer and problem solver. Coursera's "Data Structures and Algorithms" Specialization offers a comprehensive and structured learning path to achieve this mastery. With expert instruction, interactive learning experiences, and the flexibility to learn at your own pace, this specialization is an invaluable resource for anyone looking to excel in the tech industry.
Tuesday, 9 January 2024
Python Data Structures
Python Coding January 09, 2024 Coursera, Data Strucures, Python No comments
What you'll learn
Explain the principles of data structures & how they are used
Create programs that are able to read and write data from files
Store data as key/value pairs using Python dictionaries
Accomplish multi-step tasks like sorting or looping using tuples
Join Free: Python Data Structures
There are 7 modules in this course
Saturday, 16 December 2023
Object Oriented Programming [OOP]
Python Coding December 16, 2023 Data Strucures No comments
Basic Concepts:
a. Define what an object is in the context of OOP.
b. Explain the difference between a class and an object.
Encapsulation:
a. Describe the concept of encapsulation and its benefits.
b. Provide an example of encapsulation in a programming language of your choice.
Inheritance:
a. Explain the concept of inheritance and its purpose.
b. Differentiate between single inheritance and multiple inheritance.
Polymorphism:
a. Define polymorphism and explain its types.
b. Provide an example of compile-time and runtime polymorphism.
Abstraction:
a. Discuss the importance of abstraction in OOP.
b. Provide an example of abstraction in a real-world scenario.
Class and Object Relationships:
a. Explain the difference between a class method and an instance method.
b. Describe the concept of composition in OOP.
Interfaces and Abstract Classes:
a. Define an interface and explain its role in OOP.
b. Differentiate between an interface and an abstract class.
Design Patterns:
a. Discuss the singleton design pattern and its use cases.
b. Explain the observer design pattern.
Exception Handling:
a. Describe how exception handling is implemented in an object-oriented language.
b. Discuss the importance of try-catch blocks in OOP.
Object-Oriented Analysis and Design (OOAD):
a. Explain the phases of Object-Oriented Analysis and Design.
b. Discuss the importance of UML (Unified Modeling Language) in OOAD.
Generic Programming:
a. Define generic programming and its advantages.
b. Provide an example of using generics in a programming language.
Reflection:
a. Explain the concept of reflection in OOP.
b. Discuss situations where reflection can be useful.
Saturday, 17 August 2019
Data Structures- Leture 4
Lecture 4
Stack Representation
Let us start with how stacks are represented. So stacks are represented with a node in the linked list with the node containing data. That is what is to be represented and link pointing to the next node. And the also you have and access to a stack throw a node. Which is designated to a stack and also maintain the count the no. of elements of the stack. Now first think we going doing is create a stack. To creating a stack, you have to first dynamically the allocate a stack. Who size is equal to the size of the stack and if the stack top is equal to null. When that is what you are doing. To the initialize the top and we are also since creating the stack. And any top initialize equal to be null and count to be equal to zero. You are not a actually create a node. This is first step in creating a stack. So once you created a stack we went to do the operation from stack. Important operation has push already seen push operation. This is if you look at linked list representation of stack. In the push operation similar to inserting a node in the front of a list. Because already operations are done with a stack at the top of the you can access the stack accessed to throw only the top. Insertion and deletion when you represent a stack as the linked list is in the front. So here. Same as inserting a new element to the list before the first. So let us assume that this is the element. You want to insert and this is the previous stack. So previous stack has this is the count and is the top. So top is pointing to the first element in the stack. Are you wanted to insert the new element? First to create an element for the node. And this is the address of the node. And this is containing the data red and pointer next. So that’s what is available. When you are going to insert this into the stack. It’s come like this. Now this is Pnew and which know this is address of this. You create next. Change the next pointer to point to the address of blue. And change to things top to point to address of red and increment the count be equal to 3. So this is insertion of push operation. We don’t call it insert in stacks. We call it push operation. Push into the stack. Which is represented as a linked list. So this is the push operation. The code for the push operation so first thing will you do introduce create a node. In that node you creating a node. You have get it from the allocated area. If there is no allocated area. That is can’t get a new node. You can’t insert. Once you got that. In the new position you put data. Pointed to that data whatever to insert. And you make the pointer of the new location of the new node. That is to be created.
Pointed to original stack top. And now change the stack top pointed to the new pointer implement top to the point to the new node. And increment the count of the stack by one. And return one. And Return one this is indicated. So this is what we do for insertion into a stack. As we consider to this is very similar to the insertion into the front of the linked list. Now let us look at the next operation of stack. Which is pop. Pop is to delete the element and as you know you can only the delete element from top of the stack. That is the constraint that you have on stack. So this is the same as the removing first element from a linked list. So what you have to do is. This is an original stack. Now the only element you can delete or remove from the stack from and do the pop operation. In this element. No other element can remove. So what you do is. You make the pop. Now point to blue. Ok. That is it. So now you can access the stack. Only. Throw this. Now you have a node which is short of bankling. So this can be recycled. So you make a pointer to Point to this node. So that it can be recycled. So this is the pop operation. So the code for the pop operation. As follows. So you have a pointer to point to the node. Which you want to the return. And if the stack already discussed you want to a deletion and what do you want we consume must. First ensure that the data structure from which you want do the deletion. Is not empty. So that is what is doing here. Just checking the count what whether equal to zero. You saying that will return zero. Which means that is an underflow. That is no element. To be delete it. Otherwise you make this pointer to point to the original stack. This is for recycling purposes. And then what you do is. Make the stack top. Point to the new stack. Top and if free, dlt pointer. What do you going to doing here is, string is the node. That has been deleted. And decrement the stack count and return the value of stack. This is code for the pop stack. Both these cases the stack is represented using a linked list and these particular data structure is very useful. When we are doing for organizing the nodes in an allocated list. It is called allocation list. And these represented linked list. Who store all the nodes are has been deleted are when you want to delete. You store for recycling take allocated list. Which is represented as stack. When you want to insert to take a node from same allocated list. So the next stack top is already discussed before stack top doesn’t change stack at all. Just access the top element of the stack. So again if the count is only greater than zero. That mean stack doesn’t contain anything. Then just take out the pointer to the top element. Make that data to be returned in data pointer and return 1. If it is less than 0. That means no stack. So you return. So that is top. Know hearing to change of the list, this is can normal thing. And empty stack a stack count. So what you do here in. if the count is equal to zero then the return value. Otherwise the stack is not empty. This is a code for Boolean function. This is an empty stack. Which
is return value from the stack is empty. Which is value is false. The stack is not empty. This is return a count. So already maintain the count. There are implementation do not maintain count of the stack. Certain implementation you maintain count .so return stack. That is it. So the count can be equal to zero. The stack is empty. You can also check for full stack. This is assuming that u have decided that only so many nodes going to give for the stack. This is a stack. If you have stack full condition then malloc is failed. If malloc is failed, it means, you cannot there is no temporary node to be given to for the operation. In which case you have a return 1. So this is a full stack. Where you cannot, remember that in full stack condition checking whether there are nodes available for putting into the stack. If there are not saying full otherwise putting full. This is not like an array implementation already allocated the size of the stack. This is the destroying stack Destroying complete stack. So you want to delete all the nodes in the stack. So if the stack top is null it means already stack is empty. You don’t have after do any destroying. So if it is not null. Then you make delete pointer to point to the top of the stack top of the point to the next node and free delete pointer. You keep doing this. Till the stacks it will come. Come to the last node in the stack. The Stack is now empty then the destroy the head node. So free that and you return null. So this here having a by loop. Here this is the logic. Where you keep on deleting nodes of push. Popping of the nodes. Till start becomes. Now what you seen upto now is the some of the implementation of stacks. Where we look at linked list implementation of the stack. In this particular implementation of the stack. What you done is we are assume that you have a count. Also it is not necessary. So in case you don’t have a count the code has to be appropriately modified. Stack Applications Now let us go to next some of the application. Using stack. Very interesting applications. I said used in no.of places in computer science itself. For example, the stack is a particular specific data structure that is used for quick sort algorithm is a difficult data structure. It also used in other applications. Like very important application where you have to maintain the program counter and return address in the case of recursive calls in function calls. So this is very important data structure as well as computer science.is concerned. We are looking at 2 very different application. One is the depth first search. And one is the N_Queens problem. So let us first look at the depth first search. The depth first search actually backtracking type of concept. That it uses. And this backtracking type of concept we do use stack. Stack is a difficult data structure that is used for doing back tracking. So this problem as follows discover a part from start to goal and
the solution you have to go deep. If there is an unvisited neighbour go there then you retreat along the path to find an unvisited neighbour. The outcome is if there is a path from the stack to goal. DFs very finds such a path. So that is going to go deep and cannot enough to do. Go to DFS wise. That is an idea. So this is a difficult application of a stack. So let us soon given a tree and if you want to find the goal. So initialize to start at 1. That is pushed on to the stack. Then you go to two depth number. To get to the child. So push 2. When you push 5. 5 has no children so you go to the sibling with 6. Then Go to child 9. After then you don’t have anything. So Pop it up. Pop is 6 out. Then pop 5 out. Pop 2 out. When you go to the next child which is 3. Then you go to 7. Then you go to 10. That is depth first we go to 10. Now you have identifying the value. So that the path followed 1,2,5,6,9. Then back tracking up and then go to 1. Find the next child go down. Ok. That is the path followed by the depth first search. So let us algorithm for the DFS. So the stack is first initialized. And you stack the operation look at push start. Now while the stack is a not empty. This is keep track. You data in the top element. If it is the goal you just put access. If T has a unvisited neighbour. Choose an unvisited neighbour n. Mark N as visited and push n into the stack. Otherwise that is if doesn’t have a unvisited neighbour. When you backtrack take in the next node from the stack. Keep doing this. Till stack is empty. Are you reach the goal? So this is the DFS algorithm. Of course you searching the node in a algorithm you can also happen that here may be a failure. So this is a difficult application of stack. Where the stack is used to maintain the node. When we want to do the DFS algorithm. As specially backtracking algorithm. This is a difficult data structure that used many concept used back tracking. Also used stack is a basic data structure. For implementation purpose. N-Queens Problem
Now you going to look at what is the N_Queens problem? This is a difficult problem in artificial intelligence and the N_Queens problem is actually problem associated with the chess board. So in this lecture I will explain the problem and then how it is solved using the stack. OK. So first let us see what the problem is the NQueens problem can be defined as follows. It is a backtracking problem to solve the NQueens. Suppose you have 8 chess queens & and a chess board. Can the queens be placed on the board? So that no two queens are attacking each other? Now what do you mean by attacking. We will see that as we go long. So the problem is this. Two queens are not allowed in the same row, or in the same column. Or along the same diagonal. So that is the idea. So 2 queens are not allowed on the same row, and the same column, or along the same diagonal, the no.of queens and the size of the board can vary.
Normally use all this problem for the NQueens problem. We are going to take it can simple example and show you. But basically solve it for any queen. It after all chess board is the square. So you can 64 * 64. Where N = 64 and so on. So basically NQueens can be represented this way you consist of NQueens. And chess board that you have consist of N rows and N columns. So your aim is placed NQueens on the boards. Such that if you have a queen here. We don’t have queen anywhere here and also don’t have anywhere queen here. So you gone queen same diagonal on the same row, same columns, along this same row. That’s the problem so are idea is to try to find solution to this problem. The computer program to solve this problem. Program tries to find a way to place N queens on the N * N chess board. Following the instruction we already seen. Now comes the application of stack. We going to uses a stack to keep track of where each queen as already been placed. So first place a queen on the board. The position of the new queen is stored in a record which is placed in the stack. And also you have an integer variable to keep track of how many rows have been filled so for. So these are two things that a going to use keep track of how to place the NQueens. So the is how the program works you have take 4 */ 4 board in very simple example to show the how the program works and this is the no. of queens to be filed. Which is 4 and this is stack to be used. Stack contains record. Which gives the position of the queen. Which is 1,1 is the position 1,2 mean this 1, 4 means first row , 4th column and so on. And this is the variable. Which keeps track of how many queens have already been placed. OK. This is the way. This is the complete show. You have a N * N board. You have NQueens, you have a stack. Which give the position of queen and you have the no. of queens that mean placed directly as the program. Now let us start the program. So first you place 1 here. Then you come do this what happen so that is 1,1 has been placed here. Then you come here. Now can you placed queen here, you can’t the queen placed here. Because along it a same diagonal so the logic uses that you shift it once to the right and see whether breaks it in a rules now that is no queen along the column, that is no queen along the row, that is no queen along the diagonal. So this is allowed. Now you have a queen at 1,1 you have a queen at 2,3 and 2 have been filled. Now we are to place this. N row you can place it here. Can’t place it here. Because if it is in the diagonal. So what you do is? Go up here and place it here. can you place it here 3, 4 so 3 rd row, 4 Th column you can’t place it here. Because of the fact at that along diagonal. How the program works? When we run out of remove in or row, pop the stack,
reduce filled by 1 and continue working on the previous row. Let us look at that. What is mean these? When you can’t place, pop it off. Go to the previous row and you see whether place it along that. Along the right or left. You will see the logical as we see go long. Again I tell you. When we run out of room in a row, pop the stack, reduced filled by 1 and continue working on the previous row. Whatever you placed in the previous row, here are having so ok. That is what is happened here. This is r th position. We still have to queens 2. And reduced filled by 1. Now we continue working on row 2, shifting the queen to the right. Now instant have it here. We pop it up. And shifting the queen here. Now thus has to been incremented this position has no conflicts, so we can increase filled by 1, and move to row 3. So now we move to row 3. Ion row 3 what happens, we can’t place it here. Because diagonal. So placed it here. And then we go to 3 one. And this is the conflicts. We stack again first column conflicts. Second column that is no conflicts. So that is how we so along to the problem. You can work it on row. You see how 4 queens are filled. So the logical basically to be repeat. That is you take the row placed a queen there. Then you go to the next row place the queen there. When conflict arises. What you do is? You tried to push the queen to right. If it is possible and you know no conflicts arises. If you come across a conflict then you pop the top element from the stack. That’s you are a backtracking. You are not using that. Already placed it, removing from the stack. Which remove it. And try again to reworks on the previous row and that’s how you do the queen. Nqueens problem. So for are nqueens problem. Let us see this is slightly different from the problem. That mean normally used. We are going to first talk about the pseudo code.so here what we do is. We first initialize the stack. Which is date structure. We want to use. Keep track of artificians and we also place the first queen. Pushing its position onto the stack and setting filled it equal to be 0. This is pseudo code repeat these steps. If there are no conflicts in the queen then we do else if there is a conflict and there is room to shift the current queen right ward do it. Else if there is a conflict and there is no room to shift the current queen right ward then what we do. You have do keep on doing this. Repeat these steps. There are no conflicts increase filled by 1. If filled is now what then doing here and take this each of the steps and giving the details. If there are no conflicts with the queen what we do increase filled by 1. If filled row is now N. That means filled all the queens then the algorithm is over. Otherwise, move to the next row and place a queen in the first column. So that this steps is over. So what we and done is. We done this. If you take one queen ok. We are placed it the first in the row. We see there is a conflict. Then there is a conflict moving a right. If there is a conflict and
there is a room to shift the current queen rightward. Move the current queen rightward adjusting the record on top of the stack to indicate the new position. So, this is in the same row. Even that you can’t do. Position where you have can’t fill the there is conflict. Can’t move rightward and fill. Because there is a conflict again. If there is a conflict and there is a room to shift the current queen right ward. This is place to have do a back. So what you do. You keep popping the stack and reducing filled by 1. Until you reach a row where the queen can be shifted rightward. When you shift this queen right. Then what you doing is. What ever done before you backtracking. Can backtracking till you reach the position? Where you can have another alternative. Which is not placing that. But moving it to the right. If it is possible. So the movement to the right once step of the time. But you move one also. So that is the NQueen problem. By the NQueens problem is very challenging is that. We are actually redoing the work. We already done. So that we get the choice of what we doing actually in the algorithm is we first start with the easiest method. Placed the first row that we see. Then we keep on doing it till the and the second we can take is every ok. When I placed in that place there is a conflict. So I will let move right to see. If you move to right and see, fill a conflicts. So I will let more right to se. If you move to right and see, fill a conflicts. Only then I go back. And I check whether. What I will done can be changed so that’s can be accompanied. You can properly try thus for 6 * 6 or 4*4 on your own on. Similarly act how it works. That will be a good exercise for you. When you for you do understand. How the stack works and how backtracking algorithm work also. That is explain both the concept of backtracking as well as the application of stack to backtracking. Now let us look at some problems. Associated with stacks. There is know up to implementation of stack.
Data Structures - Lecture 3
Data Structures - Lecture 3
Data Structure
Lecture 3
STACKS Stacks are a very important data structure and are necessary for implementing the logic behind many programmers. So let us look at start at the end of this lesson. we objective of this lesson this to introduce the concept of this stacks and then look at the operations of the stack and then the applications of the stacks these are thinks we going to talk about in this lesson before we go to on to the complete aspect of stacks as you know there are stacks every day in our life like stack of shirt, stack of books and stack of boxes and so on. As you see the idea is that normally when you take out the first shirt you take give be the top shirt of this stack and so on. So these are otherwise (57 sec) fall down and this catch in very carefully the same concept in applied to stacks in data structure. So this is the typical application of stack there will have stacks of book and stacks of coins at the same think represented in computer stack. Computer stack has gone to number of object set of placed one on top of other in a sense so another common linear data structure that I already talk to you about is stacks one you already seen its list and in one way the stack is nothing but the list but getter lot of restriction of how the list is used, then it became a stacks with the stack we have restricted to the access to the list to one end we take out the element from the stack using the pop element and we push element in to the stack using push operations. So the result of this restriction is that the list pile one on top of the other so basically talk about stacks we talk about when we what is call the last in first out policy. To get to the bottom item, we must first remove all the items above it another words so the behaviour is sometimes described as this is the policy we that talk about which is called is last in first out. So whenever you think of stacks you must think of it has last in first out whatever you put in last will be taken out first are so it’s called a LIFO and this is because I already told you that last item put in the stack the item removed first. So elements can be added and removed only at one end this end will call as the top of the stack with this stack the top item is always the last item to enter the stack and it is always the first item to leave the stack because no other items can be removed or added on to the stack without affecting the top element so let’s look at some terminology above the stack so the depth of stack is the number of elements it continues so suppose you have ten elements this stack it’s deep ten and you say that there are the depth is stack is ten and normally as obviously an empty stack is get a depth is zero. So why to be used a stack. Stacks provide a very efficient storage structure for manipulating data that is last in first out policy and stacks are often used as temporary storage to speculate the solution of a problem. So stack are restricted linear list as already told you of where
additions and detections are made only to the top and what happened is because of this specialization are restrictions that we do on the stack we can implement the stack using link list and we can also implement the stack using arrays and we think of ways in which in efficiency of the implementation can be improved. So as before you just seen basically what I stack data structure is you must remember that stack data structure is that restricted types of list and its follows the last in first out policy all access to the stack is to through the pointer call pop and through the top you can instead element and delete elements and the last item which has to be which has been instead the first item that is to be removed. Now let us look at all the operations that you can do on stacks. So first operations the do on the stacks .what is called a max item. Max that is nothing but the maximum number of items that would be on a stack. Now before you going to details about this that what the meaning of max item depends on the implementation of the stack so if it is arrays implementation. You already discuss array implementation they will be maximum size of the array and that will be the maximum number of elements you can put in the stack but how many elements has actually we put is the max item and item type can vary it can single and simple integer are we can a structure and we can as we saw list san be any data item they others are make empty that is an operation that make a stack completely and you can also have a Boolean operation call is empty that is to test whether the stack is empty or not similarly you can have Boolean is full the test whether the stack is full this actually make sense only you can talking about array implementation and next you have push (X,S) this is to add push an element X to the top of a stack S and then this is the function as this is the adds X to the top of the stack and the pre-condition is that in order to push in a element to the stack. The stack should not be full and the post condition is at after the push operation the element X becomes the top elements of the stack next you have pop S this is nothing but up to delete element an a stack it’s call pop the top most elements of from the stack and the functions of obviously its remove the element stack and return the item and the pre-condition has for any deletion operation for that can be matters this stack should next be a empty it has to be initialize and it has cannot be empty if it’s empty the pop operation is become un defined the post condition is that the top element would have remove from the stack and copy of item will be available and the top has been modified then you have something call has top S the stack S has it is hear is axis to the top most element of the stack hear no change occurs to the stack and only the top most element you will get the value of the element that’s it . So let us go little more in details about the operation of the stack so you have first the push. Push is add and item and the problem here is that you can over flow suppose you say the stack in contain ten item and it’s already full within ten item then you try to added another element eleventh element then the stack is overflow condition occurred this is the only for the array implementation and for the pop element you remove an element you can have already total you can have a underflow and the stack top is what the top is stack so this is the pop operation you end element and this is the stack pop operation where you take out it so let’s take this more in details so you have the take this more in details so you have the data that you want to push on the stack this is the initial stack of the stack. So for example the stack has to element and assuming the stack starts with the top is equal to one here you have the top is equal to two so now when you sit what happened is this the element data is pushed on to like this the top increment is one and the element stack size increases. Now let us assume we want explain the pop operation as you already know it moves data element from top of the stack initially the stack has three element and top now points to three when you do a pop operation there is no questions of which element to delete you can only delete the top most element the way the stack is defined so what you do you give the pop operation the top most element is deleted that is return and top reduces by one so this is the pop operation. Then look at this operation this is the stack top operation you don’t have any change in the stack. Stack has three element and also a three element top value here is three here top value is three and only think is you are able to access the element and value is given out please not when I say top is equal to 1, 2, 3 am assuming the array on the stack is which is told in a array and top start from one it’s not necessary you can start stack from hundred you can array location hundred and you can also store stack in link list then the meaning of this is different it here is explain it’s so you understand what the operation is this so let’s look at simple figure here if you look here in this step one you have the empty stack and given a data that you want to push on the stack now what happens here you will note the tope is equal to zero and the stack is empty now incremented top by one and pushing into green into the stack now this is the new condition is the stack is end. Then with that you add another element which is blue here so now top becomes two and belay pushed on the stack this is the condition of the stack after the second push operation then what you do you go to the see the pop given the stack of the stack if I just give pop there is no questions of which element is pop because pop the top most element so what happened after the pop operation blue comes out and this is new condition of the stack where top is been decremented by the one and blue is no longer present in the stack then next let’s see if you want added another element that element is push this is similar to at do it here and top increments by one then doing a stack top operation here what happens the state a stack is before and after the operation is same but only think if you can access the element then this operation and this operation is the same you just removed a element and here also you doing pop operation . you see here that is green has been removed that is top most element
from the stack has been remove the stack is empty now if you give pop operation there is error in the condition because the stack has is empty .so let us look at stack as an abstract data type so that means we are not bother about the implementation we going to using this stack so basically for any stack. Whatever the implementation the following at the operation of function that associated with the stack so one is create this means you just create an a empty stack for the implementation then the push you seen in of about the push. Push means added an element top of the stack then you have pop which means pop an element from the top of the stack you don’t have to specify the element because only think at pop from the stack is top element then stack top which you already defined that is you are accessing the top element of the stack no changing in the stack that is the top remains in the same number of element in the stack remains the same then you can also have full condition the question mark that we put here is you cannot check a full condition when you do a link list implementation of a stack because you can keep an adding notes dynamically but fill make sense in the stack is implemented as an a array and then empty is when the stack is element that is does not contain any element so this is the stack in empty condition so you can just look at this small data structure of this so you have a external interface you have a data structure and can have the data here so this is the data you want to input in to the stack this is just giving feeling of what is available outside. The outside is when you doing push you have indicate which element it is X. which stack you want to put it and similarly when you defining the stack you have to also know the access point that is top of the stack so one typical application of a stack is the famous parenthesis matching or matching of brackets so what it do here this you don’t have a matching parenthesis here so what it do you input when you see the traverses list from this corner when you see the bracket you put it in the stack then you see the other bracket . Put it the stack then you see an a just pass it don’t be anything you see plus B don’t be anything then you see the closing bracket. So you look at this stack and C whether whatever you have top of the stack matches this if it matches you removed that so now you left with is one bracket one that we put here then you see a divide sign don’t be anything just pass it C. don’t be anything then you finished you come to the end of the expression when you come to the end of the expression if it was matching expression. You should have add the stack is empty unfortunately now the stack is contain the single bracket so you know that the equation has not brackets have not been matched if you look at this same think you can do it surffency you see that this you will put on the stack. Then here you will you put on the stack again are left with closing bracket that is not matching so here are matching we a put in this on the stack then you putting a open parenthesis and the stack then you have a matching closing parenthesis which will cancel each other that will left with in
open parenthesis here you will left with the closing parenthesis but however you do that always you should have the stack is empty then only it’s matched now in this example you take on simple example there is only one type of bracket you can have any type you can have square bracket and check the corresponding matching.
count is equal to zero and the stack max equal maximum number of element. So next let as look at the push operation so the push stack you have when you remember when I told you told that you have a push stack operation you have two think as to define one is the stack array which is the array in which you want to push into the next is data element that we want to push so first for any push operation infect this is two five any in session operation you have first check whether there is place to instant the element in other words. So for that we are doing a stack check full stack check. So here what you doing is if the count of the number of elements is equal to the maximum number of elements is stack can hold then we are returning zero let us it is over flow and the number of elements in this stack equal to the maximum number you can hold and you cannot add any more elements otherwise when you come out this it means that you have to place the hold elements but in case what you do is you increment the count so the number of elements in the stack increases by one you increment pop by one because now want to create to a place pointed at to this top, there you want to inset the element and then what you do you with array at the position calls top you inset the elements that you want to inset and you return one . just this indicate that the push operation has been success if it already full then you did have return zero which means that there is the problem there is an error and this condition the error is a overfull. So this is how you do please note here we are first incrementing talk to create place and then we are putting the element into the top position so next let look at pop operation again as you know in any deletion operation you should have something to delete so in deletion operation you will get an under flow the same is true for stack. So here what you do you given a stack given data output pointer this is the data you going to output and given a stack you can you did not have the as in input parameter you can gives the stack and you can delete from that but here want to get out what is top on the stack for that’s why having the extra parameter some pop operation implementation do not look at this is a separate parameter inside the pop operation. One of the example. We saw people we did not have to parameters for the pop – operation. So here what you do this please remember this is array implementations? So what you do is you first. Check whether stack is empty if it is empty then you cannot do a deletion operation, became you don’t know anything to delete. So you getting underflow condition otherwise what you do is you have to take out the them the list of the stack so what you do the access is top element of the stack and take it out is the variable call data output points and decrement the count by one because round in the count number of element is decreased and decrement top also by one because previously whatever top is pointing to is now a empty so end don’t want to access is you will decrement all and return one indicate one it is successful operation this is the top operation this function retrieve the data is the top of the stack without
changing the stack so again as we already saw pre-conditions stack is pointer to the stack and post return one its success zero is under flow so have what you do is we have the stack again and this is the output pointer as we did in the pop operation so it the count is greater than zero than only you can do the operation. If it is can then zero you don’t have to access at all because these stack in empty you don’t have a element so it is next zero that this then element greater than zero that is element so you just take out the elements not take out you just access the element but remember no top changing nothing change is the count does not decrease nothing happens only think is accessing the top element so hear after the top operation this stack remain same is as already told you and returning zero this return zero is if not able to do the operation because of count being not greater than zero which mean that’s the stack is this is the condition check whether the stack is empty as next so the pre-condition is stack is pointer to the stack and post condition is if returns one its empty and zero is there is data is this stack so here what you do is again the input the stack and you that’s the structure stack. If the count is equal to zero that means is an empty stack. You just Boolean you will return the value that is true value similarly full this function determine the stack is full so fully detained as heat full ok heap full for latter so pre stack is pointed to the stack head note suppose if return one heap for stack is full and zero is heap as room what you do here is this is full stack condition again we have the complete structure now here because its and array implementation then you know the stack is full then the count is equal to these stack max so if count is equal to these stack max so if the count is equal to the maximum element the stack in held then we know that the stack hen full then you return the value now Growable tray – based stack this is the slightly difference diversion of what will apposing to say In a push operation, when the array is full, instead of throwing an exception, we can replace the array with a larger one. How large should the new array be? Incremental strategy: increase the size by a constant C. doubling strategy, double the size, what you mean by here is we docent usually know cannot predict how much the size of stack will be now the problem here is that you have if you put stack is 1000 elements are using one 10 or 15 eliminating wasting are memory resources are then have you put is or 10 elements you against to 20 or 30 elements then you concisely you will getting a stack full condition. So one we doing this is have global array stating what will you do is if you get stack full condition that point you reallocated larger array and then put all the stack elements is to that array so this is not a very simple operation. This is changing of elements from one array to other bus assume that you can do that but two strategists of how the largers array allocated how much of how much should be one think you going to suppose the original stack size is 10 and you a have stack full condition you can increased by constancy size 5 and every time to get a stack full condition keep
increment, increasing it by 5 please not this depends of the explication purely on the application. How you have a doubling stratarge Initially I will put 10 I will act put 10 and then came now will have stack size of 20 again can put 20 and so on. So this is a predict. So depending of the application you do this now we go the next type of implementation plus please not but when I said we going of global array after you stack full condition is array happen when you allocate a larger array that is the lot of completion on work needed transfer this array implementation of next array implementation. So this not to travel operation so this not to say that global array is a solution to the problem of using of array stack operator so next implementation in the link list implementation. So here what you do is you have to understand the concept of an abstract data type again you already seeing this and you need to see understand nested implementation and you need to see some application of link list so every data of course touch a goes also top link list implementation of stack. So this is the typical link list implementation of a stack so here you see that this is conceptual view here the conceptual view of whether you implement of the stack using link list are whether implement the stack using array conceptual view is same but when you look at this now what you have the bottom most element will have the link pointer to be equal to zero and then you have the next element pointing to this element pointing to this, this element pointing to this and count is the number of element in the stack before and top now giving the address of the top most pointer, this link is given the address of the next top most the bottom most element. The address link will be equal to zero this is the link list implementation of the stack. Now let’s look at this is no count this is the top this is the before you create a stack now look here you are incremented. This is the a creating a empty stack so what happened this you have count equal to zero and top pointing to null still the stack is empty you just created a stack now let us look at push operation now what happens the count is zero the top most equal to zero now what am doing am creating a node to put green this is the same operation what we saw when we did link list implementation of a stack so what happens after this green I have to change the address of this stack from null to the address of this node and this next here has to be null so next is again a push operation now this has to be now node has to be created and please note that is new node will come here because now this is we comes the bottom most node and the top has point to the most reason node and top most node now what will have to increment the count by two this buy will point to the new node and the next of the new node will pointed to the previous top so this is what happens is the blue has to be removed so now top will point to green again and blue will be removed it’s blue will be entered here and blue will be removed from there so if you want to distributed stack what you do this you make a count zero. If you don’t have any point of from top address of
Data Structures - Lecture 2
Data structure Lecture -2
Tuesday, 30 July 2019
Data Structures - Lecture 1
Lecture 1
Data structure is a systematic way of manipulating data. A data structure structures data. Usually more than one piece of data and we have to provide legal operations on the data and the data can also be joined together. That is it can be collection. Basically data structure talks about two aspects. One aspect is data organization and other is manipulating data. In fact manipulation of data, how we want to manipulate the data and how do we organize the data. Results in different data structure that we going to talk about. All of you are some of you have done computer programming and they you have used programming languages and there are some data types that are called primitive data types. For example and this holds a single piece of data in java are may be in ‘C’ most programming languages built in data types called int means integer, char means character ,long stand for long integer and Boolean means Boolean values. There are some Legal operations which is stress for this built in data types like for example for integer: +,-,*, /. Because of the coming of object oriented programming languages abstract data types are get a lot of importance .We talk about data types we also talk about abstract data types. Abstract data types are like a black box. An abstract data type (ADT) is a data type together with the operations, whose properties are specified user of the abstract data type does not have to know what particular implementation used for implementing that particular data type. When we look from data to data structures actually the machine store only binary data. So that what we can see the figure and then you have primitive data types. For example 23 which is an integer 3.1415 which is a decimal and ‘A’ is a character and then you have some basic data structures like arrays and structures used to store the data types and then have a high level data structure like stack, queue and list. Stack, queue and list are data structures that define so that does particular operations these types of data structures. We talk about data to data structures actually as we all of you know data stored in a machine in the form of binary bits and that’s what machine level data storage and then we have primitive data types that are provided most programming languages like integers, floating point 3.145 and character like A and then have basic data structures that are also provided in programming languages like arrays and structures in addition to this we have high level data structure which are special type of list and structures like stack, queue and list. When you talk about data structures there are two types of data structures one is linear data structure and another one is non-linear data
structures.
Linear structures
Array is common linear data structure. Most important concept of array is that the size of array is fixed. Linked list is a variable size. Then you have a stack is very common data structures. It is a restricted form of list where we can add and delete from one point on top of the list. Then we have queue add to back and remove from front. These are ordinary queue. Priority queue add anywhere remove the highest priority. Other important types of data structures which is very necessary for many application of computer science and one such as a hash table .The hash table commonly used for compilers , storing of variables names compilers and so on. Hash tables: unordered list which use a 'hash function' to insert and delete. A tree is a very important data structures. It is unlike most of the data structure since it is a non-linear data structure because it has a branching structure. Graph: Graph is a more linear type of data structure than the Tree. Tree has no loops. Graph has less stringent connection conditions there can be loops in that. When we talk about data structures talk about the data organizations then addition to the data organizations what manipulation you can do with this data types its very important concept. Necessarily to some of the operations you normally do in data structures one is creating an empty data structures. Create an empty list. Give a list we have Determine whether a list is empty. Determine the number of items on a list. Add an item at a given position in a list. Remove the item at a given position in a list. Remove all the items from a list. Now actually what are the actions doing have a half a do depends on the application. Some applications just we do look at only addition and deletion. Certain application you do have to find a list is empty. So operation and combination of operations depends on a particular application that you want to a data structure to have and another important operations are data structures. Another important operation of data structure is to get the item from a given position in a list. Accessing on elements in a list very important operation so in a sorting and searching in any application. For example counseling that you have in Anna University and certain other application. Sorting of the ranks and searching for a particular student then list is a very important operation and mostly all these occupied searching and sorting frequently used operations of data structure. Some time you need the capacity of the list data structure what is the total count of the elements in list. Some time you have needed to modify, update, delete and insert in list. Generally you say that for most applications. This type of modification is not accessed common as action. If we look at the data
structure you can also think of a matrix as a data structures. Linked list as a data structures, a tree and network as a data structures. How this is implemented in how this is represented. LIST: This is the fundamental data structure in computer science and this processing is considered as one of the most important data structures. Infract has been the inspiration for the particular type of programming and language called Lisp. List of integers is the most widely used kind of list and that can also be set or collection of instance. Examples of list are 0,+1,-1,+2,-2,+3,-3 is an example of integer list. We can also have the Days of week = { s,m,t,w,th,f,sa} and sometimes it is not necessary that all elements need to be same type. Instances may or may not be related. {Apple, chair, 2,5.2, red, green, jack}. There is no connection between elements of the list back but tree still that also a list. In many ways list can be classified. But most important classification is unordered and ordered list. Unordered list means insertion list are not in any particular order. Sorted order it could be an alphabetical, numerically but the way in unordered list. Ordered lists are very similar to alphabetical list of employee names. E.g.: The rank of student exam and so on. Difficult example of ordered list. These ordered lists keep items in a specific order and so most manipulation depends on one this order list. When ever an item added to a list. That has to be placed in correct order and similarly when you remove an element from the list. Still have to remain in sorted order. Linear list: Example of linear list. It is a sequence of elements. There is something called as a first element and last element and if you take an every element it has a previous and next element is obliviously there is no element before first another is no element in after the last element. So for an example you can represent list. Linear (or ordered lists) It could be a linear list or ordered list of the form of each row to e0,e1,e2,..en-1 and assigning that n is finite. And size of the list is obliviously n. e0 is the zero. Here if we look e0 is the front e0 is the zeroth element of the list. En-1 is the last element and ei always precedes ei+1 succeeds en. So there is definite relation between elements of the list. Especially in the case of order list. Example of linear list is Student in some particular course. Jack, Jill, tree, henry, Mary and Judy. Please note that this is not an ordered list. Linear list examples Students in comp 2210 = (jack, Jill, able, Hendry, Mary, Judy). OPERATIONS ON LIST:
First create an empty list. We go and look at each operation in detail as we go long. So create an empty list. Determine whether a list is empty. Get the item at a given position is a list that is normally called as retrieval. Determine the no.of items on a list that is count the item of list. Then given an element finite index of an element. Then traverse the list you want to find the all element in the list. Add as item at a given position in a list. Remove the item at a given position in a list. Remove all the items from a list. You can thing a may such operation depending on an application. But which are discussed some of the very common operation do on any list. So first we look at create an empty list. First look at a create (list). Create (list)
In description is creates a new empty list and the inputs are either it can be no inputs are and i want to create an integer list. Types of elements are list integers are character list or character and output as an only empty list no specific output is given. If we look at this result is a new creating an empty list? You have specified in size. You may have specific the type and you may have want to specify something else also. Is empty () .You have found whether list is empty or not. So input is obliviously in the list. Output is it a Boolean output. True if one list is empty and gives false if the list is not empty and the result is after still list is remain unchanged. Important operation of the list or linear list is getting an index. Get an element the input is getting in element which has specific an index. L=(a,b,c,d,e), this an example list if you give get(0). Remember that list is start from 0 to n-1. When you say get(0) you get a. when you say get(2) you get c and so on. If you give index that are not valid like -1 you get an error and 9 though it is a valid integer. It is not a index of the list. Maximum of the index list is e0 to e4. Here so that gives an error. The index is given an index want to get an item from the list. So the input is an index. The item to be got that an index. Output is return to the items at the specified index and it throws an exception if index is not valid. But here result for list is unchanged. Throws an exception if index is out of range. The result is remaining in unchanged. Retrieval means which we just discuss. Suppose i give this and i want to retrieval the element called dog. I don’t know for examples are given index is one. It retrieval dog for me. List at the top and the bottom do not change. Only for that particular index taking are data element and showing it the use. Size and indexof: Size means determine list size. For example if given L is a,b,c,d,e the size of the list is 5. Important one is index of the element. Here unlike the previous one. When for example given a list a,b,c,d,e given the index of d is 2. Given the index of a is 0. The index of z is -1. Because is not there. The index of d is actually here 3.
Traverse
Traverse is finding all the going to list and get out the elements in particular order. When you say get first you gave an input. Get first (list) - returns first element of it list. Get next (list) returns next element if it exists. Both functions will return null if there is no data at all. Otherwise calling get next in a loop we will get one by one all elements in the list. Linear list operation first one is inserting. You adding given an index add an element and adding an element into the array. So function answer an item to list and the pre condition is list has to be existing. The list should not be full. Give a more explanation of full as we go long. And assuming the no duplicates are allowed. If the item is already in the list does not allowing insertion the element. The post condition is after insertion operation will be in the list. Suppose if we have list L is a,b,c,d,e,f,g and give an add(0,h) 0 is which are index to be add. L is element to be added. Then this will be a result. L=h{a,b,c,d,e,f,g). Please note the index of a,b,c,d,e,f,g has increase by 1. Value to be provided before the insert an add operation the index of a is 0. After the add operation index of a is 1. Similarly, that when we have want to add to the front of the list. Suppose if you want to add in the second position 0,1, & 2. So here add (2,h) now the index of c,d,e,f will not change or increase by 1. Again complete elements after insertion operation shifted or moved by one place. Suppose if you give add (10,h) the 10 does not exist in the element . That the no of element is <10. Then will get an error and given an (-6, h) also will get an error. Insert list, data -> new list Let look at insertion operation. I want to insert an element which is called 25. And i want to insert it. Add the second position. So what happen in the initial list is having 10,20,30 and data want to add 25. And it has been told to the i want to added after 25. After the insertion operation i get 10,20. 25 & 30. Now have be 25 is added to a list and get the new list. Next is removing. Specifications (Remove index)
Remove an element from the list given an index. Remove an element from the list. Input which an item which you want to remove. And index of an item. And then if an item out of range. If an item is valid has to be removed. An all item in the list will have moved position ok decreased by 1. You will see the example so this is about previous saw about removal next is deleting. Remove and return an element with given index. Remove an element delete the element whose key matches the item's key. List there are some pre condition are delete. First if you have to a list and the key member of an item has been initialized and there are assuming again no duplicate if you find an item finally 1. So item's key will be nothing to only one element. Post condition is delete is key element matching is
key element. So suppose if have a,b,c,d,e,f,g and is given remove 2. Please remember index is 0,1,2,3,4,5. so remove 2 means if will return c. And list will change. Now a,b,c,d,e,f,g and now what has happened is d,e,f and g all the index is d,e,f, and g has increased by 1. If you take an example of this particular list blue, green, red and yellow. And you want to delete an element which called red what will happen after the deletion operation. The list is been blue, green and yellow only the output given red because the red has been deleted. Other operation is remove all. Removes all the elements in the list. Input is none and output is none after you finish the operation the output comes out to be empty. Example for this kind is phone book data phone records. The normal operation you want to do on the list add to an empty list, remove an entry, and look up someone’s phone number by name. Name will be given we have to search for that particular name and number. We have to find the list of all the phone number for one entry at a time this like a traversal and get the number of entries is like a count. Add, remove, retrieve, traverse and get the number of items. Here the details are normally in the phone book entries are stored in alphabetical order. Another is shopping list to do list schedule. Normally there are some order and when we talk about items in a list they of the same type. They will be either integer or they will be names of people or they will be name and phone number and so on. And the variation of list include what order you have. For the same list you have alphabetical order and numerical order and what are the types of element in the list and what are the common operations you want to do. Depending upon the application it may vary. What can we can do with the linear list is we can delete element, insert element, find an element and we can traverse a list and so on. You can sort by numerically alphabetically you can do any type of sorting. Classification of list When you look at this a specifically linear list and think of 2 types of following classification. Where you have general and restricted list? General list can be unordered and order. Restricted list can FIFO will talk about the queue. And LIFO talk list in detail. Which is the stack? Up to now where not look at the implementation at all. We generally look at as what is the list and how the list can be how the list looks like and be the list of numbers. It can be names can be list of telephone numbers and so on. And we look at what are the operations you can do. All the operation that any application of which user list you what but then if you what to actually represent in this computer. You have to implement using some particular method of implementation. IMPLEMENTATION OF LIST:
Different ways in which list can be implemented. One is arrays one is linked list and we can also implement list using doubly linked list. Array: how to choose the implementation of whether do you want an array implementation a list implementation depends upon operation you want do to the list. And nothing else and what are the operations you want to do the list depends upon the applications of the list. You have decide you want to do array implementation or linked list implementation depending upon the applications and application will be desired what operation. Operation decided on the application. First we look at the array implementation before look how do to array implementation letters look at what type of operation in list mode easy by the array implementation. Search is easy if you use the array. Traversal is easy use arrays. Insert and delete is not easy. It is fairly operation in an application better to avoid array. One of the major problem in array implementation is before you start the implementation you do not the application is not know how much storage want to an array. For an array, before start an implementation. Ok 100. I want to allocate 100 locations for the particular implementation in the list. But the problem is application can you guess it. To large in a number waste in a memory. So this is the problem of using array. But has array is one advantage it because if the list which is implementation using an array. But has array is one advantage it because if the list which is implemented using an array it mainly using for searching. For traversal then the array implementation of the list is best. So you can also implement list using linked list and slight confusion among the students as what is the list and what is the linked list. Actually list is nothing but list of names, numbers and so on. Nothing to do with the implementation list can be implemented using different data structures like arrays, link list and so on. Linked list data structures is used for implementation is make of the difference in the data structures which we can implement either an array or link list. Linked list not only used for represent the list. Linked list implementation can be used for queue, stack, trees and so on. This is the difference between list and array. Implementation list using arrays. Array is set of pairs the pair is an index and a value is a data structures. Array is a sequence of indexed items for each index there is a value associated with that particular index suppose you say array one. Array one will a value A, array 5 will have a particular value c. This is a pair that is index along with the value. One of important concepts in array is the length array is fixed when the array is created and the array is consecutive memory location is allocated to the array that is physically as well as logically contiguous memory. Actually what happen when a array is created is sequence of blocks are allocated dynamically to store the value of the array. Example: we are assuming that two address spaces are used to store content 1228 as 0 and 1230 as 1 so this 01234 if you take it as list it is stored in contiguous
memory location. That is the basic aspect of arrays. Normally when you talk about the array you have in this is ranging from the lower bound. Normally 0 in most programming languages through a higher bound n-1 and n represents total no of elements stored in the array. Any item in the array can be accessed using the index if you say a1 it will be access the first element a5 it will access the fifth element. If you say 1 you will get the element you can access it directly. That why you say the time clock complexity is of the order of one because if you cay one you get immediately go and get the element in the first place and a1000 suppose the array of size thousand. The operation that you do obviously the same the you going represent the list in the array means operations are create initialize then the length property to find the length of the array then insertion deletion and then searching. Searching for the element from the array. There are many application that uses list and which use arrays for list implementation. One of it is polynomial. Polynomial is defined by list of coefficient and exponents and the degree of polynomial is the largest exponent. This particular polynomial can be represented using list. If you look at link list implementation this is how the link list will be I will talk about this in detail later. One important different between list implementation using array and list implementation using link list is while in array the elements of the list are logically contiguous and physically contiguous and when you use link list for implementation of the list the elements of the list are logically still contiguous but physically need not to be contiguous for example bag, cat, sat and vat. Bag can stored at thousandth location and cat can be stored at three hundredth location sat can be stored at four fifty location and vat can be stored at some 600 location no continuity but still bag, cat, sat and vat are logically connected because of the links between the nodes if you look at the link list implementation. Link list is the chain of elements. If you look at each node of elements or each element it consist of two parts data part and the link part and the link part job is to point to the next element or logically next element in the list. Here a link list will normally have a head pointer which is called a p head that pointed to the first node in the list and each node in the list will have date and link data will store element and link will be the address of the next element and if you have an empty link list it will just represented by the p head. You can have a node of different types for example a node with one date field. The element and the data stored is number the link is the address if you look at the next one the node with three data field name id and some grdpts are whatever you can any number of data fields. But normally only one link if it is this type of link list and that is structure like name, address and phone and the link can also be represented as structures there are many ways in which link list are implemented we are looking at one we are defining two structure one is list head
some implementations of link list do no separate out this list head bt in this particular implementation we are talking about list head. List head will also have the count of the number of elements as well as a link field so if you look at the left hand side you have list count integer and head is a pointer. Pointer means address. That is the structure heads structures you have a node structure where you have data which is the data type and link which is again a hundreds this is data here we have assumed that data is one field it can have more than one.
Popular Posts
-
Exploring Python Web Scraping with Coursera’s Guided Project In today’s digital era, data has become a crucial asset. From market trends t...
-
What does the following Python code do? arr = [10, 20, 30, 40, 50] result = arr[1:4] print(result) [10, 20, 30] [20, 30, 40] [20, 30, 40, ...
-
Explanation: Tuple t Creation : t is a tuple with three elements: 1 → an integer [2, 3] → a mutable list 4 → another integer So, t looks ...
-
What will the following code output? a = [1, 2, 3] b = a[:] a[1] = 5 print(a, b) [1, 5, 3] [1, 5, 3] [1, 2, 3] [1, 2, 3] [1, 5, 3] [1, 2, ...
-
What will the following Python code output? What will the following Python code output? arr = [1, 3, 5, 7, 9] res = arr[::-1][::2] print(re...
-
Through a recent series of breakthroughs, deep learning has boosted the entire field of machine learning. Now, even programmers who know c...
-
What will the following code output? import pandas as pd data = {'Name': ['Alice', 'Bob'], 'Age': [25, 3...
-
What will the output of the following code be? def puzzle(): a, b, *c, d = (10, 20, 30, 40, 50) return a, b, c, d print(puzzle()) ...
-
Step-by-Step Explanation: Dictionary Creation: my_dict = {'a': 1, 'b': 2, 'c': 3} A dictionary named my_dict is crea...