<<

Samira Arabgol, Hoo Sang Ko JAISCR, 2013, Vol. 3, No. 3, pp. 251 – 263 DOI 10.2478/jaiscr-2014-0018

[20] . E. Goldberg, Genetic in Search, Waste Management, vol. 29, no. 11, 2009, pp. Optimization, and Machine Learning, Addison- 2874–2879,. Wesley, 1989. [21] S. Jahandideh, S. Jahandideh, E. Barzegari Asad- [22] D. Venkatesan, K. Kannan, and R. Saravanan, ”A B- COMPLEXITY ANALYSIS TO abadi, M. Askarian, M. M. Movahedi, S. Hos- Genetic Algorithm-based Artificial Neural Net- seini, and M. Jahandideh, ”The Use of Artificial work Model for the Optimization of Machining EVALUATE THE FEASIBILITY OF ITS APPLICATION IN Neural Networks and Multiple Linear Regression Processes,” Neural Computing and Applications, to Predict Rate of Medical Waste Generation,” vol. 18, no. 2, 2009, pp. 135–140. THE UNIVERSITY COURSE TIMETABLING PROBLEM

Marco Antonio Cruz Chvez, Alina Martnez Oropeza CIICAp, Universidad Autnoma del Estado de Morelos Av. Universidad 1001. Col. Chamilpa, .P. 62209. Cuernavaca, Morelos, Mxico [email protected]

Abstract

This paper presents a comparative analysis of complexity between the B-TREE and the Binary Search Algorithms, both theoretically and experimentally, to evaluate their effi- ciency in finding overlap of classes for students and teachers in the University Course Timetabling Problem (UCTP). According to the theory, B-TREE Search complexity is lower than Binary Search. The performed experimental tests showed the B-TREE is more efficient than Binary Search, but only using a dataset larger than 75 students per classroom.

1 Introduction sity where there are many constraints to be consid- ered in order to obtain a feasible solution. Resource Scheduling is a very important area To treat the problem of scheduling at a univer- within computer sciences due to its wide applica- sity level, there is a proposed mathematical model tion in different areas, such as manufacturing, the and some benchmarks which are used as a paradigm academic environment, and vehicle routing, among to try to obtain feasible and better solutions. The others. One of the typical problems in this area name of the problem in combinatorial optimiza- is the scheduling in an academic environment [6], tion is the University Course Timetabling Problem where school schedules must be established. Their (UCTP), which has been classified within the development requires long periods of time due to of NP-Complete problems due to its complexity [1, the number of variables to assess. Also on occasion, 2]. This means that there is no known deterministic unfeasible solutions are obtained because overlaps algorithm bound by a polynomial temporal func- could occur. An overlap is the timeslot in which the tion to solve this kind of problem [3]. Therefore, same event or activity happens simultaneously; in the scientific community has focused its research this context, when scheduling classes, teachers and on the treatment of NP-Complete problems through students cannot give or take different classes during non-deterministic algorithms, which are bound by the same timeslot. polynomial time. These algorithms (better known Designing school schedules is not an easy task, as Heuristics) need to be constantly improved in but its complexity depends on the level. For exam- attempt to obtain better solutions or reduce the ex- ple in an elementary school the complexity is re- ecution time [4]. There are several techniques that duced due to the smaller quantity of teachers, class- have been used to find feasible solutions to this rooms, and the fixed student groups, so they do not problem, but the most common are metaheuristics. have to take into account so many variables. The complexity increases for a high school or a univer- 252 Cruz Chvez M. A., Martnez Oropeza A.

To find a good solution to UCTP using any the efficiency of the search algorithms applied to metaheuristic, local search application is necessary. this specific case. The heart of a local search is the application of a The contribution of this work is to find the most neighborhood structure, which generates exchanges efficient search algorithm to detect overlap of events of elements. Iterative local search, guided by an for students and teachers in the UCTP. objective function, can improve the solution of a problem as UCTP, but every swap generated by the The present research is divided as follows. Sec- neighborhood structure through local search could tion one provides a general introduction to the generate an unfeasible solution. To detect a move- problem, and emphasizes the importance of having ment of the neighborhood structure that can gener- an efficient method which can obtain good solu- ate an unfeasible solution in UCTP, it is necessary tions in a reasonable computational time. Section to use a search algorithm. For example, in a UCTP, two presents the formal definition of the Univer- moving a student e to take a class on day i, at a sity Course Timetabling Problem, focusing on the specific hour j, in classroom k, (i, j, k), may cre- explanation of the set of constraints, which define ate schedule conflicts (overlap) for the student and the specific case. Section three discusses the theo- other classes that he takes. To determine if there retical complexity managed in the literature for the is overlap, it is necessary to perform a search in all principal search methods. An explanation is given classrooms (k = 1,..., n) to verify that the student e for the methods of both Binary Search and B-TREE is not taking another class in the same timeslot (i, Search. The fourth section presents the temporal j). functions specified to each algorithm. Section five shows the experimental results, and the compara- According to theory, the search algorithms with tive analysis of both methods, taking into account the least theoretical complexity are B-TREE and their theoretical and experimental complexity. Fi- Binary search. The B-TREE complexity, in the nally, the conclusions of this research are presented worst case, is lower than the Binary search com- in section six. plexity. For this reason, in this work, these two search algorithms were tested for UCTP. A set of hard constraints were accounted for, which ensured 2 University Course Timetabling non-overlapping classes for both teachers and stu- Problem dents [5]. The fulfillment of these constraints must be verified; it is necessary to check that students do The University Course Timetabling Problem not take more than one subject per timeslot (i, j), (UCTP) has been classified within the Complexity and in one classroom k. If a student e takes more Theory as NP-Complete [1]. This problem could be than one subject in the same timeslot (i, j), the stu- solved by deterministic or non-deterministic meth- dent is overlapping; therefore, the obtained solution ods. Using a deterministic method, it is only fea- is unfeasible. sible to obtain the optimal solution for a small in- In this research, the two most efficient search al- stance, because if the instance size grows, the com- gorithms, according to their theoretical complexity, putation time of a deterministic algorithm increases were used to conduct an experimental comparison. exponentially. As a result, most researchers have focused on heuristics, which get approximated so- Application of a search method allows for re- lutions in a reasonable time; although, there is no vision of each student e assigned to an event in a guarantee of their optimality. timeslot in a CR classroom. It also allows for revi- sion of possible overlaps with other events the stu- The features of the components that are consid- dent takes, where an event is a class taken by the ered in this problem, such as students, classrooms, student e. According to this reasoning, the meth- facilities, teachers, and classes, when considered in ods applied to UCTP require a very efficient search combination with the features of limited resources, algorithm within their structure due to the iterative time considerations and the available spaces for as- nature which is required for this problem. Accord- signing the events, make it difficult to get feasible ing to theoretical and experimental results, a con- solutions in a reasonable computing time. clusion was reached as to the best option, based on Cruz Chvez M. A., Martnez Oropeza A. B-TREE ALGORITHM COMPLEXITY ANALYSIS TO . . . 253

