स्वागत है!

Python में Data Structures और Algorithms

Miriam Antona

Software Engineer

एल्गोरिदम और डेटा स्ट्रक्चर का महत्व

  • डेटा स्ट्रक्चर और एल्गोरिदम हमें
    • रोज़मर्रा की समस्याएँ हल करने देते हैं
    • efficient code से
  • यह कोर्स किसी भी प्रोग्रामिंग लैंग्वेज में सिखाया जा सकता है
Python में Data Structures और Algorithms

एल्गोरिदम और डेटा स्ट्रक्चर

  • एल्गोरिदम: निर्देशों का सेट जो समस्या हल करे

    1. Design

      एल्गोरिदम डिजाइन का एक स्केमैटिक चित्र.

    2. Code

      एल्गोरिदम के कोड का एक स्केमैटिक चित्र.

  • डेटा स्ट्रक्चर: एल्गोरिदम के चलने पर डेटा को रखते और संभालते हैं
    • एडवांस्ड स्ट्रक्चर: linked lists, stacks, queues...
Python में Data Structures और Algorithms

Linked lists

एक लिंक्ड लिस्ट का विजुअल उदाहरण जिसमें ब्रेड बनाने के स्टेप्स हैं.

  • लिंक से जुड़ी डेटा की श्रृंखला
Python में Data Structures और Algorithms

Linked lists - संरचना

लिंक्ड लिस्ट में एक नोड का निरूपण.

Python में Data Structures और Algorithms

Linked lists - संरचना

लिंक्ड लिस्ट में एक नोड, जिसके पहले भाग में "DATA" लिखा है.

Python में Data Structures और Algorithms

Linked lists - संरचना

लिंक्ड लिस्ट में एक नोड, पहले भाग में "DATA" और दूसरे भाग में पॉइंटर के साथ "NEXT".

Python में Data Structures और Algorithms

Linked lists - संरचना

लिंक से जुड़े लिंक्ड लिस्ट के दो नोड्स का निरूपण.

Python में Data Structures और Algorithms

Linked lists - संरचना

लिंक से जुड़े कई नोड्स का निरूपण.

Python में Data Structures और Algorithms

Linked lists - संरचना

एक लिंक्ड लिस्ट का निरूपण जहाँ आखिरी नोड null की ओर इशारा करता है.

Python में Data Structures और Algorithms

Linked lists - संरचना

"HEAD" लिखे पहले नोड के साथ लिंक्ड लिस्ट का निरूपण.

Python में Data Structures और Algorithms

Linked lists - संरचना

आखिरी नोड में "TAIL" लिखी लिंक्ड लिस्ट का निरूपण.

  • डेटा को contiguous memory blocks में रखना जरूरी नहीं
  • डेटा किसी भी उपलब्ध memory address पर हो सकता है
Python में Data Structures और Algorithms

Singly linked lists

सिंगली लिंक्ड लिस्ट का निरूपण.

  • एक लिंक: singly linked list
Python में Data Structures और Algorithms

Doubly linked lists

डबल्ली लिंक्ड लिस्ट का निरूपण.

  • दोनों दिशाओं में दो लिंक: doubly linked list
Python में Data Structures और Algorithms

Linked lists - वास्तविक उपयोग

  • अन्य डेटा स्ट्रक्चर इम्प्लीमेंट करें:
    • stacks
    • queues
    • graphs
  • पीछे-आगे नेविगेट कर जानकारी एक्सेस करें
    • web browser
    • music playlist
Python में Data Structures और Algorithms

Linked lists - Node क्लास

class Node:
  def __init__(self, data):
    self.data = data
    self.next = None
Python में Data Structures और Algorithms

Linked lists - LinkedList क्लास

class LinkedList:
  def __init__(self):
    self.head = None
    self.tail = None
Python में Data Structures और Algorithms

Linked lists - methods

  • insert_at_beginning()
  • remove_at_beginning()
  • insert_at_end()
  • remove_at_end()
  • insert_at()
  • remove_at()
  • search()
  • ...
Python में Data Structures और Algorithms

Linked lists - insert_at_beginning

सिंगली लिंक्ड लिस्ट का निरूपण.

Python में Data Structures और Algorithms

Linked lists - insert_at_beginning

सिंगली लिंक्ड लिस्ट और एक नया नोड.

 def insert_at_beginning(self, data):
    new_node = Node(data)

if self.head:
Python में Data Structures और Algorithms

Linked lists - insert_at_beginning

कनेक्ट हुआ नया नोड वाली सिंगली लिंक्ड लिस्ट.

 def insert_at_beginning(self, data):
    new_node = Node(data)
    if self.head:
      new_node.next = self.head

Python में Data Structures और Algorithms

Linked lists - insert_at_beginning

नए नोड के साथ सिंगली लिंक्ड लिस्ट, और इस नोड पर "HEAD" लिखा है.

 def insert_at_beginning(self, data):
    new_node = Node(data)
    if self.head:
      new_node.next = self.head
      self.head = new_node

Python में Data Structures और Algorithms

Linked lists - insert_at_beginning

खाली लिंक्ड लिस्ट में नया नोड.

 def insert_at_beginning(self, data):
    new_node = Node(data)
    if self.head:
      new_node.next = self.head
      self.head = new_node
    else:

self.tail = new_node self.head = new_node
Python में Data Structures और Algorithms

Linked lists - insert_at_end

  def insert_at_end(self, data):
    new_node = Node(data)
    if self.head:  

self.tail.next = new_node
self.tail = new_node
else:
self.head = new_node self.tail = new_node
Python में Data Structures और Algorithms

Linked lists - search

def search(self, data):

current_node = self.head
while current_node:
if current_node.data == data:
return True

सिंगली लिंक्ड लिस्ट, जिसमें "current_node" पहले नोड की ओर इशारा कर रहा है.

Python में Data Structures और Algorithms

Linked lists - search

def search(self, data):
  current_node = self.head
  while current_node:
    if current_node.data == data:
      return True
    else:
      current_node = current_node.next

सिंगली लिंक्ड लिस्ट, जिसमें "current_node" दूसरे नोड की ओर इशारा कर रहा है.

Python में Data Structures और Algorithms

Linked lists - search

def search(self, data):
  current_node = self.head
  while current_node:
    if current_node.data == data:
      return True
    else:
      current_node = current_node.next

return False

सिंगली लिंक्ड लिस्ट, जिसमें "current_node" तीसरे नोड की ओर इशारा कर रहा है.

Python में Data Structures और Algorithms

Linked lists - उदाहरण

खाली लिंक्ड लिस्ट में नया नोड का निरूपण.

sushi_preparation = LinkedList()

sushi_preparation.insert_at_end("prepare")
Python में Data Structures और Algorithms

Linked lists - उदाहरण

लिंक्ड लिस्ट के अंत में नया नोड जोड़ा गया.

sushi_preparation = LinkedList()  
sushi_preparation.insert_at_end("prepare")
sushi_preparation.insert_at_end("roll") 

Python में Data Structures और Algorithms

Linked lists - उदाहरण

लिंक्ड लिस्ट की शुरुआत में नया नोड जोड़ा गया.

sushi_preparation = LinkedList()  
sushi_preparation.insert_at_end("prepare")
sushi_preparation.insert_at_end("roll") 
sushi_preparation.insert_at_beginning("assemble")
Python में Data Structures और Algorithms

Linked lists - उदाहरण

लिंक्ड लिस्ट का निरूपण.

sushi_preparation.search("roll")
True
sushi_preparation.search("mixing")
False
Python में Data Structures और Algorithms

अभ्यास करते हैं!

Python में Data Structures और Algorithms

Preparing Video For Download...