Programming (Topic 6 and Topic 7) Flashcards

All Searching Types, Coding etc. (21 cards)

1
Q

What is Binary Search?

A

A search algorithm for sorted lists that divides the list into halves to find a target.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does Binary Search work?

A
  1. Compare the middle element to the target.
  2. Search left or right based on the target.
  3. Repeat.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is Linear Search?

A

A search algorithm that checks each element one by one until the target is found or list ends.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When is Linear Search useful?

A

For small or unsorted lists.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does Bubble Sort work?

A
  1. Compare two adjacent items.
  2. Swap if wrong order.
  3. Repeat for the whole list.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the main disadvantage of Bubble Sort?

A

It is slow for large lists because it repeatedly checks all elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does Insertion Sort work?

A
  1. Start with one item as “sorted.”
  2. Insert the next item into its correct position.
  3. Repeat.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does Merge Sort work?

A
  1. Divide the list into smaller sublists.
  2. Merge the sublists back in sorted order.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a While Loop?

A

A loop that runs as long as a condition is true.
Example: while x < 5: print(x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a For Loop?

A

A loop that iterates over a sequence (list or range).
Example: for i in range(5): print(i)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an If Statement?

A

A decision-making construct that runs code based on a condition.
Example: if x > 0: print(“Positive”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is an Array?

A

A collection of items stored in a single variable (lists in Python).
Example: numbers = [1, 2, 3]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a Function?

A

A reusable block of code designed for a specific task.
Example: def greet(name): return f”Hello, {name}!”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a Subroutine?

A

Another term for a function or method used for specific tasks in a program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are Parameters in Functions?

A

Variables in the function header to take inputs.
Example: def add(x, y): return x + y

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is Basic File Handling?

A

Operations to read from and write to files in Python. Modes: “r” (read), “w” (write), “a” (append).

17
Q

How do you write to a file in Python?

A

with open(“file.txt”, “w”) as file: file.write(“Hello, world!”)

18
Q

How do you read a file in Python?

A

with open(“file.txt”, “r”) as file: content = file.read()

19
Q

What is SQL?

A

Structured Query Language, used to manage and query databases.

20
Q

What are common SQL commands?

A

SELECT (retrieve), INSERT (add), UPDATE (modify), DELETE (remove).

21
Q

How do you connect Python to a database?

A

Use sqlite3 for simple databases:
import sqlite3; conn = sqlite3.connect(“example.db”)