Skip to content
🤔prompts chat🧠
🔍
question:11 "Odası dağınık olduğu için ders çalışamayan çocuğun annesi odayı düzenledikten sonra ders çalışma süresi artmıştır." Bu durum aşağıdakilerden hangisiyle açıklanır? a) İkinci tip ödül b) Olumlu koşullanma C) Olumlu pekiştirme 060 d) Olumsuz pekiştirme e) Birinci tip ödül

answer:d) Olumsuz pekiştirme ile açıklanır.

question:write me Hash table python program

answer:Sure! Here's a simple implementation of a hash table in Python: ``` class HashTable(): def __init__(self, size=10): self.size = size self.keys = [None] * self.size self.values = [None] * self.size def hash_function(self, key): return hash(key) % self.size def insert(self, key, value): i = self.hash_function(key) while self.keys[i] is not None: if self.keys[i] == key: self.values[i] = value return i = (i + 1) % self.size self.keys[i] = key self.values[i] = value def get(self, key): i = self.hash_function(key) while self.keys[i] is not None: if self.keys[i] == key: return self.values[i] i = (i + 1) % self.size return None def __str__(self): items = [] for k, v in zip(self.keys, self.values): if k is not None: items.append(f"{k}: {v}") return "{" + ", ".join(items) + "}" ``` Here's how you can use it: ``` ht = HashTable() ht.insert("a", 1) ht.insert("b", 2) ht.insert("c", 3) print(ht.get("a")) # Output: 1 print(ht.get("d")) # Output: None print(ht) # Output: {b: 2, c: 3, a: 1} ``` In this implementation, we use a hash function to map each key to an index in the `keys` and `values` arrays. If there are collisions (i.e., multiple keys map to the same index), we use linear probing to find the next available index. The `insert` method inserts a key-value pair into the table, the `get` method retrieves the value associated with a key, and the `__str__` method provides a string representation of the table.

question:write me Breadth-first traversal python program

answer:Sure! Here's a basic implementation of Breadth-first traversal in Python: ```python from collections import deque graph = { 'A': ['B', 'C'], 'B': ['D', 'E'], 'C': ['F'], 'D': [], 'E': ['F'], 'F': [] } def BFS(start_node, graph): visited = set() queue = deque([start_node]) while queue: node = queue.popleft() if node not in visited: print(node, end=' ') visited.add(node) neighbours = graph[node] for neighbour in neighbours: queue.append(neighbour) BFS('A', graph) ``` In this implementation, we first define a graph as a dictionary of nodes and their adjacent nodes. We then define a `BFS` function which takes a starting node and the graph as input. We initialize a set called `visited` to keep track of the nodes we have already visited. We also create a `deque` called `queue` to hold the nodes that we want to visit next, starting with the starting node. We then enter a loop that continues until there are no more nodes in the queue. We use the `popleft` method to remove the first node from the queue and assign it to `node`. We then check if `node` is in `visited`. If it is not, we print `node`, add it to the `visited` set, and get its neighbours from the graph. We then iterate over these neighbours and add them to the `queue`. The final output of the `BFS` function is a breadth-first traversal of the graph starting from the starting node.

question:write me Depth-first traversal python program

answer:Sure! Here's a basic implementation of Depth-first traversal in Python: ```python graph = { 'A': ['B', 'C'], 'B': ['D', 'E'], 'C': ['F'], 'D': [], 'E': ['F'], 'F': [] } def DFS(node, graph, visited=None): if visited is None: visited = set() visited.add(node) print(node, end=' ') for neighbour in graph[node]: if neighbour not in visited: DFS(neighbour, graph, visited) DFS('A', graph) ``` In this implementation, we first define a graph as a dictionary of nodes and their adjacent nodes. We then define a recursive `DFS` function which takes a node, the graph, and a set called `visited` (which keeps track of the nodes we have already visited) as input. If `visited` is not already initialized (if it is None), we initialize it to an empty set. We then add the current node to the `visited` set and print it. We then loop over the neighbours of the current node from the graph and call the `DFS` function recursively on any neighbours that have not already been visited. This ensures that we visit all the nodes in the graph. The final output of the `DFS` function is a depth-first traversal of the graph starting from the specified node.

Released under the Siri License.

has loaded