Unit 1: Algorithms and Their Complexity

  1. What is the time complexity of binary search?
    a) O(n)
    b) O(log n)
    c) O(n^2)
    d) O(1)
    Answer: b) O(log n) [1]

  2. Which is the best case time complexity of linear search?
    a) O(n)
    b) O(1)
    c) O(log n)
    d) O(n^2)
    Answer: b) O(1) [1]

  3. Which notation represents average case analysis?
    a) Theta
    b) Omega
    c) Big O
    d) Little o
    Answer: a) Theta [1]

  4. What is the time complexity for finding an element in a balanced BST?
    a) O(n)
    b) O(log n)
    c) O(n^2)
    d) O(1)
    Answer: b) O(log n) [1]

  5. The recurrence relation for the optimal time of the Tower of Hanoi problem is
    a) T(n) = 2T(n-1) + 1
    b) T(n) = T(n-1) + 2
    c) T(n) = 2T(n-2) + 2
    d) T(n) = T(n-1) + 1
    Answer: a) T(n) = 2T(n-1) + 1 [1]

  6. Which sorting algorithm works best on nearly sorted arrays?
    a) Heap sort
    b) Insertion sort
    c) Bubble sort
    d) Selection sort
    Answer: b) Insertion sort [1]

  7. What is the best time complexity for comparison-based sorting?
    a) O(n log n)
    b) O(n)
    c) O(n^2)
    d) O(log n)
    Answer: a) O(n log n) [1]

  8. Which algorithm is optimal for finding the shortest path in a graph with negative weights?
    a) Dijkstra
    b) Bellman-Ford
    c) Kruskal
    d) Prim
    Answer: b) Bellman-Ford [1]

  9. Which notation describes the upper bound of an algorithm?
    a) Omega
    b) Theta
    c) Big O
    d) Little o
    Answer: c) Big O [1]

  10. What is the space complexity of an adjacency matrix for a graph with n vertices?
    a) O(n)
    b) O(n^2)
    c) O(log n)
    d) O(1)
    Answer: b) O(n^2) [1]

  11. Which of the following sorts is NOT stable?
    a) Bubble sort
    b) Merge sort
    c) Quick sort
    d) Insertion sort
    Answer: c) Quick sort [1]

  12. An algorithm with time complexity O(n^3) will run how many times faster if n triples?
    a) 9
    b) 27
    c) 3
    d) 18
    Answer: b) 27 [1]

  13. For a fixed small input, which case is most meaningful?
    a) Best-case
    b) Worst-case
    c) Average-case
    d) None
    Answer: a) Best-case [1]

  14. Which is the correct increasing order of complexity?
    a) O(1), O(n), O(n log n), O(n^2)
    b) O(1), O(n log n), O(n), O(n^2)
    c) O(n^2), O(n), O(1), O(n log n)
    d) O(1), O(n^2), O(n log n), O(n)
    Answer: a) O(1), O(n), O(n log n), O(n^2) [1]

  15. The worst-case complexity of merge sort is
    a) O(n log n)
    b) O(n)
    c) O(n^2)
    d) O(log n)
    Answer: a) O(n log n) [1]

  16. What is the time complexity of selection sort?
    a) O(n log n)
    b) O(n^2)
    c) O(n)
    d) O(log n)
    Answer: b) O(n^2) [1]

  17. Efficiency of an algorithm mainly depends on
    a) Processor
    b) Language used
    c) Input size
    d) None
    Answer: c) Input size [1]

  18. The space complexity of recursion is
    a) O(n)
    b) O(1)
    c) O(n log n)
    d) O(n^2)
    Answer: a) O(n) [1]

  19. Which measure gives an exact count of instructions?
    a) High-level code
    b) Assembly
    c) Machine code
    d) Algorithmic complexity
    Answer: c) Machine code [1]

  20. Best-case for quicksort occurs when
    a) Array is completely sorted
    b) Pivot divides array in equal halves
    c) Pivot is lowest element
    d) All elements are same
    Answer: b) Pivot divides array in equal halves [1]

  21. What type of analysis is relevant for real-time systems?
    a) Best-case
    b) Average-case
    c) Worst-case
    d) Expected-case
    Answer: c) Worst-case [1]

  22. The lower bound of comparison sorts is
    a) O(n)
    b) O(log n)
    c) O(n^2)
    d) O(n log n)
    Answer: d) O(n log n) [1]

  23. Radix sort complexity is
    a) O(n^2)
    b) O(n log n)
    c) O(nk)
    d) O(log n)
    Answer: c) O(nk) [1]

  24. When is an algorithm called optimal?
    a) Uses minimum memory
    b) Gives only best-case time
    c) Uses minimum time for all cases
    d) None
    Answer: c) Uses minimum time for all cases [1]

  25. For a list of size n, what is the worst-case time of inserting in a sorted array?
    a) O(1)
    b) O(n)
    c) O(log n)
    d) O(n^2)
    Answer: b) O(n) [1]

  26. Which curves represent exponential growth?
    a) Logarithmic
    b) Linear
    c) Polynomial
    d) 2^n
    Answer: d) 2^n [1]

  27. Which of the following is not a divide-and-conquer algorithm?
    a) Merge Sort
    b) Quick Sort
    c) Heap Sort
    d) Binary Search
    Answer: c) Heap Sort [1]

  28. Time complexity of traversing a matrix row-wise is
    a) O(n^2)
    b) O(n)
    c) O(log n)
    d) O(n log n)
    Answer: a) O(n^2) [1]

  29. Counting sort is efficient when
    a) Data is small range
    b) Data is very large
    c) Data is random
    d) Data is unique
    Answer: a) Data is small range [1]

  30. Prim’s algorithm is used for
    a) Shortest path
    b) Sorting
    c) Minimum spanning tree
    d) Maximum flow
    Answer: c) Minimum spanning tree [1]


Unit 2: Programming with C and Data Structures

  1. Which of the following is a valid C variable name?
    a) 2var
    b) var_name
    c) var-name
    d) var name
    Answer: b) var_name [2]

  2. What does the “*” operator signify in C?
    a) Addition
    b) Multiplication
    c) Pointer dereferencing
    d) Address-of
    Answer: c) Pointer dereferencing [2]

  3. Which header file is needed for printf()?
    a) stdio.h
    b) conio.h
    c) string.h
    d) math.h
    Answer: a) stdio.h [2]

  4. What is the value in array[1] if int array[3] = {1,2,3,4,5};
    a) 1
    b) 2
    c) 3
    d) 4
    Answer: c) 3 [2]

  5. Which is NOT a primitive data type in C?
    a) int
    b) float
    c) double
    d) array
    Answer: d) array [2]

  6. Which is used to implement recursion?
    a) Queue
    b) Stack
    c) Array
    d) List
    Answer: b) Stack [2]

  7. Which is not an application of stack?
    a) Parentheses checking
    b) Recursion
    c) Level order traversal
    d) Expression evaluation
    Answer: c) Level order traversal [2]

  8. What is returned by main() if nothing is specified in C?
    a) 1
    b) 0
    c) null
    d) undefined
    Answer: b) 0 [2]

  9. What is the value of strlen(“abc”)?
    a) 2
    b) 3
    c) 4
    d) 0
    Answer: b) 3 [2]

  10. Linked lists allow
    a) Random access
    b) Fast insert/delete
    c) Slow insert/delete
    d) None
    Answer: b) Fast insert/delete [2]

  11. Which data structure follows FIFO?
    a) Stack
    b) Queue
    c) Tree
    d) Graph
    Answer: b) Queue [2]

  12. Which is required to check balanced parentheses?
    a) Queue
    b) Stack
    c) Tree
    d) Array
    Answer: b) Stack [2]

  13. Which traversal lists all nodes in a binary tree in left, root, right order?
    a) Inorder
    b) Preorder
    c) Postorder
    d) Level order
    Answer: a) Inorder [2]

  14. The postfix form of (A+B)C is
    a) AB+C

    b) ABC*+
    c) A+BC*
    d) None
    Answer: a) AB+C* [2]

  15. What is the output of push and pop when reversing a string?
    a) Same order
    b) Reversed order
    c) Random order
    d) Alternating
    Answer: b) Reversed order [2]

  16. Which data structure is non-linear?
    a) Stack
    b) Queue
    c) Tree
    d) Array
    Answer: c) Tree [2]

  17. Which is not a type of queue?
    a) Priority queue
    b) Circular queue
    c) Simple queue
    d) Inside queue
    Answer: d) Inside queue [2]

  18. What is the infix form of AB+?
    a) A+B
    b) AB+
    c) +AB
    d) None
    Answer: a) A+B [2]

  19. The data structure required for BFS is
    a) Stack
    b) Queue
    c) Array
    d) Tree
    Answer: b) Queue [2]

  20. Which is true about arrays?
    a) Fixed size
    b) Dynamic size
    c) Elements in random locations
    d) All of the above
    Answer: a) Fixed size [2]

  21. Insertion in a linked list requires
    a) Copying all elements
    b) O(1) time for known position
    c) O(n^2) time
    d) None
    Answer: b) O(1) time for known position [2]

  22. Which NOT true about linked list?
    a) Random access
    b) Dynamic size
    c) Pointers required
    d) Insertion easy
    Answer: a) Random access [2]

  23. What is a bit array?
    a) Array for storing bits compactly
    b) String
    c) Tree
    d) Array with random elements
    Answer: a) Array for storing bits compactly [2]

  24. Balanced trees provide
    a) Faster searches
    b) Slower searches
    c) Unchanged search time
    d) None
    Answer: a) Faster searches [2]

  25. In AVL trees, the balance factor is
    a) 0, 1, -1
    b) 2, 0, -2
    c) 1, -1
    d) 0, 2
    Answer: a) 0, 1, -1 [2]

  26. Which header for dynamic memory allocation in C?
    a) stdlib.h
    b) math.h
    c) conio.h
    d) string.h
    Answer: a) stdlib.h [2]

  27. The degree of a node is
    a) Number of children
    b) Value
    c) Level
    d) Parent node
    Answer: a) Number of children [2]

  28. Which traversal order prints root before left and right in a binary tree?
    a) Preorder
    b) Inorder
    c) Postorder
    d) None
    Answer: a) Preorder [2]

  29. The optimal data structure for reversing a word is
    a) Stack
    b) Queue
    c) Tree
    d) Array
    Answer: a) Stack [2]

  30. What is the time complexity for searching an element in a hash table?
    a) O(1)
    b) O(n)
    c) O(log n)
    d) O(n^2)
    Answer: a) O(1) [2]


