Advanced Programming
Advanced Programming
1. A ______ is a collection which is ordered and unchangeable and written with round brackets.
A. Tuple
B. Set
C. Directory
D. List
2. A _____ is a collection which is unordered and unindexed and written with curly brackets
A. Tuple
B. Set
C. Directory
D. List
3. A _____ is a collection which is unordered, changeable, and indexed. They are written with curly
brackets and have keys and values.
A. Tuple
B. Set
C. Directory
D. List
4. ASCII stands for:
A. American Casual Code for Data
B. British Casual Code for Data
C. British Standard Code for Information
D. American Standard Code for Information
5. The operation to join two strings is performed with the following operator:
A. The * operator
B. The + operator
C. The / operator
D. None of the above
6. The operation to replicate a string is performed with the following operator:
A. The * operator
B. The + operator
C. The / operator
D. None of the above
7. The isalpha() method produces true output only if:
A. The string contains digits only
B. The string contains letters only
C. The string is a mix of letters and digits
D. None of the above
8. In general, there are two types of files and they are:
A. Text
B. Binary
C. A and B
D. None of the above
9. The operation of connecting the stream with a file is called:
A. Inserting the file
B. Locating the file
C. Editing the file
D. Opening the file
10. The operation disconnecting the stream from the file is called:
A. Closing the file
B. Editing the file
C. Locating the file
D. Inserting the file
11. Using a module in another code is done by the keyword:
A. Add
B. Import
C. Insert
D. Join
12. Which of the following is a key aspect of secure coding:
A. Least privilege
B. Separation of duties
C. Data encryption
D. All of the above
13. Users and components should only be granted the minimum permissions necessary to perform
their intended tasks is known as:
A. Least privilege
B. Data encryption
C. Regular security testing
D. Strong authentication and authorization
14. Benefits of secure coding includes:
A. Reduced risk of data breaches
B. Improved compliance
C. Enhanced brand reputation
D. All of the above
15. Validating input against a predefined set of allowed or disallowed values is known as:
A. Input sanitization
B. Unput length and size limit
C. Whitelisting and blacklisting
D. Data type validation
16. _______ refers to the combining of data and code into a single object
A. Encapsulation
B. Data hiding
C. Procedures
D. None of the above
17. Techniques for organizing and storing data in computer memory.
A. Algorithms
B. Data structure
C. Stack
D. Storage patterns
18. _________ are those data structures which are created using primitive data structures.
A. Primitive data structures
B. Non-primitive data structure
C. Linear data structure
D. Non-linear data structure
19. A data structure is said to be ______ if the data are not arranged in sequence or a linear.
E. Primitive data structure
F. Non-primitive data structure
G. Linear data structure
H. Non-linear data structure
20. An operation that checks if the stack is empty or not.
A. IsEmpty
B. Range
C. Size
D. Count
21. Consider the following: numbers = list(range(5)) the output will be:
A. [1,2,3,4]
B. [0,1,2,3]
C. [0,1,2,3,4]
D. [5,5,5,5]
22. What is the output of the following repetition operator: numbers = [0] * 4
A. [0,0,0,0]
B. [1,2,3,4]
C. [0,1,2,3]
D. [4,4,4,4]
23. A method that is used to reverse the order of the list.
A. Copy()
B. Insert()
C. Reverse()
D. Remove()
24. A ______ is a linear data structure that follows the First-in First-out (FIFO) principle.
A. Set
B. Queue
C. List
D. Data structure
25. ______ is a linear data structure that uses either first-in and last-out (FILO) or last-in and first-out
(LIFO).
A. Tuple
B. Dictionary
C. Stack
D. Set
26. An _______ is a step by step instructions that define a procedure to achieve a specific output.
A. Algorithm
B. Data structure
C. Stack
D. Storage patterns
2. My_list = [1,2,3,4,5]
My_list.reverse()
Print(‘Reversed order: ‘, my_list)
Reversed order: [5,4,3,2,1]
3. My_list = [9,1,0,2,8]
My_list.sort()
Print(‘Sorted order:’, my_list)
Sorted order: [0,1,2,8,9]
4. What is the difference between Enqueue and Dequeue?
Enqueue: adds an item to the end of the queue. If the queue is already full, it results
in an overflow condition.
Dequeue: removes an item from the front of the queue. If the queue is empty, it results in
an underflow condition.
Step 1 – start
Step 6 – print c
Step 7 – stop
6. Use the bubble sort algorithm to sort the following numbers: [5, 3, 4, 1, 2]
First pass:
53412
We compare 5 and 3 and swap because 5 is bigger than 3
35412
We compare 5 and 4 and swap because 5 is bigger than 4
34512
We compare 5 and 1 and swap because 5 is bigger than 1
34152
We compare 5 and 2 and swap because 5 is bigger than 2
34125
Second pass:
34125
We compare 3 and 4 but we don’t swap because 3 is smaller than 4
34125
We compare 4 and 1 and swap because 4 is bigger than 1
31425
We compare 4 and 2 and swap because 4 is bigger than 2
31245
We compare 4 and 5 but we don’t swap because 4 is smaller than 5
Third pass:
31245
We compare 3 and 1 and swap because 3 is bigger than 1
13245
We compare 3 and 2 and swap because 3 is bigger than 2
12345
7. Name briefly 3 characteristics of an algorithm?
Clear and Unambiguous
Well-Defined Inputs
Well-Defined Outputs
Finite-ness
Feasible
Language Independent
8. Name 3 advantages of an algorithm?
It is easy to understand.
Algorithm is a step-wise representation of a solution to a given problem.
In Algorithm the problem is broken down into smaller pieces or steps hence, it is
easier for the programmer to convert it into an actual program.