arrays vs lists, binary search

  Рет қаралды 142,390

NOC16 CS11

NOC16 CS11

Күн бұрын

Пікірлер: 25
@muralidhar40
@muralidhar40 2 жыл бұрын
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
@kaunajbanerjee8526
@kaunajbanerjee8526 5 жыл бұрын
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. wiki.python.org/moin/TimeComplexity
@lucygaming9726
@lucygaming9726 5 жыл бұрын
Python List's are Dynamic arrays not conventional arrays. en.wikipedia.org/wiki/Dynamic_array
@neiljohn2637
@neiljohn2637 3 жыл бұрын
thanks for the comment, I was confused with this
@aurkom
@aurkom 3 жыл бұрын
@@lucygaming9726 Like vectors in cpp?
@lucygaming9726
@lucygaming9726 3 жыл бұрын
@@aurkom exactly.
@muralidhar40
@muralidhar40 2 жыл бұрын
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.
@bBbKce
@bBbKce 6 жыл бұрын
Enlightened, Great job prof
@arjunpukale630
@arjunpukale630 6 жыл бұрын
The binary search program is not working The mid condition must be checked first then empty condition then it works properly
@abhinavtyagi1657
@abhinavtyagi1657 3 жыл бұрын
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) ??
@Jaimin_Bariya
@Jaimin_Bariya 2 ай бұрын
Jp here again [comment number 25] Thank you, Sir, :)
@akshaypatil2943
@akshaypatil2943 4 жыл бұрын
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))
@rohankorale6381
@rohankorale6381 3 жыл бұрын
correct! But I think code can be improved a bit. rather putting condition of: " seq[mid]==v " at 3 places, just put : "if r - l >= 0: " This will automatically handle the zero length case and in that case mid = r = l, so we will get answer in step : " if (v == seq[mid] )" 😀
@weirdo-beardo
@weirdo-beardo 6 жыл бұрын
At 17:40 Shouldn't we use elif instead of only if, to recursively search in RHS part of the sequence?
@sumedh1505
@sumedh1505 6 жыл бұрын
Yes, we can use... here we can use elif in LHS part of the sequence as it is defined first. If we define RHS part first we can use elif for RHS
@adeelshafi
@adeelshafi 5 жыл бұрын
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?
@ziya6014
@ziya6014 5 жыл бұрын
do we need to define l and r?
@chakradharkasturi4082
@chakradharkasturi4082 6 жыл бұрын
According to python design documentation Python lists are variable length arrays. docs.python.org/2/faq/design.html
@sumedh1505
@sumedh1505 6 жыл бұрын
Q: Previous program (findpos, where we found the position) , we used "Break", cant we use "Return" instead of "Break" there... Pls do rply !
@vijayakumarlakshmanan3948
@vijayakumarlakshmanan3948 5 жыл бұрын
We can , he just did to tell what a break does in a loop
@akhilantony3581
@akhilantony3581 5 жыл бұрын
how can t(1) takes only one step? pls reply
@kaunajbanerjee8526
@kaunajbanerjee8526 5 жыл бұрын
In general, let's say that searching for an element in a list of N elements takes T(N) steps. T(1) is the time taken (no. of steps) to search for an element in a list of 1 element. So, we only need to check once. For instance, if it's the list [5] and we're looking for the number 6, we check if 6 == 5 which is not true, and we're done. Hence, we need only one step.
@bejorrani
@bejorrani 2 жыл бұрын
def Binary(sqn, v): sqn.sort() start=0 end=len(sqn)-1 while startsqn[mid]: start=mid+1 else: end=mid returnFalse
@shrxshth_
@shrxshth_ 4 жыл бұрын
BINOD
2. Data Structures and Dynamic Arrays
50:18
MIT OpenCourseWare
Рет қаралды 546 М.
Top 7 Algorithms for Coding Interviews Explained SIMPLY
21:22
Codebagel
Рет қаралды 456 М.
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 22 МЛН
How many people are in the changing room? #devil #lilith #funny #shorts
00:39
Python lists vs. arrays: How similar are they?
11:45
Python and Pandas with Reuven Lerner
Рет қаралды 18 М.
manipulating lists
18:46
NOC16 CS11
Рет қаралды 126 М.
lists
28:54
NOC16 CS11
Рет қаралды 206 М.
you will never ask about pointers again after watching this video
8:03
Running "Hello World!" in 10 FORBIDDEN Programming Languages
18:07
A* (A Star) Search Algorithm - Computerphile
14:04
Computerphile
Рет қаралды 1,2 МЛН
tuples and dictionaries
15:56
NOC16 CS11
Рет қаралды 91 М.
euclid's algorithm for gcd
23:55
NOC16 CS11
Рет қаралды 290 М.
10 Math Concepts for Programmers
9:32
Fireship
Рет қаралды 1,9 МЛН