Document (1)
Document (1)
1. `is`
2. `is not`
1. Linear Search
2. Binary Search
- `//`: Floor Division (Quotient of the division rounded down to the nearest integer)
1. Encapsulation
2. Inheritance
3. Polymorphism
4. Abstraction
### Definitions:
- **Data Hiding:** Restricting access to certain details of an object and preventing the direct
modification of internal state.
- **Data Abstraction:** Presenting only the essential features of an object, hiding its implementation
details.
### Tree Terms:
A singly linked list is a linear data structure where each element points to the next element in the
sequence. Example: `1 -> 2 -> 3 -> None`.
1. **Direction:** Directed graph edges have a direction, while undirected graph edges do not.
2. **Connections:** In directed graphs, edges have a source and a destination. In undirected graphs,
edges connect nodes without a specific direction.
```python
N=5
Factorial = 1
Factorial *= i
Print(factorial)
```
```python
# Adding students
Students[4] = ‘David’
Students[5] = ‘Eve’
Students[6] = ‘Frank’
Del students[1]
Print(students)
```
A binary tree is a hierarchical data structure in which each node has at most two children, referred to as
the left child and the right child. Example:
```
/\
2 3
/\
4 5
```
1. **Numeric Array:**
```python
Numeric_array = [1, 2, 3, 4, 5]
```
2. **Character Array:**
```python
```
```python
Def insertion_sort(arr):
Key = arr[i]
J=I–1
Arr[j + 1] = arr[j]
J -= 1
Arr[j + 1] = key
Insertion_sort(my_list)
Print(“Sorted array:”, my_list)
```
```python
My_tuple = (3, 7, 1, 8, 2)
Min_value = min(my_tuple)
Max_value = max(my_tuple)
Print(“Minimum:”, min_value)
Print(“Maximum:”, max_value)
```
```python
Class Node:
Self.data = data
Self.left = None
Self.right = None
Def pre_order_traversal(root):
If root:
Print(root.data, end=” “)
Pre_order_traversal(root.left)
Pre_order_traversal(root.right)
# Example
Root = Node(1)
Root.left = Node(2)
Root.right = Node(3)
Root.left.left = Node(4)
Root.left.right = Node(5)
# Pre-order traversal
Pre_order_traversal(root)
```
```python
A=8
B=3
Result_add = add(a, b)
Result_subtract = subtract(a, b)
Print(“Addition:”, result_add)
Print(“Subtraction:”, result_subtract)
```
```python
Class Geometry:
# Example
Geometry_obj = Geometry()
Area_square = geometry_obj.calculate_area(5)
Area_rectangle = geometry_obj.calculate_area(4, 6)
```
```python
Class Queue:
Def __init__(self):
Self.items = []
Self.items.insert(0, item)
Def dequeue(self):
If not self.is_empty():
Return self.items.pop()
Def is_empty(self):
Return len(self.items) == 0
# Example
My_queue = Queue()
My_queue.enqueue(1)
My_queue.enqueue(2)
My_queue.enqueue(3)
Print(“Dequeued:”, my_queue.dequeue())
Print(“Dequeued:”, my_queue.dequeue())
```
```python
Def reverse_number(number):
Reversed_num = 0
Digit = number % 10
Number = number // 10
Return reversed_num
# Example
Original_number = 12345
Reversed_number = reverse_number(original_number)
```
**mymodule.py:**
```python
Class Rectangle:
Self.length = length
Self.breadth = breadth
Def calculate_area(self):
```
**main_program.py:**
```python
Rectangle1 = Rectangle(5, 8)
Rectangle2 = Rectangle(3, 6)
```
# Array Declaration
Numeric_array = [1, 2, 3, 4, 5]
# Insertion
Numeric_array.append(6)
```
```python
Import networkx as nx
G = nx.DiGraph()
```
i)
```python
A = [2, 5, 1, 3, 6, 9, 7]
A[2:6] = [2, 4, 9, 0]
Print(a)
```
ii)
```python
B = [‘Hello’, ‘Good’]
b.append(‘Data Structure’)
print(b)
```
iii)
```python
T1 = [3, 5, 6, 8]
Print(t1[2])
Print(t1[-1])
Print(t1[2:])
Print(t1[:])
```
Output:
```
[6, 8]
[3, 5, 6, 8]
```
### Explaining Methods of Packages:
```python
Import numpy as np
```
```python
Mean_value = np.mean(arr)
```
```python
```
```python
X = [1, 2, 3]
Y = [2, 4, 6]
Plt.plot(x, y)
```
```python
Plt.xlabel(‘X-axis’)
```
```python
Plt.show()
```
```python
Import pandas as pd
```
```python
First_rows = df.head()
```
```python
Statistics = df.describe()
```
```python
If arr[mid] == target:
Return mid
Low = mid + 1
Else:
High = mid – 1
# Example
My_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Target_value = 5
```
i)
```python
A = [2, 5, 1, 3, 6, 9, 7]
A[2:6] = [2, 4, 9, 0]
Print(a)
```
ii)
```python
B = [‘Hello’, ‘Good’]
b.append(‘Data Structure’)
print(b)
```
iii)
```python
T1 = [3, 5, 6, 8]
Print(t1[2])
Print(t1[-1])
Print(t1[2:])
Print(t1[:])
```
Output:
```
[6, 8]
[3, 5, 6, 8]