Skip to content

Conversation

@A-Kayode
Copy link
Collaborator

Switch Sort

Have the function SwitchSort(arr) take arr which will be an an array consisting of integers 1...size(arr) and determine what the fewest number of steps is in order to sort the array from least to greatest using the following technique: Each element E in the array can swap places with another element that is arr[E] spaces to the left or right of the chosen element. You can loop from one end of the array to the other. For example: if arr is the array [1, 3, 4, 2] then you can choose the second element which is the number 3, and if you count 3 places to the left you'll loop around the array and end up at the number 4. Then you swap these elements and arr is then [1, 4, 3, 2]. From here only one more step is required, you choose the last element which is the number 2, count 2 places to the left and you'll reach the number 4, then you swap these elements and you end up with a sorted array [1, 2, 3, 4]. Your program should return an integer that specifies the least amount of steps needed in order to sort the array using the following switch sort technique.

The array arr will at most contain five elements and will contain at least two elements.

Examples
Input: [3,1,2]
Output: 2

Input: [1,3,4,2]
Output: 2

Matrix Determinant

Have the function MatrixDeterminant(strArr) read strArr which will be an array of integers represented as strings. Within the array there will also be "<>" elements which represent break points. The array will make up a matrix where the (number of break points + 1) represents the number of rows. Here is an example of how strArr may look: ["1","2","<>","3","4"]. The contents of this array are row1=[1 2] and row2=[3 4]. Your program should take the given array of elements, create the proper matrix, and then calculate the determinant. For the example above, your program should return -2. If the matrix is not a square matrix, return -1. The maximum size of strArr will be a 6x6 matrix. The determinant will always be an integer.

Examples
Input: ["5","0","<>","0","5"]
Output: 25

Input: ["1","2","4","<>","2","1","1","<>","4","1","1"]
Output: -4

@A-Kayode A-Kayode closed this Feb 17, 2023
@A-Kayode A-Kayode reopened this Feb 17, 2023
@A-Kayode A-Kayode closed this Feb 17, 2023
@A-Kayode A-Kayode requested a review from CaduceusInc February 17, 2023 18:16
@A-Kayode A-Kayode reopened this Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants