Queue - Data Structures & Algorithms Tutorials In Python #8

Поділитися
Вставка
  • Опубліковано 13 жов 2024

КОМЕНТАРІ • 125

  • @codebasics
    @codebasics  2 роки тому +6

    Do you want to learn python from me with a lot of interactive quizzes, and exercises? Here is my project-based python learning course: codebasics.io/courses/python-for-beginner-and-intermediate-learners

  • @myrusEW
    @myrusEW Рік тому +7

    I'm back. had this tab up for like 2 weeks. I was working OT and picking up shifts at my second job. I quit one of em tho so back to the study grind!! Gotta get myself in a better position in life, no one else is gonna do the work for me!

    • @TheDoc-Worker
      @TheDoc-Worker 5 місяців тому

      Hope you're doing well, it ain't fuckin easy.

    • @smaransure2234
      @smaransure2234 4 місяці тому

      @@TheDoc-Worker Ye lmao

  • @tevfikklas15
    @tevfikklas15 2 роки тому +13

    please dont waste your time with watching Udemy courses. This gentleman teach everything you image about python.

  • @shawzhang4498
    @shawzhang4498 Рік тому +3

    For those of you wondering why queue has O(1) inserting and deleting item, it is because queue is usually implemented using doubly linked list.

  • @harshitsharma6834
    @harshitsharma6834 3 роки тому +3

    Hey Dhaval I m watching u from long time just commenting here to let u know how awsm your content is your efforts money u put is worth a every single penny ! God bless you

    • @codebasics
      @codebasics  3 роки тому

      I am happy this was helpful to you.

  • @pythonenthusiast9292
    @pythonenthusiast9292 4 роки тому +7

    this is really good.. thankyou so much sir.
    Also, i have a request, please include more questions in the excercises in future videos as then the topic becomes very clear!..

  • @omkarbhabal1694
    @omkarbhabal1694 3 роки тому +20

    Thanks for proving the exercises, they are really helpful.

  • @quyenscc
    @quyenscc 3 роки тому +9

    Great tutorial. I love your channel! Thanks for creating these amazing tutorials.

  • @deepaksrinivasan8188
    @deepaksrinivasan8188 3 роки тому +1

    Agree with Omkar.... What a simple and magnificent exercise to use the data structure.
    Just brilliant again....:)

  • @joeg464
    @joeg464 3 роки тому +3

    Great lecture. I appreciate the upload.

  • @Joyboy_1044_
    @Joyboy_1044_ Рік тому +1

    Add this line to stop Empty queue loop:
    def ServeOrder(orders):
    time.sleep(1)
    while True:
    if food_order.isempty():
    print("All items Served")
    break

    order = food_order.dequeue()
    print("Serving order: ",order)
    time.sleep(2)

    • @shankar7588
      @shankar7588 Рік тому

      Also may be replace the while condition to check food_order_queue.size() !=0

    • @zack176
      @zack176 Рік тому

      Bro i tested out the same code as in the solution but it gives me random results like first order the second order then after serve

  • @nilupulperera
    @nilupulperera 4 роки тому +1

    Dear Sir,
    Your approach to teaching is really amazing. You open the underlying core knowledge, which will help to understand the subject very well. Meanwhile, your guide to search the internet to gather more information is really worthwhile. So we can add more and more flesh on to the skeleton you develop in us.
    I started to follow your Data Science Series two weeks ago. Now I am going through it for the second time while doing all the exercises.
    Being medical personnel, I really started loving Data Science because of your superb explanations and encouragement!!
    I believe your video series will do invaluable service to the Data Science field.
    Please continue your great job. Your service is needed more than ever for the Data Science world.
    You can squeeze out the palatability of the subject for the people who are craving for knowledge.
    Thank you so much.

    • @codebasics
      @codebasics  4 роки тому +1

      Nilupul, thanks for your kind words of appreciation and detailed feedback :) Comments like this gives me motivation to continue my work. Thanks again and I wish you all the best :)

    • @kratugautam304
      @kratugautam304 5 місяців тому

      ​@@codebasics Sir you are Genius, How can i become genius like you?

  • @hkdelhivlogs
    @hkdelhivlogs 4 роки тому +1

    Sir you are doing very well...you are my best teacher for data science and machine learning..😃😃😃 looking for more videos on this...

  • @sagardulal2028
    @sagardulal2028 3 роки тому

    oh god my laptop is too heated. next time upload video on how to cool it...
    jokin. really the best tutorial and easy way to understand . thank you

  • @sukurcf
    @sukurcf 3 роки тому +4

    whoa. deque is double ended queue.
    Used deque for so long but never noticed.

  • @AaronBrand
    @AaronBrand 4 роки тому +5

    Can you tell me where you "copy and paste" the class from? I'm trying to document all my practice and I want to make sure to make a proper reference! Thanks for the great videos. I'm learning a lot from you.
    BTW, I've read elsewhere that some people will pronounce deque like "deck," to differentiate from dequeue.

    • @codebasics
      @codebasics  4 роки тому +23

      Aaron, what I do is I prepare the code in advance and while doing UA-cam recording I start with blank and copy paste my own code. So all my content is my own genuine hard work. I spend lot of time in preparing this content. It is 100% genuinely my own content so please give a reference to codebasics youtube channel. If you want to put my name than it's Dhaval Patel

  • @TK-vt3ep
    @TK-vt3ep 4 роки тому +4

    Hello Sir,
    Could you make video on recursion and its application.
    Besides, i really appreciate sharing your tutorial videos they are really helpful. If you can also make it in Hindi for your hindi channel , it would be awesome ☺️

    • @codebasics
      @codebasics  4 роки тому +1

      Sure, i will cover a topic of recursion. I've codebasics hindi channel as well, it has few tutorials on python and machine learning. check that out.

  • @devashishnigam5971
    @devashishnigam5971 3 роки тому

    Amazing exercise questions

  • @prasantakarmakar8554
    @prasantakarmakar8554 4 роки тому

    As I know you are the only saviour on web, who replies very fast with some effective suggestions my bunch of questions are below
    Hi Sir, I have a question obviously not related to this video....Is that Data Gathering from web or anywhere else also comes under a Data Analyst responsibility?? If yes then , Can I collect it using Python through api links??
    If yes then from where can I get the api links of any social media?
    Is it doable.....or am I asking a correct questions??
    I'm totally confused.....please help.

    • @codebasics
      @codebasics  4 роки тому +1

      Your questions are very valid prasanta. Often data collection is done by data analyst but not all the times. Sometimes companies already have huge collection of data that is owned by different engineering and infrastructure teams. Business analysts also help with data collection process. People use data scrapping tools such as web crawlers to crawl internet for data collection. You can read about python scrapy library which is used for this purpose. However remember that no website would like you to crawl their portal in automated way hence many times the question arises if it is even legal to crawl web. So really there is no good or easy way to collect data from internet. There are portals like quandl or kaggle that provide datasets. I work for Bloomberg and we have api product where you pay a price and get financial data in form of feed through excel etc.

    • @prasantakarmakar8554
      @prasantakarmakar8554 4 роки тому

      @@codebasics Thank You for your reply Sir,...So I can say data scraping is in ...grey part....
      but if I want to collect some reaction of users from social media or any online shopping websites....Suppose
      I want to get the comments of facebook or instagram users for a particular post to get peoples thoughts about that post.
      so, can I also call it data scrapping ?
      Is it also in a grey part?
      If it is legal..then Is it possible to collect those comments data by any scrapping tools?
      if yes then can I use any algorithm on those word datas converting them into numerical data , like how we get insights from twitter comments though data mining?

  • @deepanshujain002
    @deepanshujain002 4 роки тому +1

    Can you please explain why did we use self.container in stack and self.buffer while implementing queue? What is their significance?

    • @codebasics
      @codebasics  4 роки тому +1

      there is no difference. those are just two different variable names :)

    • @deepanshujain002
      @deepanshujain002 4 роки тому

      @@codebasics got it..

  • @mrwilbroadtv4230
    @mrwilbroadtv4230 3 роки тому

    thanks for knowledge ,i realy appriciate

  • @aswath8265
    @aswath8265 3 роки тому

    Sir the problems are amazing

  • @studycode4142
    @studycode4142 2 роки тому

    good example for queue.

  • @manjinderrandhawa5094
    @manjinderrandhawa5094 2 роки тому

    do we need circular queue if we implement queue this way in python? What I mean is since deque/list is dynamic and we are appending at the left, so no issues of running out of capacity per se. Thoughts?

  • @dreamraw1438
    @dreamraw1438 4 роки тому

    sir, you are awesome because your teaching style is also good and your video tutorial for python is really good sirrr plz you also make the another main concept of python and python algorithms...

  • @headach09
    @headach09 2 роки тому

    Wow! Enjoy the sense of humor in your tutorial very much. Thanks

  • @KiranSharma-ey6xp
    @KiranSharma-ey6xp 2 роки тому

    Just one thing to notify here, Example Yahoo and Google finance can not use same dequeue method, as only the first who access will get correct result than it will remove (pop) from queue

  • @davidhuang3830
    @davidhuang3830 3 роки тому

    Thank you so much. I have taken a Data Structure course before but it was taught in Java. Your videos are so helpful in implementing it in python. I am confused at what does ".buffer" do?

    • @rahulbirhade9030
      @rahulbirhade9030 3 роки тому +1

      that was just an instance of deque() created in calling properties of the class. self.buffer = deque() see the 4th line of code 10:21

  • @ducnguyenminh4289
    @ducnguyenminh4289 3 роки тому

    Thank you so much, It's so useful for me

  • @ArunKumar-lb5jr
    @ArunKumar-lb5jr 2 роки тому

    great work sir

  • @tvtrauma7024
    @tvtrauma7024 2 роки тому

    Where can I learn more about software infastructure mentioned at the beginning of the video

  • @saulgoodman980
    @saulgoodman980 4 роки тому +3

    5:12 In C++ pop() returns void i.e. it only removes the front without returning anything...

    • @omnipotentcoder9401
      @omnipotentcoder9401 3 роки тому

      you are using a different compiler.he's using jupter notebook that's why he is getting it as output

  • @prakhardixit2597
    @prakhardixit2597 3 роки тому +1

    Can you tell me how come pq.buffer print the values

  • @pavithran7776
    @pavithran7776 4 роки тому

    Amazing sir...Thank you so much. I have doubt that in Order code(exercise) Thread is not stopped after all orders are over..What I have to do now??

    • @codebasics
      @codebasics  4 роки тому +2

      Did you do thread.join? In my python tutorials series I have multithreading tutorial please watch that so that you get an idea. Also I have a solution link in exercise page so please refer to that

    • @pavithran7776
      @pavithran7776 4 роки тому

      @@codebasics ok sir...Thank you

    • @nishchaysingh7601
      @nishchaysingh7601 3 роки тому

      do this it will stop:
      def serve_orders():
      time.sleep(1)
      while food_order_queue.size() != 0:
      order = food_order_queue.dequeue()
      print("Now serving: ",order)
      time.sleep(2)

  • @sumitdhiman5381
    @sumitdhiman5381 4 роки тому

    Hello sir, Can you please tell me..if this is the right way to do 2nd ques or not?if __name__ == "__main__":
    q = Queue()
    numbers = int(input("Enter numbers:"))
    for i in range(1,numbers+1):
    q.enqueue((bin(i).replace("0b","")))
    print(q.dequeue())

  • @172yogendra
    @172yogendra 4 роки тому

    Dear sir could you please make some videos on algorithms ......which are important for product-based companies placement??

  • @moumitabose2864
    @moumitabose2864 3 роки тому

    thank you sir...

  • @amarkumarsingh014
    @amarkumarsingh014 2 роки тому

    Class implemented will again have the issues same as the list explained earlier. We can add another check in the dqueue method to check if the queue is empty or not.

  • @muhammedcanozdemir6447
    @muhammedcanozdemir6447 Місяць тому

    is there any need for appendleft, we can do it with append and we can remove the first index of the list

  • @a2zfunbegins273
    @a2zfunbegins273 2 роки тому

    sir but i performed queue using list in python and its working well.

  • @sahebsaha8788
    @sahebsaha8788 4 роки тому

    sir is this all 11 videos are covered the whole data structure in python or not and sir, plz make a tutorial on algorithms also

  • @meralmaradia4774
    @meralmaradia4774 2 роки тому

    Hello Sir, can you please create a video developing of project using only DSA ?

  • @dinesh.p8642
    @dinesh.p8642 3 роки тому

    Thank you dhaval sir

  • @daivikbhatia5041
    @daivikbhatia5041 4 роки тому +1

    hello sir,
    I'm really confused. I'm in my final year of engineering and I want to be a Data Scientist but I also want to keep Software Developer as a backup option. The problem is I'm only good at python. So do I need to learn a new language like Java or C++ or can I give SDE interviews with just python?

    • @codebasics
      @codebasics  4 роки тому +2

      just python is good.

    • @daivikbhatia5041
      @daivikbhatia5041 4 роки тому

      @@codebasics Thank-you sir!

    • @randyorton4435
      @randyorton4435 3 роки тому +1

      @@daivikbhatia5041with the only help of python have your get placed now??

    • @daivikbhatia5041
      @daivikbhatia5041 3 роки тому +1

      @@randyorton4435 yes i have been placed in 3 companies out of which 2 as a junior data scientist (both via ppo from internship)..All are based on Python only.. i still don't know any other languages

    • @user-tz6zl6gm6j
      @user-tz6zl6gm6j 2 роки тому

      @@daivikbhatia5041 should we learn DSA for data analyst roles.

  • @motivationalyug1546
    @motivationalyug1546 2 роки тому

    Thank you...

  • @ankitchoudhury9678
    @ankitchoudhury9678 3 роки тому

    love the details apart from Queue.. knowledge is beautiful

  • @apoorvshrivastava3544
    @apoorvshrivastava3544 4 роки тому

    Thanks sir , Sir how many videos are left in this playlist

    • @codebasics
      @codebasics  4 роки тому +3

      I am going to upload few videos on tree, graph and also few more videos comparing different data structures. I dont have exact count but atleast 5 more videos.

  • @tapabratacse
    @tapabratacse 2 роки тому +1

    your code for example 1 ....food_ordering_system.py should be having infinite loop while serving item. There are no checks on whether order queue is empty

    • @optimalrider
      @optimalrider 2 роки тому

      Yes, precisely.
      Either Make And If Statement Stating
      If food_order_queue.is_empty()
      break
      Something Like This In server_order
      So When There Is No More Order It Should Stop Or Wait For More Orders.

    • @optimalrider
      @optimalrider 2 роки тому

      If You Know The Correct Solution Please Let Us Know.

  • @sunmolasolomon3403
    @sunmolasolomon3403 3 роки тому

    Good day, Please how will you break the code? It keeps printing even after queue is empty?

  • @KiranSharma-ey6xp
    @KiranSharma-ey6xp 2 роки тому

    Update function server_orders() by below function, to get rid of unwanted infinite process.
    def serve_orders():
    time.sleep(1)
    while True:
    order = food_order_queue.dequeue()
    if order:
    print("Now serving: ",order)
    time.sleep(2)
    else:
    return False

  • @mihaimyh
    @mihaimyh 3 роки тому

    Insert and pop are methods specific for a Stack not a Queue, a queue usually has methods like enqueue or dequeue so I am not sure why you are referring to a list as a queue.

    • @ronsinha21
      @ronsinha21 2 роки тому

      Hey Buddy...If you understand correctly he's showing "how to create a Queue using a list", you can create a queue using a List or already available deque from collections or using a LinkedList(which again U can create). The methods "Insert" and "Pop" are built-in methods available for Python lists, similarly there are methods available for deque.
      The objective of the videos is to teach Data Structures and then implement with Python.

  • @hustler98989
    @hustler98989 3 роки тому

    sir, in list if we append new element it reallocate the memory and copy so list is not recommended but what do a queue do if a new element is appended???...how does it manage the memory?

    • @codebasics
      @codebasics  3 роки тому +1

      There are multiple ways of implementing a queue but if you use linked list it will be better because you don't have to worry about shifting elements

  • @chiragkumargohil9917
    @chiragkumargohil9917 2 роки тому

    Does every API use queue data structure?

  • @sayantanisaha
    @sayantanisaha 3 роки тому

    why does my jupyter notebook throws this error?--------- descriptor 'appendleft' for 'collections.deque' objects doesn't apply to a 'int' object

  • @zohaibramzan6381
    @zohaibramzan6381 3 роки тому

    How will u define loose and strong coupling?

  • @mayurhegde6903
    @mayurhegde6903 3 роки тому

    hey there's an error in the order placing code, replace True in line 37 with not food_order_queue.is_empty():

  • @cawaynebryan4324
    @cawaynebryan4324 2 роки тому

    My computer needs a PCR test kit

  • @shahbazkhalilli8593
    @shahbazkhalilli8593 Рік тому

    in 4:43 explanation picture is incorrect

  • @maheshpatil9055
    @maheshpatil9055 2 роки тому

    Sir my laptop has 100 and 5 degree fever what should I do 😅

  • @vandanapal7321
    @vandanapal7321 4 роки тому

    hi..actually I got an project to make using machine learning but I don't know how to start and what to do and where to get data from as I haven't looked into this kind of thing ...so kindly guide me with the project : crawl popular websites and create a database of Indian movie celebrities with their images and personality traits

    • @codebasics
      @codebasics  4 роки тому

      Vandana, can you send me your entire project description and some more details on learnpythonlanguage@gmail.com? We can discuss more on email.

    • @vandanapal7321
      @vandanapal7321 4 роки тому

      @@codebasics I had emailed you . please do check

  • @devils_arena
    @devils_arena 3 роки тому

    the code u provided in the solution it is coming a non ending loop of none and serve orders how to fix that

  • @prakharsingh2672
    @prakharsingh2672 4 роки тому

    Hiii Sir. Can you please upload these series videos fast.

    • @codebasics
      @codebasics  4 роки тому +1

      I have not prepared all videos. I am adding them as and when I get time to prepare them but yes I am trying my best. Next one is going to be on a tree.

  • @saiyedali561
    @saiyedali561 4 роки тому +1

    from collections import deque
    import time
    import threading
    class Queue :
    def __init__(self):
    self.buffer = deque()
    def pop():
    return self.buffer.pop()
    def enqueue(self , val):
    self.buffer.appendleft(val)
    def dequeue(self):
    return self.buffer.pop()
    def is_empty(self):
    return len(self.buffer) == 0
    def size(self):
    return len(self.buffer)
    def place_order(li ,q):
    for each in li :
    print("Placing order for:",each)
    q.enqueue(each)
    time.sleep(.5)
    def serve_order(q) :
    time.sleep(1)
    # this condition is bz , time_enqueue() < time_deque()
    while not q.is_empty() :
    print("Enjoy the served order : " + q.dequeue())
    time.sleep(2)
    if __name__ == "__main__" :
    li = ['pizza','samosa','pasta','biryani','burger','litti-chokha','dal-wada','mendu-wada']
    q = Queue()
    t = time.time()
    t1 = threading.Thread(target = place_order , args = (li , q,))
    t2 = threading.Thread(target = serve_order , args=(q,))
    t1.start()
    t2.start()
    t1.join()
    t2.join()
    print("Total time taken(for comparision) : " + str(time.time() - t))

    • @saiyedali561
      @saiyedali561 4 роки тому +1

      More better

    • @codebasics
      @codebasics  4 роки тому

      Great.thabks for working in exercise 👍😊

  • @shawzhang4498
    @shawzhang4498 Рік тому

    why queue has different time complexity than array??

    • @muhammedcanozdemir6447
      @muhammedcanozdemir6447 Місяць тому

      isn't it obvious, because queue behaves like a linked list, if you want to access a specific element in the queue, you can access it when its turn comes. Think like you are in a queue, how they access you if your turn does not comes. But thin you are in a room with a number written on your chest. When they call your number, they immediately reach you

    • @shawzhang4498
      @shawzhang4498 Місяць тому

      @@muhammedcanozdemir6447 how is array different in terms of access?

  • @danyahsan3958
    @danyahsan3958 6 місяців тому

    TIME COMPLEXITY?

  • @jyotiphulwariya6723
    @jyotiphulwariya6723 3 роки тому

    from collections import deque
    class Queue:
    def __init__(self):
    self.buffer=deque()

    def enqueue(self,val):
    self.buffer.appendleft(val)

    def dequeue(self):
    return self.buffer.pop()

    def front(self):
    return self.buffer[-1]

    def is_empty(self):
    return len(self.buffer)==0

    def size(self):
    return len(self.buffer)

    def rem(i):
    s=Queue()
    for n in range(1,i+1):
    z=""
    while n>0:
    a=n%2
    z+=str(a)
    n=n//2
    s.enqueue(z[::-1])
    c=len(s.buffer)
    while c>0:
    print(s.buffer[c-1])
    c-=1
    print(rem(10))

  • @rushlearning5158
    @rushlearning5158 3 роки тому

    Hello Sir,
    can you give a data structure in a different programming language slide
    Thx.

  • @faisalnazik
    @faisalnazik 4 роки тому

    can u teach us how to predict the next lottery or prize bonds numbers sequences with IA , using import requests
    from bs4 import BeautifulSoup as bs
    import threading
    import queue
    python

  • @optimalrider
    @optimalrider 2 роки тому

    Can Anyone Help Me With Question 2 in Exercise, Not Able To Understand The Logic Even After Checking Out The Solution.
    It Would Be Great Help!

    • @ronsinha21
      @ronsinha21 2 роки тому

      @Optimal Rider I implemented it in my own way using "front" as a variable which will store the dequeue and inside the loop, append "0" with front first then "1" print front and then print newline inside the loop. Even simpler and easy to understand logic than the Solution. Also I modified dequeue to do a pop(0)rather than pop. always better to implement any solution in your own way(that's the best way of determining your understanding). Do you still need help to understand the solution code?

    • @zack176
      @zack176 Рік тому

      Is your forst problem worked perfectly

  • @mrjhon6432
    @mrjhon6432 2 роки тому

    sir mere computer mai COVID 19 aagya hai sir kya kru vaccination kam nhi ayi kya kru 😰

  • @sagar_bro
    @sagar_bro 3 роки тому

    why do we use this in code:
    if __name__ == '__main__':

    • @manjinderrandhawa5094
      @manjinderrandhawa5094 2 роки тому +1

      basically for the scenario if the script is not being exported and is executed directly.

  • @priyanshumaity6780
    @priyanshumaity6780 Рік тому +1

    Ohhh no! I got COVID-19 virus in my computer!!!!!!😱😱😱

  • @nikhilreddy9411
    @nikhilreddy9411 Рік тому

    Multi threading required for exercise. So use below link to understand.
    ua-cam.com/video/GqHLztqy0PU/v-deo.html

  • @Mohib3
    @Mohib3 3 роки тому

    why do i feel like this is to easy to be true

  • @h_coder
    @h_coder Рік тому +2

    Thank you so much ... may Allah guide you to accept Islam 😊

  • @fkgaasdkjnv4824
    @fkgaasdkjnv4824 8 місяців тому

    Oops I accidentally clicked solution and my computer got covid 19 virus 😢

  • @seanli75
    @seanli75 2 роки тому

    🤣🤣🤣Covid-19 virus

  • @poojavispute2228
    @poojavispute2228 4 роки тому +1

    Thank you sir......for making such kind of videos which is veey helpful for us.