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?
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.
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 with my ZeroDenominatorException. How do I implement it to where if the denominator...
I'm having trouble with my ZeroDenominatorException. How do I implement it to where if the denominator is 0 it throws the ZeroDenominatorException and the catch catches to guarantee that the denominator is never 0. /** * The main class is the driver for my Rational project. */ public class Main { /** * Main method is the entry point to my code. * @param args The command line arguments. */ public static void main(String[] args) { int numerator, denominator =...
I'm having trouble with validating this html code. Whenever I used my validator, it says I...
I'm having trouble with validating this html code. Whenever I used my validator, it says I have a stray end tag: (tbody) from line 122 to 123. It's the last few lines. Thanks and Ill thumbs up whoever can help solve my problem. Here's my code: <!DOCTYPE html> <html lang="en"> <head> <title>L7 Temperatures Fields</title> <!--    Name:    BlackBoard Username:    Filename: (items left blank for bb reasons    Class Section: (blank)    Purpose: Making a table to demonstrate my...
Directional and non-directional Hello! I'm having som trouble understanding the meaning of directional and non-directional hypothesis....
Directional and non-directional Hello! I'm having som trouble understanding the meaning of directional and non-directional hypothesis. What does it mean, and how do this affect the p-value? I also heard about "negative directional alternative" but could not find any information about this Thank you!
Hi, I'm having trouble understanding "symbolic microprogram" in Computer Organization and Architecture 2. Can someone please...
Hi, I'm having trouble understanding "symbolic microprogram" in Computer Organization and Architecture 2. Can someone please solve any example and explain it in details so I can understand it? Thank you in advance. NOTE: Please use Computer System Architecture (3rd edition)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT