Makindo Medical Notes"One small step for man, one large step for Makindo" |
|
---|---|
Download all this content in the Apps now Android App and Apple iPhone/Pad App | |
MEDICAL DISCLAIMER: The contents are under continuing development and improvements and despite all efforts may contain errors of omission or fact. This is not to be used for the assessment, diagnosis, or management of patients. It should not be regarded as medical advice by healthcare workers or laypeople. It is for educational purposes only. Please adhere to your local protocols. Use the BNF for drug information. If you are unwell please seek urgent healthcare advice. If you do not accept this then please do not use the website. Makindo Ltd. |
Data structures are fundamental concepts in computer science that provide ways to store, organize, and manage data efficiently. They are essential for designing efficient algorithms and for solving complex computational problems. Understanding data structures is crucial for developing robust and high-performance software applications.
# Array arr = [1, 2, 3, 4, 5] # Linked List class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): self.head = None def append(self, data): new_node = Node(data) if not self.head: self.head = new_node return last = self.head while last.next: last = last.next last.next = new_node ll = LinkedList() ll.append(1) ll.append(2) ll.append(3)
# Binary Tree class TreeNode: def __init__(self, data): self.data = data self.left = None self.right = None root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(3) root.left.left = TreeNode(4) root.left.right = TreeNode(5) # Graph using adjacency list class Graph: def __init__(self): self.graph = {} def add_edge(self, u, v): if u not in self.graph: self.graph[u] = [] self.graph[u].append(v) g = Graph() g.add_edge(0, 1) g.add_edge(0, 2) g.add_edge(1, 2) g.add_edge(2, 0) g.add_edge(2, 3) g.add_edge(3, 3)
arr = [1, 2, 3, 4, 5] print(arr[2]) # Output: 3
class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): self.head = None def append(self, data): new_node = Node(data) if not self.head: self.head = new_node return last = self.head while last.next: last = last.next last.next = new_node ll = LinkedList() ll.append(1) ll.append(2) ll.append(3)
stack = [] stack.append(1) stack.append(2) stack.append(3) print(stack.pop()) # Output: 3
from collections import deque queue = deque() queue.append(1) queue.append(2) queue.append(3) print(queue.popleft()) # Output: 1
class TreeNode: def __init__(self, data): self.data = data self.left = None self.right = None root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(3) root.left.left = TreeNode(4) root.left.right = TreeNode(5)
class Graph: def __init__(self): self.graph = {} def add_edge(self, u, v): if u not in self.graph: self.graph[u] = [] self.graph[u].append(v) g = Graph() g.add_edge(0, 1) g.add_edge(0, 2) g.add_edge(1, 2) g.add_edge(2, 0) g.add_edge(2, 3) g.add_edge(3, 3)
hash_table = {} hash_table["key1"] = "value1" hash_table["key2"] = "value2" print(hash_table["key1"]) # Output: value1
Data structures are vital components in computer science, enabling efficient data storage, organization, and manipulation. Linear data structures include arrays, linked lists, stacks, and queues, while non-linear data structures include trees and graphs. Each data structure has its own set of operations and applications, making them suitable for various computational tasks. Understanding and implementing these data structures is essential for developing efficient algorithms and solving complex problems in computer science.