To find a good solution to UCTP using any the efficiency of the search algorithms applied to The goal of finding solutions to the UCTP is all the students assigned to attend the event. metaheuristic, local search application is necessary. this specific case. to obtain a scheduling such that both students and H3. The assigned classroom must have the required The heart of a local search is the application of a The contribution of this work is to find the most teachers can attend all their programmed classes facilities to carry out the assigned event. neighborhood structure, which generates exchanges without time difficulties. The UCTP has some spe- efficient search algorithm to detect overlap of events H4. No classroom can have more than one event in of elements. Iterative local search, guided by an for students and teachers in the UCTP. cific features that must be respected to obtaining a objective function, can improve the solution of a feasible solution. These features are known as con- the same timeslot. problem as UCTP, but every swap generated by the The present research is divided as follows. Sec- straints, and are classified into two kinds of con- H5. No teacher attends more than one event in the neighborhood structure through local search could tion one provides a general introduction to the straints. same timeslot. generate an unfeasible solution. To detect a move- problem, and emphasizes the importance of having an efficient method which can obtain good solu- Hard Constraints: They must be fulfilled com- Set of Soft Constraints ment of the neighborhood structure that can gener- pletely, and must not be violated. For example a tions in a reasonable computational time. Section S1. A student should not take classes in the last ate an unfeasible solution in UCTP, it is necessary teacher cannot give different classes in the same to use a search algorithm. For example, in a UCTP, two presents the formal definition of the Univer- timeslot of the day. sity Course Timetabling Problem, focusing on the timeslot. moving a student e to take a class on day i, at a S2. A student should not take two or more uninter- specific hour j, in classroom k, (i, j, k), may cre- explanation of the set of constraints, which define Soft Constraints: They should, preferably, be sat- rupted classes. ate schedule conflicts (overlap) for the student and the specific case. Section three discusses the theo- isfied, although some violations could be accepted S3. A student should not take only one class during other classes that he takes. To determine if there retical complexity managed in the literature for the adding a penalty per each violation. A clear exam- a day. is overlap, it is necessary to perform a search in all principal search methods. An explanation is given ple may be that the students should not have four or classrooms (k = 1,..., n) to verify that the student e for the methods of both Binary Search and B-TREE more continuous classes. The main reason is that The UCTP could be represented in a schematic is not taking another class in the same timeslot (i, Search. The fourth section presents the temporal it is not pedagogically recommended, because the form (Figure 1) to improve its understanding. functions specified to each algorithm. Section five students need a rest after taking continuous classes. j). The representation shown in Figure 1 is made shows the experimental results, and the compara- However, some violation could be accepted due to using a tridimensional form, better known as a cube, According to theory, the search algorithms with tive analysis of both methods, taking into account the time circumstances, and the scheduling. where each layer, represented by different colors, the least theoretical complexity are B-TREE and their theoretical and experimental complexity. Fi- The specific problem tackled in this research symbolizes a classroom. A classroom is formed by Binary search. The B-TREE complexity, in the nally, the conclusions of this research are presented consists of a set of events that have to be pro- several 3D boxes (Period, Day, and Classroom) per worst case, is lower than the Binary search com- in section six. plexity. For this reason, in this work, these two grammed in a set of 45 timeslots, which are dis- day, where each one defines a timeslot where an search algorithms were tested for UCTP. A set of tributed in five days with nine 50-minute periods event can be assigned. An event is the intersection hard constraints were accounted for, which ensured 2 University Course Timetabling per day. There is also a set of classrooms where between a Period, and a Day in certain Classroom, the events are held, a set of students who attend where an event could be assigned. Each event will non-overlapping classes for both teachers and stu- Problem dents [5]. The fulfillment of these constraints must the events, and a set of facilities in each classroom, be taken by a group of students, who will attend to which are necessary to perform the events. Each be verified; it is necessary to check that students do The University Course Timetabling Problem several events EV1, EV2,. . . , EVn per week. For student has to attend a certain number of events, { } not take more than one subject per timeslot (i, j), (UCTP) has been classified within the Complexity example, the EV1 is taken by students E1, E2, and which are scheduled in certain classrooms with spe- and in one classroom k. If a student e takes more Theory as NP-Complete [1]. This problem could be E3 in the classroom CR2. A set of events form a cific features. Taking this into account, a feasible than one subject in the same timeslot (i, j), the stu- solved by deterministic or non-deterministic meth- class. solution has to have all the events scheduled in a dent is overlapping; therefore, the obtained solution ods. Using a deterministic method, it is only fea- Each classroom has certain features, which are classroom during a timeslot, respecting the follow- is unfeasible. sible to obtain the optimal solution for a small in- required by the different events. Those features ing constraints and trying to improve the value of stance, because if the instance size grows, the com- could be TVs, DVDs, computers, projectors, or In this research, the two most efficient search al- the objective function (1). gorithms, according to their theoretical complexity, putation time of a deterministic algorithm increases whiteboards, among others. were used to conduct an experimental comparison. exponentially. As a result, most researchers have Some of the characteristics that must be taken focused on heuristics, which get approximated so- Min F.O = s1 + s2 + s3 (1) Application of a search method allows for re- ∑ ∑ ∑ into account to assign an event to a classroom are lutions in a reasonable time; although, there is no its features and size. For example, a mathematics vision of each student e assigned to an event in a The objective function minimizes the quantity guarantee of their optimality. teacher may need a whiteboard in order to give a timeslot in a CR classroom. It also allows for revi- of soft constraints violated, where S1, S2, and S3 The features of the components that are consid- class. Size of the classroom must also be consid- sion of possible overlaps with other events the stu- refer to the soft constraints defined to this specific ered in this problem, such as students, classrooms, ered. It is necessary to check the classroom capac- dent takes, where an event is a class taken by the problem [6]. The constraints, both hard and soft, facilities, teachers, and classes, when considered in ity because a common problem is that big groups of student e. According to this reasoning, the meth- are explained as follows: ods applied to UCTP require a very efficient search combination with the features of limited resources, students are assigned to small classrooms. In Figure algorithm within their structure due to the iterative time considerations and the available spaces for as- Set of Hard Constraints 1 we can observe a possible solution, where all the nature which is required for this problem. Accord- signing the events, make it difficult to get feasible H1. No student attends more than one event in the hard and soft constraints are satisfied in order to get ing to theoretical and experimental results, a con- solutions in a reasonable computing time. same timeslot. a feasible scheduling to a small instance. For this representation, the quality of the obtained solution, clusion was reached as to the best option, based on H2. The classroom capacity must be enough to hold 254 Cruz Chvez M. A., Martnez Oropeza A. according to the objective function is not evaluated, amination of their theoretical complexity allowed because it is only an example of a feasible solution for the selection of the two best algorithms. An where all the constraints are satisfied. It is very dif- experimental comparison was performed, using a ficult to use a bigger instance because of its time computer program to select the best algorithm for limitations and the nature of the problem. this specific problem.

3 Search Algorithms

