I have the following question:
Let A=[84,33,72,60,22,63] be an array of numbers.
We want to sort A using Quicksort where the pivot is chosen randomly.
At the end of the **first iteration** it might be that A will be?
1.A=[63,33,72,60,84,22]
2.A=[84,33,72,60,22,63]
3.A=[22,33,72,60,84,63]
I would love an explanation, I can not understand why I can not get to one of the answers shown. Thanks in advance.
There are 6 numbers in this array hence if you randomly pick a pivot point the first iteration might have 6 possible results. For example if 84 is picked at random the first iteration would result in
A = [33,72,60,22,63,84]
As you can see 84 was the biggest number in the list so all the entries on the right was moved to the left during the search.
Related
Further to this Thread:
I am trying to write a formula that returns maximum frequency of non blank lines and not "W"s in column B of the array shown here
This formula returns max consecutive non-W recurrences in the array:
=ArrayFormula(MAX(FREQUENCY(if(Result<>"w", ID), if(Result<>"w", 0, ID))))
And I was hoping this formula would return max consecutive non-W (<>="W") and non-blanks (<>=""), but for some reason, it doesn't return the required input:
=ArrayFormula(MAX(FREQUENCY(if(Result<>"w", if(Result<>"", ID)), if(Result<>"w", if(Result<>"", 0, ID)))))
I understand that for this example I can search for "L"s, however, I am dealing with much more complicated arrays that have multiple values and blank lines, so solving this issue should help me solve a much bigger dataframe issue I'd like to share with my colleagues on spreadsheets.
PS: If you think the solution is best in Apps Script, I'm happy for any guidance.
Thanks a lot in advanced.
I have addresses database (as hashes) with about 30 millions records. I was adding text index to all addresses fields. Searching looks ok until I want to search word which occur in many records. For example searchin word "London" which occur in about 2500000 records took 4,5 seconds (FT.SEARCH idx:a4 london LIMIT 0 2). Is it any possibility to improve this result, any changes to make? Thank you for help.
If you do not care about getting the first 2 results sorted by scoring (calculated by tfidf), you can use FT.AGGREGATE which will just return after finding the first 2 results (without getting all the results, calculating the score, sort them, and get the first 2 results). It should look like this:
FT.AGGREGATE idx:a4 london LIMIT 0 2
Notice that you should use LOAD to decide which fields to return from the hash. Please refer here for the full FT.AGGREGATE documentation:
https://oss.redislabs.com/redisearch/Aggregations/
Again if you chose to use it, know that you are losing sorting by results score.
I have a text file that contains over 11 thousand multiple choice and matching questions. The questions have different sizes, besides having different number of given choices. The following block is a sample of matching question with five given choices taken from that text file:
Type: MT
1) Can you match each of these cities to their location? Drag the cities on the right to match them with the locations on the left.
~ Correct. You got all these matches correct.
# Incorrect. You got some of these wrong.
a. North = Turin
b. Center = Rome
c. South = Naples
d. Sicily = Palermo
e. Sardinia = Cagliari
Before processing this file into a HTML generating engine, I need to shuffle all those questions, i.e. to randomly change the position of each question as a block in the file, so the final product will be extremely unpredictable. Each question number (as mentioned under Type:) is insignificant.
I found a Word vba code at this link, but it does need lots of expert alterations to accommodate variant sizes of questions.
Expert assistance in this matter is deeply appreciated. Thanks in advance.
First, I agree with Tim Williams in the comments above that this is not exactly the level of specificity that is expected in a StackOverflow posting.
That said, if I were you, I would break this question down into two components.
First - figure out if there is a text string that can be used to identify the blocks that constitute the "question." For example, if each question starts with "Type:", then you can find the first instance of this in the file, then find the second, and everything between them constitutes a "question". Then, you can place that question in an array.
Second - randomize the array. There are probably a ton of ways to do this. One might be to use a randbetween function between 0 and the length of the array of questions twice, and switch the questions for each of the random numbers. Then, repeat that a number of times relative to the total number of items in the array (for example, if you have 100 questions, perform the "switch" 125 times to sufficiently randomize the output. Then print the array back to the original file.
For the approach above, you need some delimiter in your file (I assumed the delimiter was "Type:") to break the questions above. If a delimiter like this doesn't exist, you may need some more complicated logic.
I have a number of large sorted sets (5m-25m) in Redis and I want to get the first element that appears in a combination of those sets.
e.g I have 20 sets and wanted to take set 1, 5, 7 and 12 and get only the first intersection of only those sets.
It would seem that a ZINTERSTORE followed by a "ZRANGE foo 0 0" would be doing a lot more work that I require as it would calculate all the intersections then return the first one. Is there an alternative solution that does not need to calculate all the intersections?
There is no direct, native alternative, although I'd suggest this:
Create a hash which its members are your elements. Upon each addition to one of your sorted sets, increment the relevant member (using HINCRBY). Of course, you'll make the increment only after you check that the element does not exist already in the sorted set you are attempting to add to.
That way, you can quickly know which elements appear in 4 sets.
UPDATE: Now that I rethink about it, it might be too expensive to query your hash to find items with value of 4 (O(n)). Another option would be creating another Sorted Set, which its members are your elements, and their score gets incremented (as I described before, but using ZINCRBY), and you can quickly pull all elements with score 4 (using ZRANGEBYSCORE).
I am relatively new to the world of programming and I was wondering if anybody could help me with a small project. I am trying to create two programs in VB.Net that each do one of the following individual actions:
Find the average grade given several user-inputted scores on assignments. The program should also provide the following feedback according to the final score (i.e. A, B, C, D, F).
Run two separate threads printing numbers (or words) in ascending and descending orders. (The numbers (or words) should be given by the user.)
I have a basic understanding of VB.Net, but I am having trouble when it comes to creating even remotely complex programs. I have a few ideas on how I may go about these, such as using an arraylist for the first question that takes user input to find the grades, and then uses a series of If-Then-Else statements to display the letter grade, and possibly using steps simply with dual threading that would result in numerical order being printed in ascending order and descending order. Any help or advice would be greatly appreciated.
P.S.
I will be adding the code I have so far for both of these programs shortly. In the meantime, if you can help me at all with the information I have given you, it would be helpful.
Here's some pseudocode to help you get started on #1:
get list of scores from user input (Console.Readline() if this is a console app)
assign scores to an array or list (List would be a good choice)
get the total score (assuming they're not weighted, if you have a List then you can just use the Sum() method)
get the number of grades (again, if you have a List then you can use Count() method)
divide total by count to get average (if you need a decimal average, you'll have to cast your values to double first, or if your average can be an int just leave them all as int)
use an if-then-else to compare the average to each grade cutoff (if > 90 then "A", else if > "80" then "B", etc)