0% found this document useful (0 votes)
2 views4 pages

Class Notes Cs

The document contains class notes covering fundamental programming concepts including characters, arrays, identifiers, and logic circuits. It also provides examples of algorithms such as binary search, finding the maximum in a list, summing an array, linear search, and reversing a list, along with corresponding Python code snippets. Key definitions and rules for identifiers and indexing in Python are also included.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Class Notes Cs

The document contains class notes covering fundamental programming concepts including characters, arrays, identifiers, and logic circuits. It also provides examples of algorithms such as binary search, finding the maximum in a list, summing an array, linear search, and reversing a list, along with corresponding Python code snippets. Key definitions and rules for identifiers and indexing in Python are also included.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Class Notes

1. Character
 A character is a single symbol such as a letter (A, b), digit (0–9), or
special symbol (#, @, !).
 In Python, characters are represented as strings of length 1. Example:
'A', '5',

2. Array
 An array is a data structure that stores multiple values of the same
type in a single variable.
 In Python, we often use lists to represent arrays.
 Example: marks = [45, 67, 89, 90]

3. 1-Dimension (1-D Array)


 A 1-dimensional array is a simple list of elements arranged'$'. in a
single row.
 Example: names = ["Ali", "Ravi", "Meena"]
 Accessing elements: names[0] → "Ali"

4. Identifier
 An identifier is the name used to identify a variable, function, class, or
object in a program.
 Rules:
o Must begin with a letter or underscore.
o Cannot start with a digit.
o Cannot use keywords (e.g., if, while).
 Example: student_name, marks1

5. Index
 An index refers to the position of an element in an array or string.
 In Python, indexing starts from 0.
 Example: numbers = [10, 20, 30] → numbers[1] = 20
6. Indices
 Indices is the plural of index.
 It refers to multiple positions in a list or array.
 Example: fruits = ["Apple", "Banana", "Mango"]
o Indices → 0, 1, 2

7. Logic Circuit
 A logic circuit is a circuit that performs logical operations using logic
gates.
 Logic gates: AND, OR, NOT, NAND, NOR, XOR.
 Used in computers to perform decision-making and arithmetic
operations.

8. Analogue / Digital / Digitised


 Analogue: Continuous signals (e.g., sound waves, thermometer).
 Digital: Discrete signals (0s and 1s).
 Digitised: Conversion of analogue signals into digital form (e.g.,
recording voice into MP3).

9. Binary Search
 A binary search is an efficient algorithm to find an element in a
sorted list.
 Process:
1. Find the middle element.
2. If the target is equal to the middle → found.
3. If the target < middle → search left half.
4. If the target > middle → search right half.
 Time Complexity: O(log n).
Python Example:
def binary_search(arr, target):
low, high = 0, len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1

nums = [10, 20, 30, 40, 50]


print(binary_search(nums, 30)) # Output: 2

1. Algorithm Example (Find Maximum in List)


1. Start
2. Input list of numbers
3. Set max = first number
4. For each number in list:
o If number > max → update max
5. Print max
6. Stop
Python Program:
nums = [12, 45, 67, 23, 89, 34]
maximum = nums[0]
for n in nums:
if n > maximum:
maximum = n
print("Maximum:", maximum)

2. Algorithm Example (Sum of Array)


1. Start
2. Input array elements
3. Initialize sum = 0
4. For each element, add to sum
5. Print sum
6. Stop
Python Program:
arr = [5, 10, 15, 20]
total = 0
for x in arr:
total += x
print("Sum:", total)

3. Algorithm Example (Binary Search)


(Already explained above)

4. Algorithm Example (Linear Search)


1. Start
2. Input list and target element
3. Compare each element with target
4. If found → return index
5. Else → return not found
6. Stop
Python Program:
nums = [5, 15, 25, 35, 45]
target = 25
found = -1
for i in range(len(nums)):
if nums[i] == target:
found = i
break

if found != -1:
print("Found at index", found)
else:
print("Not found")

5. Algorithm Example (Reverse a List)


Python Program:
arr = [1, 2, 3, 4, 5]
print("Original:", arr)
print("Reversed:", arr[::-1])

You might also like