Search algorithms have been widely used to perform searches in structures, such as trees, where they have been applied successfully. Many types of search algorithms exist, such as , Binary search, B-TREE search, and some hybrid searches, which have been applied to differ- ent optimization problems. The main difference among these search algo- rithms is the computational effort required to carry out a certain search, because many of them need the keys (elements of the total set) in a specific or- der, which increases the complexity of the algo- rithm. For this research, three of the most com- mon search algorithms are used, in addition to one hybrid ( + Binary search). According to their complexity, theoretically, B-TREE search is more efficient that the others. The complexity of an algorithm (Table 1) de- pends on the number of questions that it must ask in the worst case in order to find a specific key within a set of n keys. Using the information from Table 1, the graph Figure 1. Schematic representation of a possible below (Figure 2) was made, which clearly shows solution applied to a small UCTP instance the theoretical behavior of each search method. In the case of B-TREE search, a tree to the order of 5 Finding a feasible solution is not easy; it re- was used. quires an efficient process dedicated to exploring the solution space and verifying that all the con- According to the comparison presented in Table straints were satisfied. The process of ensuring that 1 and Figure 2, it can be observed that the most ef- a solution is feasible requires the use of a search al- ficient algorithm is B-TREE search, and the second gorithm, which has to examine each set of students most efficient is Binary search. It is important to and teachers in each classroom to make certain that note that these two algorithms work with ordered no subject and no students were overlapped. Even keys. They have the previously mentioned com- if a feasible solution is found, it is necessary to con- plexity only if the set of keys used are already or- tinue exploring for new feasible solutions in order dered; otherwise, the complexity increases depend- to obtain the best possible solution. The aim of the ing on the applied. present research is to find an efficient search algo- A comparison of the requirements of the search rithm to apply to the specific problem of UCTP ex- algorithm (Table 1) with the features of the specific plained in this section. problem tackled in this paper, show that it is pos- The next section provides a general explanation sible to apply them to the UCTP. The set of keys of some of the most efficient search algorithms. Ex- used corresponds to the students assigned to differ- Cruz Chvez M. A., Martnez Oropeza A. B-TREEB-TREE ALGORITHM ALGORITHM COMPLEXITY COMPLEXITY ANALYSIS ANALYSIS TO . . . TO . . . 255 according to the objective function is not evaluated, amination of their theoretical complexity allowed because it is only an example of a feasible solution for the selection of the two best algorithms. An where all the constraints are satisfied. It is very dif- experimental comparison was performed, using a ficult to use a bigger instance because of its time computer program to select the best algorithm for TableTable 1. Theoretical 1. Theoretical complexity complexity in the in worst the worst case for case four for commonly four commonly used usedsearch search algorithms algorithms limitations and the nature of the problem. this specific problem. SearchSearch Algorithm Algorithm TheoreticalTheoretical Complexity Complexity

n+1 n+1 B-TREEB-TREE m > 2m > 2 dmin =dminlog=m (logn +m1()nd+max1) =dmax1 +=log1 +mlog+1 m+1 3 Search Algorithms ( 2 )( 22 ) 2 Search algorithms have been widely used to ( )( ) BinaryBinary Search Search iterationsiterations= log=2 (logn) 2 (n) perform searches in data structures, such as trees, where they have been applied successfully. Many LinearLinear Search Search iterationsiterations= n = n types of search algorithms exist, such as linear search, Binary search, B-TREE search, and some n+c n+c QuickSortQuickSort + Binary + Binary Searchc Searchc = 3.321928095 = 3.321928095 iterationsiterations= log=10log(n 10 ()n ) hybrid searches, which have been applied to differ- ent optimization problems. The main difference among these search algo- rithms is the computational effort required to carry out a certain search, because many of them need the keys (elements of the total set) in a specific or- der, which increases the complexity of the algo- rithm. For this research, three of the most com- mon search algorithms are used, in addition to one hybrid (Quicksort + Binary search). According to their complexity, theoretically, B-TREE search is more efficient that the others. The complexity of an algorithm (Table 1) de- pends on the number of questions that it must ask in the worst case in order to find a specific key within a set of n keys. Using the information from Table 1, the graph Figure 1. Schematic representation of a possible below (Figure 2) was made, which clearly shows solution applied to a small UCTP instance the theoretical behavior of each search method. In the case of B-TREE search, a tree to the order of 5 Finding a feasible solution is not easy; it re- was used. quires an efficient process dedicated to exploring the solution space and verifying that all the con- According to the comparison presented in Table straints were satisfied. The process of ensuring that 1 and Figure 2, it can be observed that the most ef- a solution is feasible requires the use of a search al- ficient algorithm is B-TREE search, and the second gorithm, which has to examine each set of students most efficient is Binary search. It is important to and teachers in each classroom to make certain that note that these two algorithms work with ordered no subject and no students were overlapped. Even keys. They have the previously mentioned com- if a feasible solution is found, it is necessary to con- plexity only if the set of keys used are already or- tinue exploring for new feasible solutions in order dered; otherwise, the complexity increases depend- to obtain the best possible solution. The aim of the ing on the sorting algorithm applied. present research is to find an efficient search algo- A comparison of the requirements of the search Fig. 2. theoretical behavior of each search method, as shown in table 1. rithm to apply to the specific problem of UCTP ex- algorithm (Table 1) with the features of the specific FigureFigure 2. Theoretical 2. Theoretical behavior behavior of each of eachsearch search method, method, as shown as shown in Table in Table 1. 1. A comparison of the requirements of the search algorithm (table 1) with the fea- plained in this section. problem tackled in this paper, show that it is pos- tures of the specific problem tackled in this paper, show that it is possible to apply The next section provides a general explanation sible to apply them to the UCTP. The set of keys them to the UCtP. the set of keys used corresponds to the students assigned to dif- of some of the most efficient search algorithms. Ex- used corresponds to the students assigned to differ- ferent events. those data are always ordered, thus a sorting algorithm is not needed and the algorithms maintain their theoretical complexity. for this reason, the two most efficient algorithms were chosen which are, according to Table 1, the Binary search and B-tRee algorithms are.

Binary Search

This type of search works with a set of ordered keys, which divides in two parts and compares a sought key with the central one. if it is not equal, the limits of the rank are defined, depending on whether the central key is greater or less than the sought one, which considerably reduces the search set. this process is performed iteratively until the sought key is found. Binary search always finds the sought key if it exists. the worst case would be that the desired key would be the last one com- pared. Consequently, the number of iterations would be defined by (2), where the number of iterations is directly affected by the number of keys in the sample.

