Okay, well... Good morning, good afternoon, it depends on when you 're watching this video. Let's start with the videos for the Programming Workshop subject. Surely when you are watching this video, you have already gone through the first class of the workshop, which is where we explain the methodology. If you haven't attended, or haven't heard about it, the methodology is posted in the ideas section. Please review it and read it, because it's how we're going to work in the subject, so that there are no doubts or problems during the course, okay? In the workshop, as they have also explained to you, it has the particularity that we are going to use everything by means of computers and therefore it is divided into three modules: the imperative module, which has to do with further deepening the concepts that we saw in the previous subject, which is CADP; Next, there will be a module related to object-oriented programming, in which we will cover the initial and most important concepts of object-oriented programming ; And finally, there will be a module called concurrent programming, which deals with how, let's say, in the concepts that have been introduced for some years now in the initial subjects of the first year, in the careers that have to do with computer science, what it is like to divide a program into several parts and that each of those parts can be executed on one or more computers at the same time to solve a whole problem. Having said all this, let's start with the first topic we have in the workshop, in the imperative module which has to do with algorithms for sorting data structures. Okay, let's do what we always do, which is to share the presentation. In this case, we have it here, and this presentation is about sorting algorithms. Okay, during the CADP course, we've seen two data structures in which information could be stored , right? We have seen the array data types, with their characteristics, and we have seen the list data type, also with its characteristics. Each one was different, but they shared some characteristics, such as the homogeneity of the elements, right? They all had to be of the same type, but they differed in other ways, such as the fact that list data structures were dynamic, while array data structures were static. From there, we'll look at sorting algorithms for this type of data, okay? As I just told you, this is what we're going to see, we're going to see why it's important to have an ordered data structure , okay? To briefly review, we saw during the previous course that an array is a composite data structure, yes, because it holds more than one element at a time, and that it allows access to each of those components, to each of its elements, through the use of an index. That index is a position within the array and it has to have certain characteristics, right? It has to be of ordinal type. One of the most important characteristics is that the array is stored sequentially in memory, and this allows it to be a static data structure, right? So the fundamental characteristics of arrays are that they are a homogeneous data structure, they are static, they have direct access through the index, they are indexed, they are linear, right? A piece of data in an array cannot be followed by more than one other piece of data, yes, at most one, and it has..., during the CADP course we dealt, in arrays, with a physical dimension that represents the maximum number of elements that can be stored in an array and a logical dimension that represents the number of real elements that are stored in the array. Having said all this, yes, and remembering that an array was defined with the keyword "array", where one defined how much capacity an array would have at most , and then said what components, what type of components the elements of the array were; Then we defined an array type variable, and from there we could work and perform the operations. During the CADP course, we saw how to load the structure, how to add an element to the end of the array, how to insert an element in a position or to keep the structure sorted, and how to delete. Remember that in arrays, elimination is logical, right? Shifts are made, it's not that we free up memory, as in the case of lists; How to traverse a structure of array data types, how to search for an element depended on whether the structure was sorted or not, and today we are going to look at the concept of sorting. On the other hand, in contrast to arrays, we had lists, which are a structure composed of nodes; each node contains the data from the list that you want to store and also the address of the next node in the list. This is because the elements of a list, unlike an array, are not stored consecutively in memory; First, they are stored in dynamic memory and can be in different portions of memory. Each time we want to add an item to a list, we must request available dynamic memory space, and each time we want to delete an item, we must free the dynamic memory that the item occupies. The fundamental characteristics of lists are that they are homogeneous, like arrays, dynamic, and have sequential access; This meant that if I want to access the fifth element of the list, assuming it exists, I have to go through the previous four, and it is linear because each element of the list, at least the lists we saw in CADP, there are other types of lists, it was followed by a single element and preceded by a single element. Having said all this, a list, remember that first we declared the list type, which was a pointer to a node, and that node was the one that contained the element and the next node of the list, right? Then, as always, we use a variable that represents that data, right? The operations we saw during the course for lists were like what it meant to create an empty list, what it meant to add an element that could be added to the end or the beginning of the list, what it meant to insert an element so that the list remained sorted, what it meant to delete an element, yes, traversing that structure and looking for an element that was also different if the data structure was sorted or not. Next, we'll see what happens with the sorting of the lists, okay? Therefore, before looking at the sorting methods, it is important to understand the benefit of having a sorted data structure. It is not the same, for example, to work with an array, like the first drawing where the elements are stored randomly, as to have an array where the elements are ordered. If you remember the searches, yes, when the structure was ordered, if I was looking for, for example, the number 10 and I was already on 11, that meant that I didn't continue traversing that structure, and that made that search more efficient than searching in a totally unordered data structure , right? So, because of these kinds of characteristics, maintaining an organized data structure is important, right? If we take it to reality and look at Google, Google, surely not, has all its structures, all its information ordered, not in an arrangement, yes; But using indexes that you will see in later subjects, but all the information is ordered, because it needs that when the user puts, I don't know, Qatar World Cup, that information appears as quickly as possible , yes, so that the user waits as little as possible. The only way to quickly return the information to the user in an organized manner is by maintaining order in the information, right? Obviously, a sorting algorithm is a process by which a set of data that has any order, yes, that is random, after the algorithm, ends up sorted by some criterion; From lowest to highest or highest to lowest, okay? There are a lot of sorting algorithms, especially for vectors, right? Next, we'll see what happens with the lists, but each one has different characteristics. Some are easy to write, others are a little harder to write but much faster, some take up less memory, others require the array to have certain characteristics, right? Notice that I put some of the sorting algorithms there, the selection one has an order of n squared, yes, where n is the number of elements; The exchange sort is also used, but if we look at "MergeSort" or "HeapSort" or "QuickSort," for example, they have a logarithmic order, and that makes the algorithm much faster than the previous ones, but that type of algorithm is also more difficult to write, yes, and requires more memory, because in general those types of algorithms are recursive algorithms. We'll see recursion in later videos, okay? In the workshop, I almost say CADP, we in the workshop are going to work with two types of algorithms that are easy to write, so that you can see what it means to sort an array. We're going to work with the selection algorithm and we're going to work with the insertion algorithm, okay? We're going to stop this video here, and in later videos I'll explain how each of these two algorithms works and how they are implemented.
Facultad de Informática. UNLP Año 2023. Materia: Taller de Programación PRIMER MODULO - IMPERATIVO Clase 1, parte 1 Tema: Ordenación