arrays vs lists, binary search

preview_player
Показать описание
To access the translated content:
The video course content can be accessed in the form of regional language text transcripts, books which can be accessed under downloads of each course, subtitles in the video and Video Text Track below the video.
2. Regional language subtitles available for this course
To watch the subtitles in regional languages:
1. Click on the lecture under Course Details.
2. Play the video.
3. Now click on the Settings icon and a list of features will display
4. From that select the option Subtitles/CC.
5. Now select the Language from the available languages to read the subtitle in the regional language.
Рекомендации по теме
Комментарии
Автор

arrays - uniform time to access any random element, however inserting/removing takes a lotta time because the constraint that array elements should be contiguous, hence shifting op needs to be performed. linked lists eliminate the need of shifting, but increase time complexity of accessing elements. swapping elements in array is lesser time than lists

muralidhar
Автор

The binary search program is not working
The mid condition must be checked first then empty condition then it works properly

arjunpukale
Автор

At 17:50, what if we don't write return in the last two conditions and only call the function bsearch(seq, v, l, mid) ??

abhinavtyagi
Автор

python lists are best of both the arrays and linked lists, in it they take constant time for accessing any element like arrays, but also they allow for efficient addition/removal of elements like linked lists.

muralidhar
Автор

At 17:40

Shouldn't we use elif instead of only if, to recursively search in RHS part of the sequence?

weirdo-beardo
Автор

Jp here again [comment number 25]

Thank you, Sir, :)

Jaimin_Bariya
Автор

what is r & l in function parameters? like when we call that function in promt window of python what value we pass through in terms of r & l?

adeelshafi
Автор

With the Binary search program it won't check the last place.
For eg if it is a list with 7 elements, last index being 6, due to (l-r)==0 condition, 6th index won't be checked even if it has the desire value (v).

this is will help
def BinarySearchWithRange(seq, v, l, r):
mid = (l+r)//2
if (r-l) ==0 and seq[mid] == v:
return(True)
if (r-l) ==0 and seq[mid] != v:
return(False)
if (seq[mid] == v):
return(True)
elif seq[mid] > v:
return(BinarySearchWithRange(seq, v, l, mid))
else:
return(BinarySearchWithRange(seq, v, mid+1, r))

akshaypatil
Автор

In the "Lists vs Arrays" discussion, the lists being studied are not Python's lists, but what is commonly referred to as linked lists.


The built-in data structure List in Python may be treated as conventional arrays (mentioned at the end). According to the Python docs, accessing an element from a list is O(1) and inserting is O(n).


The link below provides a table of the time complexities of all list operations for those interested.

kaunajbanerjee
Автор

Q: Previous program (findpos, where we found the position), we used "Break", cant we use "Return" instead of "Break" there... Pls do rply !

sumedh
Автор

how can t(1) takes only one step? pls reply

akhilantony
Автор

According to python design documentation Python lists are variable length arrays.

chakradharkasturi
Автор

def Binary(sqn, v):
sqn.sort()
start=0
end=len(sqn)-1
while start<end:
mid=(start+end)//2
if end-start==1 :
if sqn[mid]==v or sqn[mid+1]==v:
return True
else:
return False
if v==sqn[mid]:
return True
elif v>sqn[mid]:
start=mid+1
else:
end=mid
returnFalse

bejorrani
Автор

Fucking bastard, what a shame on IIT, worst teaching ever .

welcome to shbcf.ru