256 Cruz Chvez M. A., Martnez Oropeza A. ent events. Those data are always ordered, thus a bound (Equation 3) of a B-TREE with D = 1. It has sorting algorithm is not needed and the algorithms three pointers (m = 3) and two keys per node (2D = maintain their theoretical complexity. For this rea- 2), giving a depth of three (LB = 3) and n = 26 keys. son, the two most efficient algorithms were chosen The depth is very important because is the number which are, according to Table 1, the Binary search of iterations required to find the sought key. and B-TREE algorithms are. Applying Equation 4, the upper bound of the Binary Search same B-TREE can be obtained. The result is a B- This type of search works with a set of ordered keys, TREE with four levels. In the same way, a balanced which divides in two parts and compares a sought tree is obtained, which is shown in Figure 4. It is key with the central one. If it is not equal, the limits not complete because it does not use the maximum of the rank are defined, depending on whether the number of pointers per node. central key is greater or less than the sought one, The levels vary, due to the handling of balanc- which considerably reduces the search set. This ing, and how the keys are accommodated into the process is performed iteratively until the sought key nodes. For example, in Figure 2, the maximum is found. Binary search always finds the sought key number of pointers per node is used. This is unlike if it exists. The worst case would be that the desired Figure 4, where the nodes do not use all their keys, key would be the last one compared. Consequently, and most of them have only two pointers, which in- the number of iterations would be defined by (2), Fig. 4creases. Upper Bound the levels of a B of-tRee the treeorder (UB three =, in 4.75).complete and balanced. where the number of iterations is directly affected the levels vary, due to the handling of balancing, and how the keys are accommodat- by the number of keys in the sample. ed into the nodes. for example, in figure 2, the maximum number of pointers per node is used. This4 is Binary unlike Figure and 4, where B-TREE the nodes Search do not use Al- all their keys, and iterations = log2 (n) (2) most of them have gorithms only two pointers, which increases the levels of the tree (UB = B-TREE Search 4.75). The two algorithms explained in the last sec- B-TREE search performs a specific search for a tion were programmed using C standard language. key in a balanced tree. This type of search4 makesBinaryBefore and B the-TREE experimental Search testing, Algorithms a complexity anal- a multi-way branching decision according to the ysis of both algorithms was performed, obtaining number of children per node (order). AsThe input, two B- algorithms explained in the last section were programmed using C standard language. Beforetheir the temporal experimental function testing, in thea complex worst case.ity analysis The algo- of both algorithms TREE search takes a pointer to the root nodewas performed and rithms’, obtaining programs their temporal are shown function below in the (Figure worst 5,case. and the algorithms’ searches for a key in a sub tree [10]. programs are shown6). below (figure 5, and 6). According to this, a B-TREE of order D can store up to 2D keys in each of its tree nodes, with a max- imum of 2D + 1, which corresponds to the maxi- mum number of children per node. This is true for all nodes, except the root node, which could have at least one key, and as a result two pointers [8]. Therefore, the depth d is between a lower (LB) and an upper bound (UB), which are defined by equa- tions 3 and 4 [9].

LB = logm (n + 1) (3) FigureFig. 55.. Binary search search algorithm algorithm n + 1 UB = 1 + log m+1 the Binary(4) search algorithmThe Binary presented search in algorithm Figure 5 shows presented the process in Fig- of checking the ( 2 ) 2 ( ) feasibility of theure solutions 5 shows in thea general process way of. first checking of all, the the feasibil-function receives some parameters; theity first of one the contains solutions the in array a general of students way. or Firstteachers of all,(keys) assigned to In equations 3 and 4, m = 2D + 1 indicates the total different eventsthe in functiona timeslot receives (i, j), which some have parameters; to be carefully the first checked one in each class- number of pointers per node in the tree, and n is the room of the samecontains timeslot the (i, array j) to ofavoid students overlaps. or teachersthe second (keys) one as-contains the num- number of keys in the tree. A graphical representa- signed to different events in a timeslot (i, j), which tion is shown in Figure 3, and is based on the lower (2) iterations  log 2 n B-TREE Search

B-tRee search performs a specific search for a key in a balanced tree. This type of search makes a multi-way branching decision according to the number of children per node (order). As input, B-TREE search takes a pointer to the root node and searches for a key in a subtree [10]. According to this, a B-tRee of order D can store up to 2D keys in each of its tree nodes, with a maximum of 2D + 1, which corresponds to the maximum number of children per node. This is true for all nodes, except the root node, which could have at least one key, and as a result two pointers [8]. Therefore, the depth d is between a lower (LB) and an upper bound (UB), which are defined by equations 3 and 4 [9].

LB  log m n 1 (3) Cruz Chvez M. A., Martnez Oropeza A. B-TREE ALGORITHM COMPLEXITY ANALYSIS TO . . . 257  n 1 UB 1 log  m1     (4)  2   2  ent events. Those data are always ordered, thus a bound (Equation 3) of a B-TREE with D = 1. It has in equations 3 and 4, m = 2D + 1 indicates the total number of pointers per node in sorting algorithm is not needed and the algorithms three pointers (m = 3) and two keys per node (2D = the tree, and n is the number of keys in the tree. A graphical representation is shown maintain their theoretical complexity. For this rea- 2), giving a depth of three (LB = 3) and n = 26 keys. in figure 3, and is based on the lower bound (Equation 3) of a B-TREE with D = 1. It son, the two most efficient algorithms were chosen The depth is very important because is the number has three pointers (m = 3) and two keys per node (2D = 2), giving a depth of three which are, according to Table 1, the Binary search of iterations required to find the sought key. (LB = 3) and n = 26 keys. The depth is very important because is the number of itera- and B-TREE algorithms are. tions required to find the sought key. Applying Equation 4, the upper bound of the Binary Search same B-TREE can be obtained. The result is a B- This type of search works with a set of ordered keys, TREE with four levels. In the same way, a balanced which divides in two parts and compares a sought tree is obtained, which is shown in Figure 4. It is key with the central one. If it is not equal, the limits not complete because it does not use the maximum of the rank are defined, depending on whether the number of pointers per node. central key is greater or less than the sought one, The levels vary, due to the handling of balanc- which considerably reduces the search set. This ing, and how the keys are accommodated into the process is performed iteratively until the sought key nodes. For example, in Figure 2, the maximum is found. Binary search always finds the sought key number of pointers per node is used. This is unlike Fig. 3. Lower Bound of a B-tRee order three, complete and balanced. if it exists. The worst case would be that the desired Figure 4, where the nodes do not use all their keys, key would be the last one compared. Consequently, and most of them have only two pointers, which in- the number of iterations would be defined by (2), creases the levels of the tree (UB = 4.75). ApplyingFigure equation 3. Lower 4, Bound the upper of abound B-TREE of the order same three, B-tRee complete can be and obtained balanced. the where the number of iterations is directly affected result is a B-tREE with four levels. In the same way, a balanced tree is obtained, which is shown in Figure 4. It is not complete because it does not use the maximum by the number of keys in the sample. 4 Binary and B-TREE Search Al- number of pointers per node. iterations = log (n) (2) 2 gorithms B-TREE Search The two algorithms explained in the last sec- B-TREE search performs a specific search for a tion were programmed using C standard language. key in a balanced tree. This type of search makes Before the experimental testing, a complexity anal- a multi-way branching decision according to the ysis of both algorithms was performed, obtaining number of children per node (order). As input, B- their temporal function in the worst case. The algo- TREE search takes a pointer to the root node and rithms’ programs are shown below (Figure 5, and searches for a key in a sub tree [10]. 6). According to this, a B-TREE of order D can store up to 2D keys in each of its tree nodes, with a max- imum of 2D + 1, which corresponds to the maxi- mum number of children per node. This is true for all nodes, except the root node, which could have at least one key, and as a result two pointers [8]. Therefore, the depth d is between a lower (LB) and an upper bound (UB), which are defined by equa- tions 3 and 4 [9].

LB = logm (n + 1) (3) Figure 5. Fig. 4. Upper Bound of a B-tRee order three, incomplete and balanced. Figure 4. Upper Bound of a B-TREE order three, incomplete and balanced + n 1 The Binary search algorithm presented in Fig- the levels vary, due to the handling of balancing, and how the keys are accommodat- UB = 1 + log( m+1 ) (4) 2 2 ure 5 shows the process of checking the feasibil- ed into the nodes. for example, in figure 2, the maximum number of pointers per ( ) node is used. This is unlike Figure 4, where the nodes do not use all their keys, and ity of the solutions in a general way. First of all, In equations 3 and 4, m = 2D + 1 indicates the total most of them have only two pointers, which increases the levels of the tree (UB = the function receives some parameters; the first one number of pointers per node in the tree, and n is the 4.75). contains the array of students or teachers (keys) as- number of keys in the tree. A graphical representa- signed to different events in a timeslot (i, j), which tion is shown in Figure 3, and is based on the lower 4 Binary and B-TREE Search Algorithms

The two algorithms explained in the last section were programmed using C standard language. Before the experimental testing, a complexity analysis of both algorithms was performed, obtaining their temporal function in the worst case. the algorithms’ programs are shown below (figure 5, and 6).

Fig. 5. Binary search algorithm

the Binary search algorithm presented in Figure 5 shows the process of checking the feasibility of the solutions in a general way. first of all, the function receives some parameters; the first one contains the array of students or teachers (keys) assigned to different events in a timeslot (i, j), which have to be carefully checked in each class- room of the same timeslot (i, j) to avoid overlaps. the second one contains the num- 258 Cruz Chvez M. A., Martnez Oropeza A.

have to be carefully checked in each classroom of of iterations. Secondly, experimental tests were per- the same timeslot (i, j) to avoid overlaps. The formed, which were executed on the same computer second one contains the number of keys (students and used the same instances to be able to directly or teachers) in the variable array, and the last one compare the obtained results. takes the value of the sought key (desired student or teacher), which is to be searched into the array. 5.1 Evaluation of Complexity Theory The body of the function performs an iterative The theoretical tests were performed to evalu- process, which compares the sought key, continu- ate the efficiency of both the Binary and B-TREE ously halves the search space until the desired key ber of keys (students or teachers) in the variable array, and the last one takes thesearch value algorithms. In order to be able to make a of the sought keyhas (desired been stud found,ent or and teacher), returns which the position is to be ofsearched the spe- into thecomparison array. between the algorithms, they were exe- The body of thecific function key found. performs If an the iterative key hasprocess, not which been found,compares thecuted sought using the same values and features. key, continuouslythe halves algorithm the search returns space -1, un indicatingtil the desired that thekey student has been found, and The theoretical evaluation of the complexity of returns the positiondoes of notthe existspecific in key that found. list. The if the following key has not algorithm been found, the algo- rithm returns -1,is indicating the B-TREE that the search, student which does is not shown exist inin Figurethat list. 6. The followingthe Binary search algorithm was performed using algorithm is the B-TREE search, which is shown in figure 6. Equation 2, which calculates the number of itera- tions needed to find a sought student in the worst case. In case of B-TREE search, Equations 3 and 4 were used to calculate the lower bound and the upper bound, respectively. In the experimental tests, a set of n students was used, which corresponds to the number of stu- dents assigned to a set of events in all classrooms in a timeslot (i, j) at a time. The values of n were 50, 1000, and 1, 000, 000 students. In the case of the B-TREE algorithm, the number of iterations to find a specific student depends on the depth and the FigureFig. 6 6. . B B-TREE-tRee search search algorithm algorithm amount of pointers on the tree. the function responsibleThe function for the responsiblesearch receives for thea parameter, search receives which containsThe the theoretical tests in the B-TREE algorithm sought key. Thisa value parameter, enters into which an containsiterative process, the sought which key. performs This a searchwere d performede- using three different keys (20, scending throughvalue the branches enters intoof the an tree, iterative depending process, whether which the desired per- key1000, is high- and 1000000). Based on the iterations, the er or lower thanforms the root a node. search If descendingthe sought key through is found, the the branches algorithm returnslower the and upper bounds were calculated for each value of the key. It returns -1 if the student or teacher has not been found. of the tree, depending whether the desired key is number of keys. There is a range of iterations re- higher or lower than the root node. If the sought quired to find a specific student when using the B- 5 Computationalkey is found, Results the algorithm returns the value of the TREE algorithm. The obtained results are shown in key. It returns -1 if the student or teacher has not Figure 7. Two types of testing were performed to prove the efficiency and efficacy of both been found. The range shown in Figure 7 for each quantity algorithms. first of all, the range of iterations required to find a specific student or teacher (sought key) was calculated theoretically. For B-tRee, equations of3 and students 4 indicates the possible number of itera- were used to obtain the lower and upper bound corresponding to a search withtions certain required to find a specific student, which is a characteristics, such5 as Computational number of students or Results teachers to be searched. forfunction Binary of the input size. The range could be de- search, the same conditionsTwo types were ofused testing to calculat weree performedthe maximum to number prove of iterationfined ass. R = UB – LB, where UB is the maximum Secondly, experimental tests were performed, which were executed on the same com- the efficiency and efficacy of both algorithms. First number of iterations, and LB refers to the minimum puter and used the same instances to be able to directly compare the obtained results. of all, the range of iterations required to find a number of iteration that can be generated by the B- specific student or teacher (sought key) was calcu- TREE search according to Equations 3 and 4. It is 5.1 Evaluationlated of Complexity theoretically. Theory For B-TREE, equations 3 and worth mentioning that for any value of n, the value the theoretical4 weretests were used performed to obtain to the evaluate lower th ande efficiency upper bound of both theof Binary R will be large if the number of pointers is small. and B-tRee searchcorresponding algorithms. In to order a search to be able with to certain make a character-comparison betweenTherefore, the the value of R decreases and remains al- algorithms, they istics,were executed such as using number the same of studentsvalues and or features. teachers to most constant as the number of pointers increases. be searched. For Binary search, the same condi- As was done with the B-TREE search, theoreti- tions were used to calculate the maximum number cal calculations were made with the Binary search. the theoretical evaluation of the complexity of the Binary search algorithm was performed using equation 2, which calculates the number of iterations needed to find a sought student in the worst case. In case of B-tRee search, equations 3 and 4 were used to calculate the lower bound and the upper bound, respectively. in the experimental tests, a set of n students was used, which corresponds to the number of students assigned to a set of events in all classrooms in a timeslot (i, j) at a time. the values of n were 50, 1000, and 1, 000, 000 students. In the case of the B- tRee algorithm, the number of iterations to find a specific student depends on the depth and the amount of pointers on the tree. the theoretical tests in the B-tRee algorithm were performed using three different keys (20, 1000, and 1000000). Based on the iterations, the lower and upper bounds were calculated for each number of keys. There is a range of iterations required to Cruz Chvez M. A., Martnez Oropeza A. B-TREE ALGORITHM COMPLEXITYfind a specificANALYSIS student when TO using . . . the B-tRee algorithm. the obtained results are 259 shown in Figure 7.

