Question

In: Computer Science

I'm having trouble understanding the following code (a snippet of a code). What does it do?...

I'm having trouble understanding the following code (a snippet of a code). What does it do? The whole code is about comparing efficiencies of different algorithms.

def partition(list,first,last):
piv = list[first]
lmark = first+1
rmark = last
done = False

while not done:
while lmark <= rmark and list[lmark]<=piv:
lmark=lmark+1
while list[rmark]>=piv and rmark>=lmark:
rmark=rmark-1

if rmark<lmark:
done = True
else:
temp = list[lmark]
list[lmark]=list[rmark]
list[rmark]=temp

temp = list[first]
list[first]=list[rmark]
list[rmark]=temp
return rmark

Solutions

Expert Solution

Sorry for the background test in the middle image but it is looking fine to understand that's why I'm uploading that image... .

I think now you got the picture of the given snippet gow it works for elements....

If you feel anything difficult to understand you can comment below and if you like the answer upvote it ......


Related Solutions

I'm having trouble understanding a CS assignment. I would appreciate it if you all code do...
I'm having trouble understanding a CS assignment. I would appreciate it if you all code do this for me. The template for the lab is below which you must use. You're only supposed to create/edit the product function. The assignment has to be written in asm(Mips) You will need to create a NOS table and use the structure below and write a function called product. The structure used in this program is: struct Values { short left; short right; int...
hello, I'm having trouble understanding how to do these two problems could you show me a...
hello, I'm having trouble understanding how to do these two problems could you show me a step by step. 1)Eight sprinters have made it to the Olympic finals in the 100-meter race. In how many different ways can the gold, silver, and bronze medals be awarded? 2)Suppose that 34% of people own dogs. If you pick two people at random, what is the probability that they both own a dog? Give your answer as a decimal (to at least 3...
We are learning about Ramayana in Mythology and I'm having a bit of trouble understanding the...
We are learning about Ramayana in Mythology and I'm having a bit of trouble understanding the story. Why would Rama be set apart as a true hero? The story of Rama and Sita is a favorite story that parents tell their children. What purpose does the Ramayana serve as an instructional story for Indian culture? What effect do the test and temptations have on the heroic character?
I am having trouble with a C++ code that I'm working on. It is a spell...
I am having trouble with a C++ code that I'm working on. It is a spell checker program. It needs to compare two arrays, a dictionary, and an array with misspelled strings that are compared to the strings in the dictionary. the strings that are in the second array that is not in the Dictionary are assumed to be misspelled. All of the strings in the dictionary are lowercase without any extra characters so the strings that are passed into...
I'm having trouble with my do while loop. I'm trying to get it where if the...
I'm having trouble with my do while loop. I'm trying to get it where if the user enter's 3 after whatever amount of caffeinated beverages they've entered before then the loop will close and the rest of my code would proceed to execute and calculate the average price of all the caffeinated beverages entered. Can someone please help me with this? Here's my Code: import java.util.Scanner; public class Main { public static void main(String[] args) { CaffeinatedBeverage[] inventory = new...
If anyone could simplify this for me. I'm having trouble understanding the material and I just...
If anyone could simplify this for me. I'm having trouble understanding the material and I just need a keep it simple stupid approach Discuss the various non influential as well as influential investments that company may have on their financial statements. Also compare and contrast how they are treated/recorded on the companies financial statements.
I'm having trouble understanding smart pointer functions what is get(), release(), reset(), swap() for unique pointers?...
I'm having trouble understanding smart pointer functions what is get(), release(), reset(), swap() for unique pointers? How do I use it? what is get(), reset(), swap(), unique(), use_count() for shared pointers? How do I use it? what is expired(), lock(), reset(),swap(), use_count for weak pointer? How do I use it?
MICROBIOLOGY: I'm having trouble understanding the role of thermal death time and thermal death point in...
MICROBIOLOGY: I'm having trouble understanding the role of thermal death time and thermal death point in proper sterilization. Can someone please explain the role of both in proper sterilization?
I am having trouble understanding the following: When interest rates are low (decreasing) what impact does...
I am having trouble understanding the following: When interest rates are low (decreasing) what impact does it have on the profitability of commercial banks, finance companies, insurance companies, security firms, and mutual funds? Additionally, what exactly could they do to combat this? Short simple explanations work! Thanks.
I'm having trouble figuring out what the standard deviation is for the following problem. Common stock...
I'm having trouble figuring out what the standard deviation is for the following problem. Common stock of Escapist Films sells for $30 a share and offers the following payoffs next year: Boom 0 $21 Normal $1 $32 Recession $3 $36 The expected return of Escapist is: Boom -30% Normal 10% Recession 30% Calculate the standard deviation of Escapist.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT