armi3 /
data-structures
π This is a collection of implementations I did for my university data structures course. Each exercise has testing, profiling, a demo recording and some useful resources. Java, C and Python were used.
Loading repository dataβ¦
elianalopez / repository
π Data Structures and Algorithms in Python, with explanations!
For this introduction I am going to define key terms so we can do into more depth about the applications and uses of data structures and algorithms.
These will be the key terms defined in this section:
Data types are important because they illustrate the kind of value in the variable and tells us what operations can be performed on any particular data. Down below is an intuitive definition of what a data type is:
In Python there are four categories of data types: numeric, sequential, Booleans, and dictionary
I have created a diagram of these categories of data types along with their respective data types down below.
For me, I like to think of an abstract data type as a thought process of the rules and operations of data, there is no concrete implementation, but just thoughts and ideas on how this process might work.
Note: An ADT is the what it does.
Overall this is the most intuitive definition of an algorithm:
Outside of computing, one example of an algorithm can be a recipe from a cookbook to craft a meal. Where we follow a certain set of instruction from the cook book to create our meal, which would thus solve the problem of our hunger.
The implementation of an abstract data type can be referred to a data structure but intuitively is a way of organizing data so it can be used effectively.
Overall it is a technique of how data can inter-relate to each other logically or mathematically, or in layman's terms how it does it.
The Connection between Data Structures and Abstract Data Types:
ADT gives us the blue print while a data structure tells us how to implement it
To put it simply, data structures need algorithms and algorithms need data structures.
The connection between algorithms and data structures is that an algorithm processes data and that data is then stored into a data structure.
This is an illustration of the interconnection of a data structure and an algorithm:
Often, there is more than one way to solve the same problem with different programs. So how would you be able to compare the performance of different algorithms, is one program better than the other?
Well the answer to that question is quite simple, you have to see which program is more efficient.
There are two ways to determine which algorithm is more efficient:
Overall time and space complexity can be impacted from several factors such as hardware, operating system.
The time complexity is the amount of time an algorithm takes to complete its process, and this time is usually measured by the input n, in order to compare its efficiency with other algorithms.
When determining time complexity, you have to ask, how does the runtime of our algorithm change as input becomes larger? An alternative question you can ask is, How much time, in a worse case scenario, is utilized?
Asymptotic is the nature of a graph as it reaches an untouchable bound, where we can understand how a function behaves in the asymptotic end.
There are three types of asymptotic notations utilized to illustrate the run time complexity:
Big-O - O(n)
Big Theta - Ξ(n)
Big Omega - Ξ©(n)
Big-O notation is utilized to describe the performance or complexity of an algorithm, it does with by its tail behavior (see the graph below). Big-O is typically described as the worst case scenario because the more complex your algorithm, along with large amounts of data, the longer it will take to operate with time.
When thinking about Big-O, ask yourself this question, how does an algorithm speed scale when the input scale become very large?
What is the n of O(n)?
Note for Big-O As seen in the graph above you can notice that Big-O gives us a tight-upperbound to functions.
Note for O(log(n)): Normally logarithmic are typically base 2. One thing to think about while looking at a log is, what must I power my base (of 2) by to get n. Example on how to solve this problem is down below.
When determining space complexity, you have to ask, how does the space usage of our algorithm change as input becomes larger? An alternative question you can ask is, How much memory, in a worse case scenario, is needed?
Space Complexity = Auxiliary Space + Input space
Similar to time complexity, space complexity can also be expressed using Big-O notation, such as O(n), O(nlog(n)), O(nΒ²).
What space does your program create?
Note: Runtime stack is a part of space complexity
If we had to choose between either optimizing time or optimizing space.
Overall, it depends on your needs, but in a production setting, optimizing time is the main priority because we can buy memory, but we can't buy time!
This can lead to the best trade off of both increasing the space and lowering the time!
A data structure is linear if data items are arranged in a sequential order.
A linear data structure can be envision as having two ends, either a front/rear end type, a left/right end type, or a top/bottom end type.
The following are examples of linear structures:
A stack is a linear data structure with a Last In First Out (LIFO) removal procedure, so the addition and removal of items takes place within the same end.
The stack can be envision as having a top/bottom end type, where the first item that is inserted would be in the bottom, and the last item inserted will be at the top.
Think of a stack as collection of plates stacked upon each other. The only way to access the plate of your choice (i.e. The Orange One) is to remove the plates that are sitting on top of it. The diagram below illustrates the LIFO process that is utilized in order to access the Orange Plate.
One fundamentally and useful application of the stack is that the orders of the items inserted in a stack are removed in the reverse order of the insertion.
Our plate diagram briefly illustrates this concept by removing the last two plates(plate 5, and plate 4) first.
Stack as an ADT is the picture of how the stack works with data along with the operations the stack utilizes.
As stated earlier, an ADT is the "what it does" another way to view an ADT is a mathematical blue print.
These are he following operations of a stack:
To see Stack ADT implementation in Python via a custom Stack Class click here for the source code.
Selected from shared topics, language and repository descriptionβnot editorial ratings.
armi3 /
π This is a collection of implementations I did for my university data structures course. Each exercise has testing, profiling, a demo recording and some useful resources. Java, C and Python were used.
MdShahnawaz474 /
This repository is my personal learning journey of Data Structures & Algorithms from the Namaste DSA β Zero to Hero course. It contains: π My notes & explanations for each topic π» Solution code in JavaScript, C, C++, Java & Python π Company-wise interview practice questions π― A structured path from beginner to advanced DSA
alu-rwa-dsa /
π Data Structures and Algorithms implementation in Python
francisco-oro /
π Algorithms and data structures implemented in Python with explanations and links to further readings
NewmarLucas /
π Just a repo with my algorithms and data structures study, initially using python.
ximet /
π Algorithms and data structures implemented in Python 3 with explanations