have to be carefully checked in each classroom of of iterations. Secondly, experimental tests were per- the same timeslot (i, j) to avoid overlaps. The formed, which were executed on the same computer second one contains the number of keys (students and used the same instances to be able to directly or teachers) in the variable array, and the last one compare the obtained results. takes the value of the sought key (desired student or teacher), which is to be searched into the array. 5.1 Evaluation of Complexity Theory The body of the function performs an iterative The theoretical tests were performed to evalu- process, which compares the sought key, continu- ate the efficiency of both the Binary and B-TREE ously halves the search space until the desired key search algorithms. In order to be able to make a has been found, and returns the position of the spe- comparison between the algorithms, they were exe- cific key found. If the key has not been found, cuted using the same values and features. the algorithm returns -1, indicating that the student Figure 7. TheoreticalFig. 7. theoretical results results of of B-TREE B-tRee search search using different using values different of keys values of keys The theoretical evaluation of the complexity of does not exist in that list. The following algorithm The range shown in Figure 7 for each quantity of students indicates the possible the Binary search algorithm was performed using is the B-TREE search, which is shown in Figure 6. The number of iterationsnumber required of iterations to requiredfind a soughtto find a specificThe student, compiler which used is a function to program of the both algorithms was Equation 2, which calculates the number of itera- input size. the range could be defined as R = UB – LB, where UB is the maximum student was calculated,number using of iterations, the same and numberLB refers to of the minimumVisual number C++ of 2008. iteration that can be tions needed to find a sought student in the worst students as in B-TREE.generated The calculationsby the B-tRee search were acc per-ording to equations 3 and 4. It is worth mention- case. In case of B-TREE search, Equations 3 and ing that for any value of n, the value of R will be Thelarge if testing the number problems of pointers used is during the experi- formed using Equation 2. These results were com- 4 were used to calculate the lower bound and the small. therefore, the value of R decreases andmental remains almost tests wereconstant randomly as the number generated. The sets of n pared with results obtainedof pointers from increases. Equations 3 and 4 upper bound, respectively. As was done with the B-tRee search, theorestudentstical calculations evaluated were bymade both with algorithmsthe to prove their for a B-TREE with m =Binary 5. The search. comparison The number of is iterations shown requiredefficiency to find a sought were student generated was calcu- using pseudo-random In the experimental tests, a set of n students lated, using the same number of students as in B-tRee. the calculations were per- in Figure 8. numbers ranked in ascending order. Each testing was used, which corresponds to the number of stu- The graph shown in Figure 8 represents a com- problem was evaluated using both algorithms (Fig. dents assigned to a set of events in all classrooms parison between the analyzed algorithms, Binary 5 and Fig. 6). In the case of B-TREE search, the in a timeslot (i, j) at a time. The values of n were search and B-TREE search, with respect to the experimental tests were performed using different 50, 1000, and 1, 000, 000 students. In the case of number of iterations required to find a desired stu- m(m = 3, m = 4, m = 5 and m = 30). the B-TREE algorithm, the number of iterations to dent if the quantity of students varies (Keys). The find a specific student depends on the depth and the The experimental tests were computed using results showed that the B-TREE search needs less Figure 6. B-TREE search algorithm amount of pointers on the tree. several testing problems varying the value of n (stu- iterations than Binary search in all the cases. In dents), where 5 n 1000. Each algorithm was ex- The theoretical tests in the B-TREE algorithm ≤ ≤ The function responsible for the search receives the case of B-TREE (Figure 8), while the number ecuted until a sought student was found 10,000,000 were performed using three different keys (20, a parameter, which contains the sought key. This of students (keys) increases, the number of itera- times, each testing problem was executed 30 times 1000, and 1000000). Based on the iterations, the value enters into an iterative process, which per- tions becomes constant. Binary search, on the other by each algorithm, and the average was calculated, lower and upper bounds were calculated for each forms a search descending through the branches hand, increases its number of iterations. which is shown in Figure 9. number of keys. There is a range of iterations re- of the tree, depending whether the desired key is According to the results shown in Figure 8, it quired to find a specific student when using the B- The comparison presented in Figure 9 shows the higher or lower than the root node. If the sought can be concluded the B-TREE search is more ef- TREE algorithm. The obtained results are shown in relationship between the number of students used key is found, the algorithm returns the value of the ficient than Binary search for 5 n 200, due to key. It returns -1 if the student or teacher has not Figure 7. ≤ ≤ and the time required to find a specific student for the theoretical analysis which demonstrated that B- both algorithms. Some changes were applied to the been found. The range shown in Figure 7 for each quantity TREE needs fewer iterations to find a specific stu- B-TREE algorithm; the variations were the value of of students indicates the possible number of itera- dent than Binary search, working under the same m used in the tree. tions required to find a specific student, which is a conditions (number of students n, and value of m). 5 Computational Results function of the input size. The range could be de- According to the experimental results shown in Nevertheless, the exact number of iterations re- Figure 9, it can be seen that the efficiency of both Two types of testing were performed to prove fined as R = UB – LB, where UB is the maximum quired for the B-TREE search will depend on the algorithms, taking into account the three versions the efficiency and efficacy of both algorithms. First number of iterations, and LB refers to the minimum implementation of the algorithm. of B-TREE search, is similar when n is between 5 of all, the range of iterations required to find a number of iteration that can be generated by the B- and 10 students. After 15 students, the behavior of specific student or teacher (sought key) was calcu- TREE search according to Equations 3 and 4. It is 5.2 Experimental Results B-TREE search (according to the number of itera- lated theoretically. For B-TREE, equations 3 and worth mentioning that for any value of n, the value tions), using trees with different m, is not uniform; 4 were used to obtain the lower and upper bound of R will be large if the number of pointers is small. The experimental tests of both algorithms B- it varies depending on the number of students. This corresponding to a search with certain character- Therefore, the value of R decreases and remains al- TREE search (Figure 6), and Binary search (Fig- is unlike the behavior shown by the Binary search, istics, such as number of students or teachers to most constant as the number of pointers increases. ure 5) were performed in a personal computer with which is a function of the number of students con- be searched. For Binary search, the same condi- As was done with the B-TREE search, theoreti- an Intel Xeon processor 3.0 GHz, 2 GB RAM, and sidered. tions were used to calculate the maximum number cal calculations were made with the Binary search. windows XP professional as the operating system. formed using equation 2. These results were compared with results obtained from equations 3 and 4 for a B-TREE with m = 5. The comparison is shown in figure 8. The graph shown in Figure 8 represents a comparison between the analyzed algo- rithms, Binary search and B-TREE search, with respect to the number of iterations required to find a desired student if the quantity of students varies (Keys). the results showed that the B-tRee search needs less iterations than Binary search in all the cases. in the case of B-tRee (figure 8), while the number of students (keys) increas- es, the number of iterations becomes constant. Binary search, on the other hand, in- 260 creases its number of iterations. Cruz Chvez M. A., Martnez Oropeza A.

the testing problems used during the experimental tests were randomly generated. the sets of n students evaluated by both algorithms to prove their efficiency were generated using pseudo-random numbers ranked in ascending order. each testing problem was evaluated using both algorithms (fig. 5 and fig. 6). in the case of B- TREE search, the experimental tests were performed using different m (m = 3, m = 4, m = 5 and m = 30). the experimental tests were computed using several testing problems varying the value of n (students), where 5 ≤ n ≤ 1000. Each algorithm was executed until a sought student was found 10,000,000 times, each testing problem was executed 30 times by each algorithm, and the average was calculated, which is shown in Figure 9. the comparison presented in figure 9 shows the relationship between the number of students used and the time required to find a specific student for both algorithms. Figure 8. ComparativeSomeFig. changes 8. Comparative were graph applied graph of theoretical ofto theoreticalthe B-tRee results results algorit of Bhm;-tRee of the B-TREE search variations vs. Binary search were search. the vs. value Binary search of m used in the tree. According to the results shown in figure 8, it can be concluded the B-tRee search is more efficient than Binary search for 5 ≤ n ≤ 200, due to the theoretical analysis which demonstrated that B-tRee needs fewer iterations to find a specific student than Binary search, working under the same conditions (number of students n, and value of m). Nevertheless, the exact number of iterations required for the B-TREE search will depend on the implementation of the algorithm.

5.2 Experimental Results the experimental tests of both algorithms B-tRee search (figure 6), and Binary search (figure 5) were performed in a personal computer with an Intel Xeon proces- sor 3.0 GHz, 2 GB RAM, and windows XP professional as the operating system. the compiler used to program both algorithms was Visual C++ 2008.

In spite of the theoretical results obtained in section 5.2, where the B-tRee search was the most efficient algorithm, the experimental results presented in Figure 9 show a different situation. Binary search demonstrated convincingly that it is more efficient than any variation of B-tRee search for small ranges; in this case a range of 5 ≤ n ≤ . ExperimentalFig. 9. experimental results: B-TREEresults: B-tRee search search (applying different different orders) vs. orders) Binary search, vs. Binary search, Figure 9 550 ≤ waskey ≤used 50. . in spite of the theoretical results5 obtainedkey in50 section. 5.2 that show the B-tRee searchAccording as the mostto the efficient experimental algorithm, results≤ figure shown≤ 10 in sh Figureows a 9,different it can be situation seen that for the up e tof- 75ficiency students. of both Binary algorithms, search demonstratedtaking into account convincingly the three that versions it is moreof B- tReeefficient search, than isany similar variation when of nB -istRee between search 5 and for 10small students ranges,. A wherefter 15 50 students, ≤ n ≤ 75 the. behavior of B- tRee search (according to the number of iterations), using trees with different m, is not uniform; it varies depending on the number of students. this is unlike the behav- ior shown by the Binary search, which is a function of the number of students consid- ered.

Figure 10. ExperimentalFig. 10. experimental results: results: B-TREE B-tRee search search (applying (applying different orders) different vs. Binary orders) search, vs.50 Binary search, ≤ key ≤ 100. 50 key 100. in figure 11, the student ranges≤ increase≤, where 50 ≤ n ≤ 1000. for B-tRee search, trees of the order 3, 5, and 30 were used. the obtained results show a different situation when compared with Figures 9 and 10. in this case, Binary search is not the best algorithm. it can be observed that, unlike for small ranges, for large values of n, the m value of the tree used in B-tRee search is important. According to figure 11, B-tRee search is the best option, because it involves less computing time than Binary search. it is interesting because according to the results for 75 < n ≤ 1000, the best option is B-tRee search using a tree order 5. B-tRee with a tree order 30 is a good option too because it is more efficient than Binary search. on the contrary, B-TREE with a tree order 3 presents worse behavior than Binary search.

Cruz Chvez M. A., Martnez Oropeza A. B-TREE ALGORITHM COMPLEXITY ANALYSIS TO . . . 261

In spite of the theoretical results obtained in sec- B-TREE search with m = 5, and m = 30, demon- tion 5.2, where the B-TREE search was the most strated itself to be more efficient than Binary search. efficient algorithm, the experimental results pre- This study proves that B-TREE search is a very sented in Figure 9 show a different situation. Binary efficient algorithm when it is necessary to manage search demonstrated convincingly that it is more a lot of data. Due to this, B-TREE search and its efficient than any variation of B-TREE search for variants are commonly used in Relational small ranges; in this case a range of 5 n 50 was ≤ ≤ Management Systems to access data quickly [10, used. 11]. In spite of the theoretical results obtained in sec- The theoretical complexity is an asymptotic tion 5.2 that show the B-TREE search as the most complexity which is evaluated in the worst case. efficient algorithm, Figure 10 shows a different sit- The results in Section 5.1 are justified for large val- uation for up to 75 students. Binary search demon- ues of n. This is seen in Figure 11, where B-TREE strated convincingly that it is more efficient than . Comparative graph of theoretical results of B-TREE search vs. Binary search shows better performance for a value of m 5. One Figure 8 ≥ any variation of B-TREE search for small ranges, of the reasons that the Binary search is more effi- where 50 n 75. ≤ ≤ cient than B-TREE search for small ranges of stu- In Figure 11, the student ranges increase, where dents is the number of instructions that must be 50 n 1000. For B-TREE search, trees of the or- evaluated. B-TREE requires fewer iterations, but ≤ ≤ der 3, 5, and 30 were used. The obtained results it evaluates more instructions in each one, unlike show a different situation when compared with Fig- Binary search, which performs a greater number of ures 9 and 10. In this case, Binary search is not the iterations, but each iteration evaluates fewer instruc- best algorithm. It can be observed that, unlike for tions. small ranges, for large values of n, the m value of the tree used in B-TREE search is important. 6 Conclusion According to Figure 11, B-TREE search is the best option, because it involves less computing time In conclusion, according to theoretical com- than Binary search. It is interesting because accord- plexity of B-TREE search and Binary search, the ing to the results for 75 < n 1000, the best option ≤ number of iterations to be evaluated is smaller in B- is B-TREE search using a tree order 5. B-TREE TREE search than in Binary search, but the number Figure 9. Experimental results: B-TREE search (applying different orders) vs. Binary search, with a tree order 30 is a good option too because it of instructions evaluated experimentally in Binary 5 key 50. is more efficient than Binary search. On the con- search is smaller than B-TREE to n ¡ 200. ≤ ≤ trary, B-TREE with a tree order 3 presents worse Theoretically, there are two cases for B-TREE. behavior than Binary search. The first one generates a complete tree and the sec- Using 5 key 50, some experimental tests ≤ ≤ ond one generates an incomplete one. In the second were performed with the B-TREE search increas- case, due to its incompleteness, the tree depth tends ing the order of the tree (m = 8, 9, 10, 18, 19, and to be higher than a complete one. As a result, the 20) to analyze how the order of the tree affects the number of iterations required to find a sought stu- efficiency of the algorithm. The results are shown dent increases. in Figure 12. Experimental results showed that Binary search According to Figure 12, we can conclude that is more efficient than any version of B-TREE search increasing the tree order does not necessarily im- evaluated in this research, for less than 200 stu- prove the algorithm efficiency, considering that the dents. However, for more than 200 students, B- behavior of the algorithm is very similar in the six TREE demonstrated itself to be faster. The reason cases shown for a specific range of key. for this behavior is the number of instructions to be Contrary to their theoretical complexity re- evaluated. B-TREE requires fewer iterations, but it evaluates more instructions in each one. This is un- Figure 10. Experimental results: B-TREE search (applying different orders) vs. Binary search, ported in literature, Binary search demonstrated it- like Binary search, which performs a greater num- 50 key 100. self to be better than B-TREE search in all cases ≤ ≤ on all the tests performed using a small rage of stu- ber of iterations, but it evaluates fewer instructions dents 5 key 75. For bigger values of key > 75, per iteration. ≤ ≤ 262 Cruz Chvez M. A., Martnez Oropeza A.