Unit 3: Object Oriented Programming Concepts and SQL

  1. What is data hiding in OOP called?
    a) Abstraction
    b) Encapsulation
    c) Inheritance
    d) Polymorphism
    Answer: b) Encapsulation [4]

  2. The process by which one object acquires properties of another is
    a) Inheritance
    b) Polymorphism
    c) Abstraction
    d) Encapsulation
    Answer: a) Inheritance [4]

  3. OOP concept that allows the same function name to be defined differently is
    a) Overriding
    b) Inheritance
    c) Overloading
    d) Encapsulation
    Answer: c) Overloading [4]

  4. Hiding complexity and showing only essentials is
    a) Encapsulation
    b) Inheritance
    c) Abstraction
    d) Polymorphism
    Answer: c) Abstraction [4]

  5. Which is not an OOP concept?
    a) Compilation
    b) Inheritance
    c) Polymorphism
    d) Abstraction
    Answer: a) Compilation [4]

  6. The main component of a class is
    a) Methods
    b) Objects
    c) Both
    d) None
    Answer: c) Both [4]

  7. Which of the following is NOT possible in OOP?
    a) Multiple inheritance
    b) Overloading
    c) Data hiding
    d) Direct variable access
    Answer: d) Direct variable access [4]

  8. Binding at compile-time is
    a) Early binding
    b) Late binding
    c) Dynamic binding
    d) None
    Answer: a) Early binding [4]

  9. In OOP, an object is
    a) Class definition
    b) Instance of a class
    c) Variable
    d) Method
    Answer: b) Instance of a class [4]

  10. Which feature describes function name same in base and derived class?
    a) Overloading
    b) Overriding
    c) Abstraction
    d) Encapsulation
    Answer: b) Overriding [4]

  11. Which of the following is an example of polymorphism?
    a) Function overloading
    b) Data hiding
    c) Encapsulation
    d) Class definition
    Answer: a) Function overloading [4]

  12. The base class from which all classes are derived in OOP is
    a) Parent class
    b) Super class
    c) Object
    d) Derived class
    Answer: c) Object [4]

  13. To create a database in SQL:
    a) MAKE DATABASE
    b) CREATE DATABASE
    c) BUILD DATABASE
    d) ADD DATABASE
    Answer: b) CREATE DATABASE [5]

  14. Which SQL clause is used to filter records?
    a) WHERE
    b) ORDER BY
    c) GROUP BY
    d) HAVING
    Answer: a) WHERE [5]

  15. What is the command to delete a table in SQL?
    a) REMOVE TABLE
    b) DELETE TABLE
    c) DROP TABLE
    d) CLEAR TABLE
    Answer: c) DROP TABLE [5]

  16. Which SQL keyword sorts the result-set?
    a) GROUP BY
    b) SORT
    c) ORDER BY
    d) SEQUENCE
    Answer: c) ORDER BY [5]

  17. How do you select all the columns from a table?
    a) SELECT * FROM table;
    b) SELECT ALL FROM table;
    c) GET * FROM table;
    d) SHOW ALL table;
    Answer: a) SELECT * FROM table; [5]

  18. Which SQL function returns the number of records?
    a) TOTAL()
    b) NUM()
    c) COUNT()
    d) NUMBER()
    Answer: c) COUNT() [5]

  19. The SQL command to remove all records in a table but not structure is
    a) ERASE
    b) DELETE
    c) DROP
    d) TRUNCATE
    Answer: d) TRUNCATE [5]

  20. Which command modifies data in SQL?
    a) ALTER
    b) UPDATE
    c) SELECT
    d) CREATE
    Answer: b) UPDATE [5]

  21. Which command adds new record to a table?
    a) ADD
    b) INSERT
    c) CREATE
    d) NEW
    Answer: b) INSERT [5]

  22. The default ordering in ORDER BY is
    a) Ascending
    b) Descending
    c) Random
    d) None
    Answer: a) Ascending [5]

  23. Which command retrieves unique values in SQL?
    a) DISTINCT
    b) ONLY
    c) UNIQUE
    d) SINGLE
    Answer: a) DISTINCT [5]

  24. What is the result of a SELECT statement with no WHERE?
    a) No records
    b) Some records
    c) All records
    d) Error
    Answer: c) All records [5]

  25. Which clause groups records in SQL?
    a) GROUP BY
    b) ORDER BY
    c) WHERE
    d) HAVING
    Answer: a) GROUP BY [5]

  26. SQL is
    a) High-level language
    b) Procedural language
    c) Non-procedural language
    d) Assembly language
    Answer: c) Non-procedural language [5]

  27. Which operator checks for NULL?
    a) = NULL
    b) IS NULL
    c) == NULL
    d) EQUALS NULL
    Answer: b) IS NULL [5]

  28. JOINs in SQL are used to
    a) Find duplicates
    b) Combine tables
    c) Remove tables
    d) None
    Answer: b) Combine tables [5]

  29. What is SQL?
    a) Simple Query Language
    b) Structured Query Language
    c) Sorted Query Language
    d) None
    Answer: b) Structured Query Language [5]

  30. Which command removes duplicate rows in the result of a SELECT query?
    a) UNIQUE
    b) DISTINCT
    c) ONLY
    d) FIND
    Answer: b) DISTINCT [5]