| || |
Get numbers inside all webelements in webtable and sort them
I have attended QTP interview @broadridge hyd he asked me this question
webtable was there 3 rows 3 columns inside webtable all are webelemnts and 9 numbers(3,1,9,4,7,2,6,5,8) were there inside these webelements.we have to retrieve all these 9 numbers and sort them.
I have written this below code please check once and let me now anything wrong and if any better solutions for this.
For i = 1 To rc
For j = 1 To cc
For i=0 To ubound(b)
For j=0 To ubound(b)
If strcomp(b(i),b(j),1) < 0 Then
temp = b(i)
For i=0 To ubound(b)
Can you use the '[code]' blocks? I cannot read without the indentation.
It looks like a reasonable answer to me.
When in Florida, Don't Tampa with the code. I made this up.
In programming, you'll hear something called BigO complexity. So your current algorithm with the nested For loops that run up to the number of elements is considered O(n^2), where N is the number of elements, and all the constants are removed from the equation. https://en.wikipedia.org/wiki/Big_O_notation Basically, in the worst case scenario, you're running for every N elements, C*N number of instructions, Cn^2, simplified as just O(n^2)
There are 2 computer science concepts that'll improve your runtime.
The first concept is optimizing the algorithm to avoid revisiting elements you have already compared. Quicksort if a famous algorithm in this space. https://en.wikipedia.org/wiki/Quicksort Quick sort will get you down to O(n log n)
The 2nd concept is using advanced data structures that uses references to avoid recopying values. Currently you're using arrays, where you have to waste 3 instructions to copy the data to a temp value, then back to its new destination. Data structures such as linked lists and trees allow you to simply insert an element at it's intended destination without recopying. A famous algorithm in this space is the Binary search tree, https://en.wikipedia.org/wiki/Tree_sort This will also get your a O(n log n). There are variations of this that work better with large data sets such as the B-Tree, https://en.wikipedia.org/wiki/B-tree