Show
Terms in this set (19)Students also viewedSets found in the same folderOther sets by this creatorVerified questionscomputer science Verified answer
computer science Relate to a recursive sorting algorithm called QuickSort, which is described as follows: A one-element list is already sorted; no further work is required. Otherwise, take the first element in the list, call it the pivot element, then walk through the original list to create two new sublists, $L_{1}$ and $L_{2}.$ $L_{1}$ consists of all elements that are less than the pivot element and $L_{2}$ consists of all elements that are greater than the pivot element. Put the pivot element between $L_{1}$ and $L_{2}.$ Sort each of L1 and L2 using QuickSort (this is the recursive part). Eventually all lists will consist of 1 element sublists separated by previous pivot elements, and at this point the entire original list is in sorted order. This is a little confusing, so here is an example, where pivot elements are shown in brackets: Original list: 6, 2, 1, 7, 9, 4, 8; After 1st pass: 2, 1, 4, [6], 7, 9, 8; After 2nd pass: 1, [2], 4, [6], [7], 9, 8; After 3rd pass: 1, [2], 4, [6], [7], 8, [9] Sorted. How many comparisons between list elements are required for pass 1 of QuickSort on an n-element list? Verified answer
computer science Verified answer
computer science Verified answer Recommended textbook solutions
Other Quizlet setsAn algorithm is a procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed. An algorithm is merely the sequence of steps taken to solve a problem. The steps are normally "sequence," "selection, " "iteration," and a case-type statement. In C, "sequence statements" are imperatives. The "selection" is the "if then else" statement, and the iteration is satisfied by a number of statements, such as the "while," " do," and the "for," while the case-type statement is satisfied by the "switch" statement. Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode is a "text-based" detail (algorithmic) design tool. The rules of Pseudocode are reasonably straightforward. All statements showing "dependency" are to be indented. These include while, do, for, if, switch. Examples below will illustrate this notion. GUIDE TO PSEUDOCODE LEVEL OF DETAIL: Given record/file descriptions, pseudocode should be created in sufficient detail so as to directly support the programming effort. It is the purpose of pseudocode to elaborate on the algorithmic detail and not just cite an abstraction. Examples: 1.. If student's grade is greater than or equal to 60
endif 2. Set total to zero Set grade counter to one While grade counter is less than or equal to ten
endwhile Set the class average to the total divided by ten Print the class average. 3. Initialize total to zero Initialize counter to zero Input the first grade while the user has not as yet entered the sentinel
endwhile if the counter is not equal to zero
else
endif 4. initialize passes to zero initialize failures to zero initialize student to one while student counter is less than or equal to ten
else
endif endwhile print the number of passes print the number of failures if eight or more students passed
endif Some Keywords That Should be Used And Additional PointsFor looping and selection, The keywords that are to be used include Do While...EndDo; Do Until...Enddo; While .... Endwhile is acceptable. Also, Loop .... endloop is also VERY good and is language independent. Case...EndCase; If...Endif; Call ... with (parameters); Call; Return ....; Return; When; Always use scope terminators for loops and iteration.As verbs, use the words Generate, Compute, Process, etc. Words such as set, reset, increment, compute, calculate, add, sum, multiply, ... print, display, input, output, edit, test , etc. with careful indentation tend to foster desirable pseudocode. Also, using words such as Set and Initialize, when assigning values to variables is also desirable.
More on Formatting and Conventions in PseudocodingDo not include data declarations in your pseudocode.
Function Calls, Function Documentation, and Pseudocode
Source CodeSPELLING ERRORS ARE NOT ACCEPTABLE What are the three types of operations used to construct algorithms?Terms in this set (25) The three types of ____ used to construct algorithms are sequential, conditional, and iterative.
Which of the following is an example of algorithm?Common examples include: the recipe for baking a cake, the method we use to solve a long division problem, the process of doing laundry, and the functionality of a search engine are all examples of an algorithm.
When can an algorithm fall into an infinite loop?If we will provide more memory than again loop will start running. So, it means when the condition of the loop never becomes false the loop will never terminate. Hence, An algorithm can fall into an infinite loop when the condition of the loop never becomes false.
Can an algorithm lead to an infinite loop?Algorithm is finite set of statements that ends its execution in a finite time and produces some output. Therefore, Having an infinite loop in an algorithm is an error.
|