Write a (list-based) insertion sort algorithm in Prolog. Heres what it looks like in C, using arrays:
Question:
Write a (list-based) insertion sort algorithm in Prolog. Here’s what it looks like in C, using arrays:
Transcribed Image Text:
void insertion_sort(int A[], int N) int i, j, t; for (i = 1; i < N; i++) { %3D t = A[i]; for (j = i; j > 0; j--) { if (t >= A[j-1]) break; A[j] A[j-1]; A[j] = t; }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 83% (6 reviews)
Here is a listbased insertion sort algorithm in Prolog insertionsortList Sor...View the full answer
Answered By
Churchil Mino
I have been a tutor for 2 years and have experience working with students of all ages and abilities. I am comfortable working with students one-on-one or in small groups, and am able to adapt my teaching style to meet the needs of each individual. I am patient and supportive, and my goal is to help my students succeed.
I have a strong background in math and science, and have tutored students in these subjects at all levels, from elementary school to college. I have also helped students prepare for standardized tests such as the SAT and ACT. In addition to academic tutoring, I have also worked as a swim coach and a camp counselor, and have experience working with children with special needs.
0.00
0 Reviews
10+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
A compare-exchange operation on two array elements A[i] and A[j], where i < j, has the form COMPARE-EXCHANGE (A, i, j) 1 If A[i] > A[j] 2 exchange A[i] with A[j] After the compare-exchange operation,...
-
Quicksort works well for large lists, but has higher overhead than insertion sort for short lists. Write a sort algorithm in Prolog that uses quicksort initially, but switches to insertion sort (as...
-
The purpose of this assignment is to give you practice working with arrays, passing them to functions, sorting, searching and reading and writing text files. In this program you will read two files...
-
The following data are from the accounting records of Niles Castings for year 2: Units produced and sold . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85,000 Total revenues and costs Sales...
-
Evaluate the effect of removing the upstream bridge at section 106365 on the backwater profile in HEC-RAS?
-
In Exercises 5 and 6, describe and sketch the surface given by the function. g(x, y) = x
-
Consider a market with two securities, one of them risk free with rate of return \(R\), and three future states. Suppose that the risky security has a present value \(S_{1}\) and can take three...
-
Annual revenue for Corning Supplies grew by 5.5% in 2007; 1.1% in 2008; 3.5% in 2009; 1.1% in 2010; and 1.8% in 2011. What is the mean growth annual rate over this period?
-
4 Smallman's Garage uses standards to plan and control labor time and expense. The standard time for an engine tune-up is 3.75 hours. and the standard labor rate is $15 per hour. Last week, 26...
-
Which of the graphs in Fig. Q25.12 best illustrates the current I in a real resistor as a function of the potential difference V across it? Explain. Figure Q25.12 (a) (b) (c) (d)
-
Write a Prolog sorting routine that is guaranteed to take O(n log n) time in the worst case.
-
Use the clause predicate of Prolog to write a predicate call_bfs that attempts to satisfy goals breadth-first.
-
What characteristic of a normal quantile plot indicates that the data follow a distribution that is approximately normal?
-
Explain the red flags that should have alerted the auditors to the financial shenanigans at Sunbeam. Also, to what extent do you believe the auditors should have considered Sunbeam's culture in...
-
Consider the following information about a photography business Leila opened last year: Price = $70 per unit Quantity sold = 12,500 Implicit cost = $95,000 Average material cost = $55 per unit...
-
Consider the following information about a roofing business Taylor opened last year: Taylor was a manager at Stater Bros, with an annual salary (including benefits) of $50,000 per year. Taylor has...
-
what is the current industry standard for data transfer and provides a comprehensive list of data elements?
-
Consider the following information about a mobile car wash business Joel opened last year: Price = $20 per unit Quantity sold = 39,196 Implicit cost = $61,977 Average material cost = $9 per unit...
-
Gala Fruit Corp's accounting records include the following items, listed in no particular order, at December 31, 2014. Other gains (losses)........................$(12,500).............Net sales...
-
Use the graphs of f and g to graph h(x) = (f + g) (x). To print an enlarged copy of the graph, go to MathGraphs.com. 1. 2. y 24 8. 2. -2 -2 4 6
-
This exercise examines the accuracy of various branch predictors for the following repeating pattern (e.g., in a loop) of branch outcomes: T, NT, T, T, NT 1. What is the accuracy of always-taken and...
-
This exercise explores how exception handling affects pipeline design. The first three problems in this exercise refer to the following two instructions: Instruction 1...................Instruction 2...
-
In this exercise we compare the performance of 1-issue and 2-issue processors, taking into account program transformations that can be made to optimize for 2-issue execution. Problems in this...
-
Write a function that takes in a value x, a value el, and a list and adds as many el's to the end of the list as there are x's in the list. Make sure to modify the original list using list mutation...
-
Our office building has a total square footage of 120,000 square feet.We have 9 tenants in the building and no vacancies.The total square footage of the tenant spaces is 105,000.A) What is the Load...
-
00 00 1) A state transition diagram for a synchronous finite state machine is shown in Figure 3. Derive the combinatorial logic required to implement this FSM with the use of Karnaugh maps. Note that...
Study smarter with the SolutionInn App