[{"content":"Trees Trees are a fundamental concept in computer science, used in various applications from databases and file systems to AI and machine learning.\nWhat is a Tree? In data structures, a tree is a way of representing hierarchical information. It consists of nodes connected by edges, similar to how branches connect to a tree trunk in nature. However, in data structures, our tree is usually inverted, with the root at the top and branches extending downwards.\nA tree has several components:\nRoot: The top node from which all other nodes branch out. There\u0026rsquo;s only one root per tree. Node: Each element in the tree. It can have a name, value, or any data you want to store. Edge: The link between two nodes, representing their relationship. Children: Nodes that branch out from another node. Parent: The converse concept of children; a node that has other nodes branching from it. Leaf: A node without children. It\u0026rsquo;s the end point of a tree branch. Subtree: A section of the tree that is itself a tree, consisting of a node and all its descendants. Types of Trees There are several types of trees used in data structures, each with its unique properties and uses:\nBinary Tree: Each node has at most two children (commonly referred to as the left and right children). Binary Search Tree (BST): A binary tree where each node\u0026rsquo;s left descendants are less than the node, and the right descendants are greater. AVL Tree: A self-balancing binary search tree where the difference between heights of left and right subtrees cannot be more than one for all nodes. B-Tree: Often used in databases, a B-tree is a self-balancing tree where a node can have more than two children and more than one key. Red-Black Tree: Another type of self-balancing binary search tree where each node has an extra attribute: color, which is either red or black. Why Use Trees? Trees are used in data structures for several reasons:\nOrganized Data: Trees provide a natural structure for organizing data hierarchically. Efficient Searches: Trees like binary search trees make it easier and faster to search for data. Flexible Size: Trees can expand as new nodes are added, making them flexible in terms of size and structure. Ordering: Trees can represent data in an ordered manner, allowing for sorting operations. Examples of Trees in Action Here are a few examples to help you visualize how trees are used in real-world applications:\nFile System: Your computer\u0026rsquo;s file system is structured as a tree, with folders as nodes and files as leaves. HTML DOM: The Document Object Model (DOM) for web pages is a tree structure, with HTML elements as nodes. Decision Trees: Used in machine learning for decision-making processes. Understanding Trees Through Examples Let\u0026rsquo;s take a simple example to understand the basic operations in a tree, particularly a binary search tree:\nInsertion: To insert a value, start at the root and compare the value to insert. If it\u0026rsquo;s smaller, go to the left child; if larger, go to the right child. Repeat this process until finding an empty spot to insert the new node. Searching: Similar to insertion, but instead of inserting, you\u0026rsquo;re looking for a value. Start at the root and traverse left or right depending on whether the value is smaller or larger. For example, if we have a binary search tree containing the numbers 15, 10, 20, 8, 12, 17, and 25, and we want to add the number 16, we would compare it to 15 (go right), then compare it to 20 (go left), and then insert it to the left of 17.\nUnderstanding trees is a fundamental part of learning data structures and algorithms. They are powerful tools for organizing data, speeding up search operations, and maintaining hierarchical relationships. With this basic understanding, you\u0026rsquo;ll be able to delve deeper into more complex tree structures and their applications.\n","permalink":"https://cihanilhan.dev/tutorials/trees/","summary":"Trees Trees are a fundamental concept in computer science, used in various applications from databases and file systems to AI and machine learning.\nWhat is a Tree? In data structures, a tree is a way of representing hierarchical information. It consists of nodes connected by edges, similar to how branches connect to a tree trunk in nature. However, in data structures, our tree is usually inverted, with the root at the top and branches extending downwards.","title":"Trees"},{"content":"Queues Welcome to our exploration of one of the most essential and widely used data structures in computer science: the queue. Like in real life, where a queue at a coffee shop functions on a first-come, first-served basis, the queue data structure follows a similar principle. This blog aims to demystify queues, making them easy to understand for beginners and students alike. Let\u0026rsquo;s dive in!\nWhat is a Queue? A queue is a linear data structure that stores items in a sequential order. The operations on a queue are performed based on the FIFO (First In, First Out) principle, which means that the first element added to the queue will be the first one to be removed. This is analogous to a line of people waiting for their turn at a ticket counter, where the person who arrives first gets served first.\nKey Operations The primary operations that can be performed on a queue are:\nEnqueue: Adding an item to the end of the queue. Dequeue: Removing the item from the front of the queue. Peek/Front: Viewing the item at the front of the queue without removing it. IsEmpty: Checking if the queue is empty. Real-life Examples To better understand queues, let\u0026rsquo;s consider some real-life scenarios:\nTicket Lines: People waiting in line for movie tickets are served in the order they arrive. Print Queue: Documents sent to a printer are printed in the order they were sent. Call Center: Incoming calls are placed in a queue and answered in the order they are received. Implementing a Queue Let\u0026rsquo;s look at a simple example of how a queue can be implemented in Python:\nclass Queue: def __init__(self): self.items = [] def enqueue(self, item): self.items.append(item) def dequeue(self): if not self.is_empty(): return self.items.pop(0) def is_empty(self): return len(self.items) == 0 def peek(self): if not self.is_empty(): return self.items[0] # Example usage queue = Queue() queue.enqueue(\u0026#39;John\u0026#39;) queue.enqueue(\u0026#39;Jane\u0026#39;) queue.enqueue(\u0026#39;Doe\u0026#39;) print(queue.dequeue()) # John print(queue.peek()) # Jane In this example, we define a Queue class with methods to enqueue (add) items, dequeue (remove) items, check if the queue is empty, and peek at the first item. The implementation uses a Python list to store the queue elements.\nWhy Use Queues? Queues are incredibly useful in situations where operations need to be handled in a specific order. They are widely used in operating systems for managing processes, in networking for handling packets, and in web development for managing requests.\nConclusion Understanding how queues work and where to use them is a fundamental skill in computer science and programming. The FIFO principle makes queues a fair and efficient way to handle data in sequential order. With this knowledge, you\u0026rsquo;ll find numerous applications for queues in your projects and real-world scenarios.\nWe hope this blog has provided you with a clear understanding of queues and their importance in data structures and algorithms. Happy coding!\n","permalink":"https://cihanilhan.dev/tutorials/queues/","summary":"Queues Welcome to our exploration of one of the most essential and widely used data structures in computer science: the queue. Like in real life, where a queue at a coffee shop functions on a first-come, first-served basis, the queue data structure follows a similar principle. This blog aims to demystify queues, making them easy to understand for beginners and students alike. Let\u0026rsquo;s dive in!\nWhat is a Queue? A queue is a linear data structure that stores items in a sequential order.","title":"Queues"},{"content":"Stacks In the realm of computer science, particularly in data structures and algorithms, a stack stands out as a simple yet powerful tool for managing data. Imagine a stack of plates at a buffet, where you can only take the top plate and add a new plate to the top. This real-world analogy perfectly encapsulates the essence of a stack in computing: a linear data structure that follows the Last In, First Out (LIFO) principle. In this blog, we\u0026rsquo;ll break down the concept of stacks, their operations, and provide examples to make it easy to understand for students embarking on their data structures journey.\nWhat is a Stack? A stack is a collection of elements with two principal operations: push, which adds an element to the collection, and pop, which removes the most recently added element. The last element added is the first one to be removed, hence the Last In, First Out (LIFO) principle. It\u0026rsquo;s like a stack of books; you can only remove the book on top, and any new book gets added on top of the pile.\nKey Operations Push: Add an element to the top of the stack. Pop: Remove and return the top element from the stack. Peek or Top: Return the top element of the stack without removing it. IsEmpty: Check if the stack is empty. Examples Let\u0026rsquo;s dive into some examples to better understand how stacks work:\nExample 1: Stack of Plates\nConsider a stack of plates. When you add a new plate, you place it on top of the stack. When you need a plate, you take the one at the top. If you want to look at the top plate without taking it, you\u0026rsquo;re essentially \u0026ldquo;peeking\u0026rdquo; at the stack.\nExample 2: Browser Back Button\nA more technical example is the way a web browser tracks the pages you\u0026rsquo;ve visited. Every time you visit a new page, the browser \u0026ldquo;pushes\u0026rdquo; that page onto a stack. When you hit the back button, the browser \u0026ldquo;pops\u0026rdquo; the current page from the stack, taking you back to the previous page.\nImplementing a Stack Here\u0026rsquo;s a simple implementation of a stack in Python:\nclass Stack: def __init__(self): self.items = [] def is_empty(self): return self.items == [] def push(self, item): self.items.append(item) def pop(self): return self.items.pop() def peek(self): return self.items[-1] # Example usage stack = Stack() stack.push(\u0026#39;A\u0026#39;) # Stack: [\u0026#39;A\u0026#39;] stack.push(\u0026#39;B\u0026#39;) # Stack: [\u0026#39;A\u0026#39;, \u0026#39;B\u0026#39;] print(stack.peek()) # Output: \u0026#39;B\u0026#39; stack.pop() # Stack: [\u0026#39;A\u0026#39;] print(stack.peek()) # Output: \u0026#39;A\u0026#39; Applications of Stacks Stacks are widely used in various computer science applications, including:\nExpression Evaluation: Stacks are used to evaluate arithmetic expressions, such as infix to postfix conversion. Function Calls: The call stack keeps track of function calls in a program, allowing for function execution and return. Undo Mechanisms: Many applications use stacks to keep track of operations for undo functionalities. Conclusion Stacks are a fundamental data structure in computer science, with a wide range of applications from web browsing to programming language compilers. Understanding how to implement and use stacks is a crucial step in mastering data structures and algorithms. By grasping the LIFO principle and practicing with real-world examples, students can develop a solid foundation in computer science concepts and problem-solving strategies.\n","permalink":"https://cihanilhan.dev/tutorials/stacks/","summary":"Stacks In the realm of computer science, particularly in data structures and algorithms, a stack stands out as a simple yet powerful tool for managing data. Imagine a stack of plates at a buffet, where you can only take the top plate and add a new plate to the top. This real-world analogy perfectly encapsulates the essence of a stack in computing: a linear data structure that follows the Last In, First Out (LIFO) principle.","title":"Stacks"},{"content":"Linked Lists Linked lists are a fundamental data structure in computer science, used to store a collection of items in a sequential manner. Unlike arrays, linked lists store elements in separate objects called \u0026ldquo;nodes,\u0026rdquo; and each node contains a reference (or a \u0026ldquo;link\u0026rdquo;) to the next node in the sequence. This structure allows for efficient insertion and removal of elements without needing to reorganize the entire data structure, making linked lists a versatile choice for many algorithms and applications. In this blog, we\u0026rsquo;ll explore the basics of linked lists, their types, and provide simple examples to help you understand how they work.\nWhat is a Linked List? At its core, a linked list is a collection of nodes, where each node contains data and a reference (or pointer) to the next node in the list. The first node is called the head, and the last node, which points to null (indicating the end of the list), is known as the tail. This structure allows data to be stored in a flexible and efficient manner.\nWhy Use Linked Lists? Linked lists offer several advantages over traditional arrays, including:\nDynamic Size: Unlike arrays, linked lists can easily grow or shrink in size, making them ideal for situations where the number of elements can change over time. Efficient Operations: Adding or removing elements from a linked list is generally more efficient than doing so with an array, especially if the operation is near the beginning of the list, because it doesn\u0026rsquo;t require shifting elements. However, linked lists also have some drawbacks, such as:\nSequential Access: Accessing an element in a linked list requires traversing from the head of the list to the desired node, which can be slower than indexed access in an array. Extra Memory: Each element in a linked list requires extra memory for the reference (or pointer) to the next node. Types of Linked Lists Singly Linked List: Each node contains data and a reference to the next node. This is the simplest form of a linked list. Doubly Linked List: Nodes contain a reference to both the next and the previous node, allowing for backward traversal of the list. Circular Linked List: The last node of the list points back to the first node, forming a circle. Example: Implementing a Singly Linked List Let\u0026rsquo;s implement a basic singly linked list in Python to illustrate how it works:\nclass 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_node = self.head while last_node.next: last_node = last_node.next last_node.next = new_node def print_list(self): cur_node = self.head while cur_node: print(cur_node.data, end=\u0026#34; -\u0026gt; \u0026#34;) cur_node = cur_node.next print(\u0026#34;None\u0026#34;) In this example, the LinkedList class manages the list, and the Node class represents each element in the list. To add an element, we create a new node and traverse the list until we reach the end, then link the new node to the last node in the list. The print_list method allows us to visualize the list by printing each element\u0026rsquo;s data followed by an arrow pointing to the next element, ending with \u0026ldquo;None\u0026rdquo; to indicate the end of the list.\nWorking with the Linked List Here\u0026rsquo;s how you can use the above implementation to create a linked list and add some elements:\n# Create a new linked list my_list = LinkedList() # Append elements my_list.append(1) my_list.append(2) my_list.append(3) # Print the list my_list.print_list() # Output: 1 -\u0026gt; 2 -\u0026gt; 3 -\u0026gt; None Conclusion Linked lists are a powerful and flexible data structure that can handle dynamic data sets efficiently. By understanding the basic concepts and operations of linked lists, you can start to leverage their capabilities in your algorithms and applications. Whether you\u0026rsquo;re implementing a singly, doubly, or circular linked list, the principles remain the same, offering a foundation for more complex data structures and algorithms. As you continue your journey in learning data structures, experimenting with linked lists will provide valuable insights into the organization and manipulation of data.\n","permalink":"https://cihanilhan.dev/tutorials/linked-lists/","summary":"Linked Lists Linked lists are a fundamental data structure in computer science, used to store a collection of items in a sequential manner. Unlike arrays, linked lists store elements in separate objects called \u0026ldquo;nodes,\u0026rdquo; and each node contains a reference (or a \u0026ldquo;link\u0026rdquo;) to the next node in the sequence. This structure allows for efficient insertion and removal of elements without needing to reorganize the entire data structure, making linked lists a versatile choice for many algorithms and applications.","title":"Linked Lists"},{"content":"Understanding Classes When venturing into the world of programming, especially in data structures and algorithms, one fundamental concept you\u0026rsquo;ll come across is the use of classes. Classes are the blueprint of objects; they define the properties (attributes) and behaviors (methods) that the objects created from them will have. This concept is crucial in organizing and managing code, especially when dealing with complex data structures like lists, trees, graphs, and more.\nWhat is a Class? In simple terms, a class is a template for creating objects. Objects are instances of classes. Think of a class as a sketch (prototype) of a house. It contains all the details about the floors, doors, windows, etc. Based on this sketch, you can build as many houses (objects) as you like, each with its own specific characteristics.\nAttributes and Methods Attributes: These are the properties or characteristics of a class. For example, if we have a class Dog, attributes could be breed, age, and color.\nMethods: These are the actions or functions that a class can perform. Continuing with the Dog example, methods could be bark(), eat(), and sleep().\nExample: Implementing a Stack To understand how classes work in practice, let\u0026rsquo;s implement a simple data structure: a stack. A stack is a linear data structure that follows the Last In, First Out (LIFO) principle. The last element added to the stack will be the first one to be removed.\nclass Stack: def __init__(self): self.items = [] def push(self, item): self.items.append(item) def pop(self): if not self.isEmpty(): return self.items.pop() else: return \u0026#34;Stack is empty.\u0026#34; def peek(self): if not self.isEmpty(): return self.items[-1] else: return \u0026#34;Stack is empty.\u0026#34; def isEmpty(self): return self.items == [] def size(self): return len(self.items) How Does This Work? Initialization: The __init__ method initializes a new instance of the class, creating an empty list items to represent the stack.\nPush: The push method adds an item to the top of the stack.\nPop: The pop method removes and returns the top item of the stack. It checks if the stack is empty first to avoid errors.\nPeek: The peek method returns the top item of the stack without removing it, allowing us to see what\u0026rsquo;s at the top without altering the stack.\nisEmpty: The isEmpty method checks whether the stack is empty and returns a boolean value.\nSize: The size method returns the number of items in the stack.\nUsage Example my_stack = Stack() my_stack.push(\u0026#34;A\u0026#34;) my_stack.push(\u0026#34;B\u0026#34;) print(my_stack.peek()) # Output: B my_stack.pop() print(my_stack.size()) # Output: 1 Why Use Classes in Data Structures and Algorithms? Classes help encapsulate and organize code related to specific data structures or algorithms, making it easier to understand, maintain, and reuse code. For instance, by defining a class for a binary tree, you can easily implement methods to insert, delete, or search for elements without worrying about the underlying data structure every time you want to perform these operations.\nClasses also promote the principle of abstraction, allowing you to work with high-level operations without needing to know the details of how these operations are implemented.\nConclusion Understanding classes and how to use them is crucial in programming, especially when dealing with data structures and algorithms. Classes allow you to encapsulate attributes and methods related to specific data structures, making your code more organized, reusable, and easy to maintain. Start experimenting with classes by implementing simple data structures like stacks or queues, and gradually move on to more complex structures. Happy coding!\n","permalink":"https://cihanilhan.dev/tutorials/what-are-classes/","summary":"Understanding Classes When venturing into the world of programming, especially in data structures and algorithms, one fundamental concept you\u0026rsquo;ll come across is the use of classes. Classes are the blueprint of objects; they define the properties (attributes) and behaviors (methods) that the objects created from them will have. This concept is crucial in organizing and managing code, especially when dealing with complex data structures like lists, trees, graphs, and more.","title":"Classes"},{"content":"Understanding Pointers While Python does not use pointers explicitly like C or C++, understanding how references and memory management work in Python can give you a pointer-like perspective. This guide will help you understand these concepts with simplicity and clarity.\nWhat Are Pointers? A Quick Recap In languages like C, a pointer is a variable that stores the memory address of another variable. In Python, we don\u0026rsquo;t deal with memory addresses directly, but we do work with references, which you can think of as Python\u0026rsquo;s high-level abstraction of pointers.\nPython\u0026rsquo;s Approach to References In Python, variables are names attached to objects, and these objects can have multiple names bound to them. When you assign an object to a variable, you are essentially creating a reference to the object\u0026rsquo;s memory address.\nExample: References in Python a = [1, 2, 3] # `a` references a list object b = a # `b` now references the same list object as `a` Modifying Through References a = [1, 2, 3] b = a b.append(4) # Modifying the list through `b` print(a) # Output: [1, 2, 3, 4] Python\u0026rsquo;s Dynamic Memory Management Python handles memory allocation and garbage collection automatically. When an object\u0026rsquo;s reference count drops to zero (i.e., no variable points to it), Python\u0026rsquo;s garbage collector removes the object from memory. This automatic memory management simplifies working with dynamic data structures.\nExample: Dynamic Data Structures Let\u0026rsquo;s consider implementing a simple linked list in Python, showcasing dynamic memory usage without manual pointer management.\nLinked List Node Definition class Node: def __init__(self, data): self.data = data self.next = None Adding a New Node class LinkedList: def __init__(self): self.head = None def append(self, data): if not self.head: self.head = Node(data) else: current = self.head while current.next: current = current.next current.next = Node(data) In this Python example, self.head and current.next serve as references to Node objects, similar to how pointers would link nodes in a linked list in languages like C.\nConclusion While Python abstracts away the explicit use of pointers found in languages like C, understanding references and memory management is crucial. Python\u0026rsquo;s approach allows you to focus on the logic and structure of your data structures and algorithms without worrying about low-level memory management details.\n","permalink":"https://cihanilhan.dev/tutorials/pointers/","summary":"Understanding Pointers While Python does not use pointers explicitly like C or C++, understanding how references and memory management work in Python can give you a pointer-like perspective. This guide will help you understand these concepts with simplicity and clarity.\nWhat Are Pointers? A Quick Recap In languages like C, a pointer is a variable that stores the memory address of another variable. In Python, we don\u0026rsquo;t deal with memory addresses directly, but we do work with references, which you can think of as Python\u0026rsquo;s high-level abstraction of pointers.","title":"Pointers"},{"content":"Importance of Big-O Notation When you start learning about data structures and algorithms, one term that constantly pops up is \u0026lsquo;Big O Notation\u0026rsquo;. It might seem daunting at first, but understanding Big O is crucial for assessing the efficiency of algorithms. In this blog post, we\u0026rsquo;ll break down what Big O Notation is, why it\u0026rsquo;s important, and how you can use it to improve your coding skills.\nWhat is Big O Notation? Big O Notation is a mathematical concept used in computer science to describe the performance or complexity of an algorithm. Specifically, it describes the worst-case scenario, or the maximum amount of time or space an algorithm will take to run.\nThink of it as a way to measure the efficiency of your code. If you were a chef, Big O would be like estimating the maximum time it would take to prepare a dish, considering the most complex recipe.\nWhy is Big O Notation Important? Understanding the Big O Notation of an algorithm helps in:\nPredicting Performance: It gives you a high-level understanding of how the algorithm will perform as the size of the input data increases. Writing Efficient Code: It helps in identifying bottlenecks and optimizing code for better performance. Making Informed Choices: When choosing between multiple algorithms to solve a problem, Big O Notation helps in selecting the most efficient one. Common Big O Notations Here are some of the most common Big O Notations, ordered from most efficient to least efficient:\nO(1) - Constant Time:\nRegardless of the dataset size, the algorithm takes a constant time to complete. Example: Accessing a specific element in an array. O(log n) - Logarithmic Time:\nAs the dataset size increases, the time it takes to complete the task increases logarithmically. Example: Binary Search in a sorted array. O(n) - Linear Time:\nThe time taken increases linearly with the increase in dataset size. Example: Finding the maximum number in an unsorted array. O(n log n) - Linearithmic Time:\nThe time taken increases linearly and logarithmically with the dataset size. Example: Efficient sorting algorithms like Merge Sort or Quick Sort. O(n^2) - Quadratic Time:\nThe time taken is proportional to the square of the dataset size. Example: Bubble Sort or Insertion Sort. O(2^n) - Exponential Time:\nThe time taken doubles with every addition to the dataset. Example: Certain recursive algorithms, like the naive solution for the Fibonacci sequence. O(n!) - Factorial Time:\nThe time taken grows factorialy with the dataset size. Example: Solving the Travelling Salesman Problem via brute-force. Examples in Practice To solidify your understanding, let\u0026rsquo;s look at two examples:\nLinear Search (O(n)): Imagine you have a list of names, and you need to find if \u0026lsquo;John\u0026rsquo; is in the list. You start from the beginning and check each name until you find \u0026lsquo;John\u0026rsquo;. In the worst case, you\u0026rsquo;ll check every name once. So, if the list has \u0026rsquo;n\u0026rsquo; names, you\u0026rsquo;ll make \u0026rsquo;n\u0026rsquo; comparisons.\nBinary Search (O(log n)): Now, imagine the list is sorted alphabetically. Instead of searching sequentially, you start in the middle. If \u0026lsquo;John\u0026rsquo; is alphabetically after the middle name, you ignore the first half of the list; otherwise, you ignore the second half. You then repeat this process on the remaining half. This way, the number of names you need to check reduces exponentially with each step.\nConclusion Big O Notation is a powerful tool in the world of algorithms and data structures, providing a high-level understanding of algorithm efficiency. It\u0026rsquo;s not about the exact time an algorithm takes to run, but rather about how its runtime increases as the data it operates on grows.\nRemember, the goal is not just to write code that works, but to write code that works efficiently, even with large datasets. By understanding and applying Big O Notation, you\u0026rsquo;re taking a significant step towards writing high-quality, performance-optimized code.\nKeep practicing, keep learning, and soon, you\u0026rsquo;ll find yourself intuitively understanding the efficiency of different algorithms and data structures. Happy coding!\n","permalink":"https://cihanilhan.dev/tutorials/big-o-notation/","summary":"Importance of Big-O Notation When you start learning about data structures and algorithms, one term that constantly pops up is \u0026lsquo;Big O Notation\u0026rsquo;. It might seem daunting at first, but understanding Big O is crucial for assessing the efficiency of algorithms. In this blog post, we\u0026rsquo;ll break down what Big O Notation is, why it\u0026rsquo;s important, and how you can use it to improve your coding skills.\nWhat is Big O Notation?","title":"Big-O Notation"},{"content":"Functions A function in Python is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing.\nHere\u0026rsquo;s how you can define a function:\ndef greet(name): print(f\u0026#34;Hello, {name}!\u0026#34;) And here\u0026rsquo;s how you can call it:\ngreet(\u0026#34;Alice\u0026#34;) # Output: Hello, Alice! Functions can also return a value using the return statement:\ndef add(a, b): return a + b result = add(5, 3) # result is now 8 Methods Methods in Python are very similar to functions except they are associated with object/classes. Methods in Python are in fact functions that are called using dot notation. For example, list objects have methods called append, insert, remove, sort, and so on.\nHere\u0026rsquo;s how you can define a method:\nclass MyClass: def greet(self): print(\u0026#34;Hello, World!\u0026#34;) And here\u0026rsquo;s how you can call it:\nobj = MyClass() obj.greet() # Output: Hello, World! ","permalink":"https://cihanilhan.dev/tutorials/python-functions-methods/","summary":"Functions A function in Python is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing.\nHere\u0026rsquo;s how you can define a function:\ndef greet(name): print(f\u0026#34;Hello, {name}!\u0026#34;) And here\u0026rsquo;s how you can call it:\ngreet(\u0026#34;Alice\u0026#34;) # Output: Hello, Alice! Functions can also return a value using the return statement:\ndef add(a, b): return a + b result = add(5, 3) # result is now 8 Methods Methods in Python are very similar to functions except they are associated with object/classes.","title":"Python functions and methods"},{"content":"Control flow statements in Python are used to control the order in which the program\u0026rsquo;s code executes. Here are some of the most common ones:\nIf, Elif, and Else if, elif, and else are used for conditional execution, i.e., to execute a certain block of code if a certain condition is met.\nif: The if statement is used to test a specific condition. If the condition is True, the block of code under it is executed. x = 10 if x \u0026gt; 5: print(\u0026#34;x is greater than 5\u0026#34;) elif: The elif (short for else if) statement is used to check multiple expressions for True and execute a block of code as soon as one of the conditions evaluates to True. x = 10 if x \u0026gt; 10: print(\u0026#34;x is greater than 10\u0026#34;) elif x == 10: print(\u0026#34;x is equal to 10\u0026#34;) else: The else statement is used to catch anything which isn\u0026rsquo;t caught by the preceding conditions. x = 10 if x \u0026gt; 10: print(\u0026#34;x is greater than 10\u0026#34;) elif x \u0026lt; 10: print(\u0026#34;x is less than 10\u0026#34;) else: print(\u0026#34;x is equal to 10\u0026#34;) Loops Loops are used to repeatedly execute a block of code. Python has two types of loops - for and while.\nfor: The for loop is used for iterating over a sequence (like a list, tuple, dictionary, string, or set) or other iterable objects. Iterating over a sequence is called traversal. # Example of for loop for i in range(5): print(i) while: The while loop is used to repeatedly execute a block of code as long as a condition is True. # Example of while loop i = 0 while i \u0026lt; 5: print(i) i += 1 ","permalink":"https://cihanilhan.dev/tutorials/python-control-flow-statements/","summary":"Control flow statements in Python are used to control the order in which the program\u0026rsquo;s code executes. Here are some of the most common ones:\nIf, Elif, and Else if, elif, and else are used for conditional execution, i.e., to execute a certain block of code if a certain condition is met.\nif: The if statement is used to test a specific condition. If the condition is True, the block of code under it is executed.","title":"Python control flow statements"},{"content":"Data structures in Python are used to store collections of data in an organized and efficient way. Here are some of the most common ones:\nLists A list in Python is a collection of items. Lists are ordered, changeable, and allow duplicate values. Lists are written with square brackets.\n# Example of list data type my_list = [\u0026#34;apple\u0026#34;, \u0026#34;banana\u0026#34;, \u0026#34;cherry\u0026#34;] Tuples A tuple in Python is similar to a list. The difference between the two is that tuples are immutable, which means we cannot change the elements of a tuple once it is assigned.\n# Example of tuple data type my_tuple = (\u0026#34;apple\u0026#34;, \u0026#34;banana\u0026#34;, \u0026#34;cherry\u0026#34;) Sets A set in Python is an unordered collection of items. Every set element is unique (no duplicates) and must be immutable (cannot be changed). However, a set itself is mutable. We can add or remove items from it.\n# Example of set data type my_set = {\u0026#34;apple\u0026#34;, \u0026#34;banana\u0026#34;, \u0026#34;cherry\u0026#34;} Dictionaries A dictionary in Python is an unordered collection of items. Each item of a dictionary has a key/value pair.\n# Example of dictionary data type my_dict = {\u0026#34;name\u0026#34;: \u0026#34;John\u0026#34;, \u0026#34;age\u0026#34;: 30, \u0026#34;city\u0026#34;: \u0026#34;New York\u0026#34;} ","permalink":"https://cihanilhan.dev/tutorials/python-data-structures/","summary":"Data structures in Python are used to store collections of data in an organized and efficient way. Here are some of the most common ones:\nLists A list in Python is a collection of items. Lists are ordered, changeable, and allow duplicate values. Lists are written with square brackets.\n# Example of list data type my_list = [\u0026#34;apple\u0026#34;, \u0026#34;banana\u0026#34;, \u0026#34;cherry\u0026#34;] Tuples A tuple in Python is similar to a list. The difference between the two is that tuples are immutable, which means we cannot change the elements of a tuple once it is assigned.","title":"Python data structures"},{"content":"Python has several built-in data types, which are commonly used in Python programming. Here are some of the most common ones:\nNumbers Python supports three types of numbers - integer, float, and complex.\nInteger: These are whole numbers, positive or negative, without decimals. Example: 5, -3, 0 Float: These are real numbers with a decimal point. Example: 3.14, -0.01, 9.0 Complex: These are numbers with a real and imaginary component. Example: 3+4j, 5j # Examples of number data types x = 5 # integer y = 3.14 # float z = 3+4j # complex Strings Strings in Python are sequences of characters. They are created by enclosing characters in quotes. Python treats single quotes and double quotes as the same.\n# Examples of string data type str1 = \u0026#34;Hello, World!\u0026#34; # string with double quotes str2 = \u0026#39;Hello, Python!\u0026#39; # string with single quotes Lists A list in Python is a collection of items. Lists are ordered, changeable, and allow duplicate values. Lists are written with square brackets.\n# Example of list data type my_list = [\u0026#34;apple\u0026#34;, \u0026#34;banana\u0026#34;, \u0026#34;cherry\u0026#34;] Tuples A tuple in Python is similar to a list. The difference between the two is that tuples are immutable, which means we cannot change the elements of a tuple once it is assigned.\n# Example of tuple data type my_tuple = (\u0026#34;apple\u0026#34;, \u0026#34;banana\u0026#34;, \u0026#34;cherry\u0026#34;) Dictionaries A dictionary in Python is an unordered collection of items. Each item of a dictionary has a key/value pair.\n# Example of dictionary data type my_dict = {\u0026#34;name\u0026#34;: \u0026#34;John\u0026#34;, \u0026#34;age\u0026#34;: 30, \u0026#34;city\u0026#34;: \u0026#34;New York\u0026#34;} Booleans In Python, Booleans represent one of two values: True or False.\n# Examples of boolean data type is_true = True is_false = False ","permalink":"https://cihanilhan.dev/tutorials/python-data-types/","summary":"Python has several built-in data types, which are commonly used in Python programming. Here are some of the most common ones:\nNumbers Python supports three types of numbers - integer, float, and complex.\nInteger: These are whole numbers, positive or negative, without decimals. Example: 5, -3, 0 Float: These are real numbers with a decimal point. Example: 3.14, -0.01, 9.0 Complex: These are numbers with a real and imaginary component. Example: 3+4j, 5j # Examples of number data types x = 5 # integer y = 3.","title":"Python data types"},{"content":"What is a Variable in Python? Think of a variable as a storage box where you can keep different items. In Python, a variable allows you to store a value (like a number, a string of text, or a list of items) that you can use and manipulate in your code.\nCreating Variables Creating a variable in Python is straightforward. You just need to choose a name for your variable and then assign a value to it using the equals sign =.\ngreeting = \u0026#34;Hello, World!\u0026#34; age = 25 height = 5.9 Rules for Naming Variables When naming your variables, there are a few rules you should follow:\nNames can contain letters, numbers, and underscores, but they can\u0026rsquo;t start with a number. Avoid using Python\u0026rsquo;s built-in keywords (like if, for, return, etc.) as variable names. Variable names are case-sensitive (Age, age, and AGE would be three different variables). Use names that are descriptive and make your code easier to understand. Using Variables Once you have created your variables, you can use them in various ways. You can print their values, combine them with other variables, or use them in calculations. Here are some examples:\n# Printing variables print(greeting) # Output: Hello, World! print(\u0026#34;I am\u0026#34;, age, \u0026#34;years old.\u0026#34;) # Output: I am 25 years old. # Using variables in calculations next_year_age = age + 1 print(\u0026#34;Next year, I will be\u0026#34;, next_year_age, \u0026#34;years old.\u0026#34;) # Output: Next year, I will be 26 years old. # Combining strings (concatenation) welcome_message = greeting + \u0026#34; I am a Python program.\u0026#34; print(welcome_message) # Output: Hello, World! I am a Python program. Changing Variable Values One of the great things about variables is that their values aren\u0026rsquo;t set in stone—you can change them as needed. Here\u0026rsquo;s how you can update the value of a variable:\n# Changing the value of a variable age = 26 print(\u0026#34;My new age is\u0026#34;, age) # Output: My new age is 26 In this example, we updated the age variable from 25 to 26. You can update a variable to not only a different number but also a different type of data altogether, like changing from a number to a string.\n","permalink":"https://cihanilhan.dev/tutorials/python-variables/","summary":"What is a Variable in Python? Think of a variable as a storage box where you can keep different items. In Python, a variable allows you to store a value (like a number, a string of text, or a list of items) that you can use and manipulate in your code.\nCreating Variables Creating a variable in Python is straightforward. You just need to choose a name for your variable and then assign a value to it using the equals sign =.","title":"Python variables"},{"content":"Problem: Middle of the Linked List Description Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node.\nExamples:\nInput: head = [1,2,3,4,5]\nOutput: [3,4,5]\nExplanation: The middle node of the list is node 3.\nInput: head = [1,2,3,4,5,6]\nOutput: [4,5,6]\nExplanation: Since the list has two middle nodes with values 3 and 4, we return the second one.\nSolution in Python class Solution: def middleNode(self, head: Optional[ListNode]) -\u0026gt; Optional[ListNode]: temp = head while temp and temp.next: head = head.next temp = temp.next.next return head Explanation: The solution uses the two-pointer technique, often known as the \u0026ldquo;slow and fast pointer\u0026rdquo; method. The temp pointer moves twice for every single move of the head pointer. By the time temp reaches the end of the list, the head pointer will be at the middle of the list. This approach effectively halves the traversal time, making it an efficient way to find the middle of a linked list.\nLink to the problem: LeetCode\n","permalink":"https://cihanilhan.dev/newsletter/001-hello-world/","summary":"Problem: Middle of the Linked List Description Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node.\nExamples:\nInput: head = [1,2,3,4,5]\nOutput: [3,4,5]\nExplanation: The middle node of the list is node 3.\nInput: head = [1,2,3,4,5,6]\nOutput: [4,5,6]\nExplanation: Since the list has two middle nodes with values 3 and 4, we return the second one.","title":"Newsletter: Question of the Week"},{"content":"","permalink":"https://cihanilhan.dev/seachindex/","summary":"","title":"Search Cache"}]