Figure 11. ExperimentalFig. 11. results:experimental Comparison results: Comparison between between B B-TREE-tRee search search,, and Binary and search Binary using search using large large student ranges, 50student ≤ key ≤ 1000 ranges,. 50 key 1000. ≤ ≤ Using 5 ≤ key ≤ 50, some experimental tests were performed with the B-tRee search increasing the order of the tree (m = 8, 9, 10, 18, 19, and 20) to analyze how the order of the tree affects the efficiency of the algorithm. the results are shown in figure 12. According to figure 12, we can conclude that increasing the tree order does not necessarily improve the algorithm efficiency, considering that the behavior of the algorithm is very similar in the six cases shown for a specific range of key. Contrary to their theoretical complexity reported in literature, Binary search quidemonstratedres fewer iterationsitself to ,be but better it evaluates than B- tReemore instructionssearch in all in case eachs onone, all unlike the tests Binary per- search,formed using which a performssmall rage a of greater students number 5 ≤ key of ≤ iteration 75. fors ,bigger but each values iteration of key evaluates > 75, B- tReefewer instructions.search with m = 5, and m = 30, demonstrated itself to be more efficient than Binary search. this study proves that B-TREE search is a very efficient algorithm when it is nec- essary to manage a lot of data. Due to this, B-tRee search and its variants are com- monly used in Relational Database management Systems to access data quickly [10, 11]. the theoretical complexity is an asymptotic complexity which is evaluated in the worst case. the results in Section 5.1 are justified for large values of n. this is seen in Figure 11, where B-TREE shows better performance for a value of m > = 5. one of the reasons that the Binary search is more efficient than B-tRee search for small ranges of students is the number of instructions that must be evaluated. B-tRee re-

Fig. 12. experimental results: B-tRee search increasing the order of the tree for 5 ≤ key ≤ 50. Figure 12. Experimental results: B-TREE search increasing the order of the tree for 5 key 50 ≤ ≤ 6 Conclusion

in conclusion, according to theoretical complexity of B-tRee search and Binary search, the number of iterations to be evaluated is smaller in B-tRee search than in Binary search, but the number of instructions evaluated experimentally in Binary search is smaller than B-tRee to n < 200. theoretically, there are two cases for B-tRee. the first one generates a complete tree and the second one generates an incomplete one. in the second case, due to its incompleteness, the tree depth tends to be higher than a complete one. As a result, the number of iterations required to find a sought student increases. Experimental results showed that Binary search is more efficient than any version of B-tRee search evaluated in this research, for less than 200 students. However, for more than 200 students, B-tRee demonstrated itself to be faster. the reason for this behavior is the number of instructions to be evaluated. B-TREE requires fewer itera- tions, but it evaluates more instructions in each one. this is unlike Binary search, which performs a greater number of iterations, but it evaluates fewer instructions per iteration. Cruz Chvez M. A., Martnez Oropeza A. B-TREE ALGORITHM COMPLEXITY ANALYSIS TO . . . 263

With the results obtained experimentally, it can ISBN 0-13-117686-2. be concluded that in the case of the University [5] B. Paechter, R. C. Ranking, A. Cumming and T. Course Timetabling Problem, the best option is to C. Fogarty, Timetabling the Classes of an En- implement a combination of a Binary search and a tire University with an Evolutionary Algorithm. B-TREE algorithm, because the number of students Parallel Problem Solving from Nature (PPSN) is different in each class, ranging from 5 to 300 stu- V. Lectures Notes in 1498, dents in a typical case of UCTP. To find overlaps Springer-Verlag, Berlin, pp. 865-874, 1998. of students in timeslots when a class has up to 75 [6] O. Rossi-Doria, M. Samples, M. Birattari, M. students, a Binary search should be used. When a Chiarandini, M. Dorigo, L. M. Gambardella, class has over 75 students, a B-TREE search should J. Knowles, M. Manfrin, M. Mastrolilli, B. be used. Following these guidelines, testing to en- Paechter, L. Paquete, and T. Sttzle. A Comparison sure satisfaction of H1 and H2 type constraints in of the Performance of Different Metaheuristics on UCTP models can be done more efficiently. the Timetabling Problem, Lecture Notes in Com- puter Science, Vol. 2740 pp. 329-351. Springer- Verlag, Berlin, Germany, 2003. References [7] J. F. Korsh, Data Structures, Algorithms and Pro- gram Style, ISBN: 0871509369, PWS Computer [1] M.R. Garey, and D.S. Johnson, Computers and Science, USA, p. 499, 1986. Figure 11. Experimental results: Comparison between B-TREE search, and Binary search using large Intractability, A Guide to the Theory of NP- student ranges, 50 key 1000. Completeness, W.H. Freeman and Company, [8] O. Cair, and S. Guardati., Data Structures, ISBN: ≤ ≤ New York, USA, ISBN 0-7167-1044-7, 1979. 9701059085, McGraw-Hill, p. 423, Mxico 2006. [2] S. Even, A. Itai, and A. Shamir, On the Complex- [9] D. F. Stubbs and N. W. Webre, Data Struc- ity of Timetable and Multicommodity Flow Prob- tures with Abstract Data Types and Pascal, ISBN: lems, SIAM Journal on Computing, 5(4):691- 0534092640, Brooks/Cole Pub. Co., p. 471, 1994. 703, ISSN 0097-5397, 1976. [10] T. H. Cormen, C. E. Leiserson and C. D. Stein, In- [3] C. H. Papadimitriou and K. Steiglitz, Combina- troduction to Algorithms, 2nd Edition. Mit Press, torial Optimization: Algorithms and Complex- U.S.A., ISBN 0-262-03293-7, 2001. ity, Dover Publications Inc., U.S.A., ISBN 0-486- 40258-4, p. 496, 1998. [11] T. Cunnolly and C. Begg, Database Systems, A Practical Approach to Design, Implementation [4] R. Johnsonbaugh, Discrete Mathematics, 6th Edi- and Management, Fourth Edition, Addison Wes- tion, Prentice Hall, U.S.A., ISBN 0-13-117686-2, ley, U.S.A., ISBN 0-201-70857-4, 2004.

Figure 12. Experimental results: B-TREE search increasing the order of the tree for 5 key 50 ≤ ≤