Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Finding the length of longest sorted sequence Diagonally

Aditya Bahukhandi, Amritesh Bhaskar, Pranav Jhawar, Tushaar Agarwal

Abstract 1. Three loops one outer and two contained within the
outer loop.
In computer science, arranging in an ordered se-
quence is called ”sorting”. Sorting is a common oper- 2.The outer loop runs from 1 till n-1 (order of matrix)
ation in many applications, and efficient algorithm to for keeping track of the n-1 diagonals above and the
perform it have been developed. This paper introduces n-1 diagonals below the principal diagonals.
various algorithms for finding the maximum length of
3. The first inner loop is run till the length of the rth
sorted sequence in a given 2-D array of size 50x50 di-
diagonal above the principal diagonal that checks for
agonally and their respective time complexities with
sorted elements and updates the max variable, that
their graphical representation..
stores the length of the largest sorted sequence found
Keywords: Random numbers, Matrix Sorting, Diago-
till that point, if necessary.
nal element, Time Complexity
4. The second inner loop is run till the length of the rth
diagonal below the principal diagonal that checks for
1. INTRODUCTION sorted elements and updates the max variable, that
stores the length of the largest sorted sequence found
Sorting is any process of arranging items system- till that point, if necessary.
atically, and has two common, yet distinct meanings:
ordering : arranging items in a sequence ordered by 5.If the length of the largest sorted sequence is equal to
some criterion. the length of the diagonals being checked then max +1
categorizing : grouping items with similar properties. is returned otherwise the algorithm continues
And, a random number generator (RNG) is a math-
ematical construct, either computational or as a hard-
ware device, that is designed to generate a random set Algorithm 1 main()
of numbers that should not display any distinguishable Input : 50 X 50 Matrix
patterns in their appearance or generation, hence the Output : Largest sorted sequence
word random. 1: max ← 0
For creating a new algorithm from scratch we look 2: lasti ← 0
into the many crucial aspects of algorithm designing 3: last j ← 0
and analysis. And the algorithm developed is tested for 4: k ← ’apd’
different sample cases for determining the time com- 5: maxsort ← ’desc’
plexity and space complexity and accuracy. 6: for i ← 1 to 50 do
This report further contains : 7: c, j, sort, temp ← i, 0, ’asc’, 0
1. Algorithm Design 8: while c <= n − 1 do
2. Algorithm Analysis 9: if Sorted sequence uptil this point is ascend-
3. Experimental Analysis ing then
4. Result 10: if (A[ j][c] <= A[ j + 1][c + 1]) then
5. Conclusion 11: temp ← temp + 1
12: if (temp > max) then
13: max ← temp
2. A LGORITHM D ESIGN
14: lasti ← j+1
15: last j ← c+1
The algorithm for finding the length of the largest
sorted component diagonally consists of the following:
16: k ← ’apd’ 70: c←c+1
17: end if 71: j← j+1
18: else 72: end while
19: temp ← 1 73: if (max == orderO f (A) − 1) then
20: sort ← ’desc’ 74: return Max
21: end if 75: end if
22: else 76: end for
23: if (A[ j][c] >= A[ j + 1][c + 1]) then 77: return Max
24: temp ← temp + 1
25: if (temp > max) then
26: max ← temp 3. E XPERIMENTAL S TUDY
27: lasti ← j+1
28: last j ← i+1
29: k ← ’apd’ A. Worst case
30: end if t1 ∝ 7n2 + 3n + 8
31: else B. Best case
32: temp ← 1 t1 ∝ 20n + 1
33: sort ← ’asc’
34: end if
35: end if
36: c←c+1
37: j← j+1
38: end while
39: temp ← 0
40: c←i
41: j←0
42: while c <= n − 1 do
43: if Sorted sequence uptil this point is ascend-
ing then
44: if (A[c][ j] <= A[c + 1][ j + 1]) then
45: temp ← temp + 1
46: if (temp > max) then
47: max ← temp
48: lasti ← c+1
49: last j ← j+1
50: k ← ’apd’
51: end if
52: else
53: temp ← 1
54: sort ← ’desc’
55: end if E. Time Complexity
56: else This Algorithm was tested for the different data sets
57: if (A[c][ j] >= A[c + 1][ j + 1]) then A of varying length and the following results were
58: temp ← temp + 1 obtained:
59: if (temp > max) then 1) Best Case: O(n)
60: max ← temp 2) Worst Case: O(n2 )
61: lasti ← c+1
62: last j ← j+1
63: k ← ’apd’ 4. C ONCLUSION
64: end if
65: else Here we have used the two lemmas given in
66: temp ← 1 introduction to prove the theorem that a positive
67: sort ← ’asc’ number x is a fibonacci number if and only if 5x2 ±4 is
68: end if a perfect square, and using this theorem we have
69: end if
checked whether a given number is fibonacci or not
and have updated the min amd max fibonacci number
simultaneously.
This algorithm has a time complexity of O(n) and
works fine for all numbers.

5. R EFERENCES

[1]: https://en.wikipedia.org/wiki/Fibonacci number


[2]: http://www.cs.swan.ac.uk

You might also like