hemanth
(Hemanth Janesh)
January 29, 2021, 12:24pm
#1
In this assignment, you’ll apply and practice the following concepts covered during the first lesson

Understand and solve a problem systematically
Implement linear search and analyze it
Optimize the solution using binary search
Ask questions and help others on the forum
Assignment Notebook

Assignment 1 - Binary Search Practice

Use the starter notebook(s) to get started with the assignment. Read the problem statement, follow the instructions, add your solutions, and make a submission.

Share your work

Share your work on the Share Your Work Category on the respective monthly threads.

```
test = {
'input': {
'nums': [19, 25, 29, 3, 5, 6, 7, 9, 11, 14]
},
'output': 4
}
```

I think, above `output`

should be 3.

and

```
nums0 = test['input']['nums']
output0 = test['input']['nums']
result0 = count_rotations(nums0)
result0, result0 == output0
```

And here, in 2nd line it should be `output0 = test['output']`

.

11 Likes

I think in problem statement, it is given to assume all elements in the list are unique. (If that you are asking)

1 Like

2019ucs0097
(SHREYAS CHATTERJEE)
January 30, 2021, 8:56pm
#7
We can assume that if the list is empty the it automatically means that the output should be 0 right?

lutherleo
(Love Kush Pranu)
January 30, 2021, 10:25pm
#8
There is a duplicates case in the bonus question.

2 Likes

lutherleo
(Love Kush Pranu)
January 30, 2021, 10:28pm
#10
if position > 0 and ??? # How to perform the check?

what is the other condition even? I am kinda confused here.

2 Likes

You have got to add a way to create a conditional statement that verifies what is commented above that line:

# Success criteria: check whether the number at the current position is smaller than the one before it

So:
`if position > 0 and (number at current position < number at previous position)`

3 Likes

lutherleo
(Love Kush Pranu)
January 30, 2021, 11:09pm
#13

What does this error mean?

satyamgipu
(Satyam Gupta)
January 31, 2021, 3:08am
#15
Your function Should be
count_rotations_linear(nums)
because you are passing the array as nums but not handling it properly in the array.

2019ucs0097
(SHREYAS CHATTERJEE)
January 31, 2021, 6:27am
#16
Can somebody please reply to this. Thanks in advance.

We have 2 test cases,

A list that wasn’t rotated at all (0 times rotated).
A list that was rotated n times, where n is the size of the list (n times rotated).
In both cases, the resulted/rotated list will be a sorted one. In that case, the expected output should be 0 or N. Isn’t it ??

3 Likes

f20190478
(Aditya Anil Singh)
January 31, 2021, 9:21am
#19
Can someone explain why this error is occurring? It did not occur for the single test case evaluative.

f20190478
(Aditya Anil Singh)
January 31, 2021, 10:07am
#20
Nevermind! It turns out the 2nd input ‘test’ should be ‘tests’ in evaluate_test_cases

3 Likes

Since, there should be minimum rotation to obtain the sorted list (Given in question). So, the final output will be 0.

1 Like

I am assuming `0`

. Let’s see what happens.

I used 0 for empty lists and it works.
But I guess using -1 makes sense because there is no possible rotation.

I think we should add the parameters

the idea is somehow works in this way, if we had checked all the position after increment and found the current value is still greater than the previous value, we should can deduce that it is a sorted list, we only give another answer indicator if it is indeed empty list. Thanks.

1 Like

I think if the list is empty, then no. of rotations = 0 it makes sense

3 Likes