How can you implement a queue using an array?

  • Implement enqueue and dequeue at the middle of the array.
  • Implement enqueue at the end and dequeue at the beginning, shifting elements accordingly.
  • Use a single pointer for enqueue at the end and dequeue at the beginning.
  • Use two pointers, one for enqueue and one for dequeue, and shift elements as needed.
A common way to implement a queue using an array is to use two pointers, one for enqueue at the end and one for dequeue at the beginning. Elements are shifted as needed to accommodate new elements and maintain the order of the queue.

The best-case time complexity of Insertion Sort is _______.

  • O(1)
  • O(n log n)
  • O(n)
  • O(n^2)
The best-case time complexity of Insertion Sort is O(1). This occurs when the input array is already sorted, and the algorithm needs only to check each element once.

Radix sort is often used to sort data represented in which numeric base?

  • Binary
  • Decimal
  • Hexadecimal
  • Octal
Radix sort is often used to sort data represented in the hexadecimal numeric base. It operates by processing digits from the least significant digit to the most significant digit.

How does merge sort handle sorting of linked lists?

  • Merge sort can efficiently sort linked lists
  • Merge sort can only be used for arrays
  • Merge sort cannot be used for linked lists
  • Merge sort requires additional memory
Merge sort can efficiently handle the sorting of linked lists. Unlike array-based sorting algorithms, merge sort's divide-and-conquer approach is well-suited for linked lists as it involves splitting and merging without the need for random access to elements. This makes it a preferred choice for sorting linked structures.

Insertion Sort is a _______ sorting algorithm that builds the final sorted array one _______ at a time.

  • Comparison, element
  • Divide and conquer, subset
  • Incremental, element
  • Simple, pass
Insertion Sort is an incremental sorting algorithm that builds the final sorted array one element at a time. It iterates through the array, comparing and inserting elements in their correct positions.

Regular expression matching involves searching for patterns in _______.

  • Arrays
  • Numbers
  • Strings
  • Text
Regular expression matching involves searching for patterns in text. Regular expressions are powerful tools for pattern matching and manipulation in strings.

Explain the main idea behind Insertion Sort.

  • Builds the sorted array one element at a time
  • Divides the array into two halves and merges them
  • Selects a pivot and partitions the array
  • Sorts the array in descending order
The main idea behind Insertion Sort is to build the sorted array one element at a time. It starts with the first element and iteratively compares and inserts the current element into its correct position in the already sorted subarray. This process continues until the entire array is sorted.

In topological sorting, what property does the resulting linear ordering of vertices maintain?

  • Preservation of edge direction
  • Preservation of vertex colors
  • Preservation of vertex degrees
  • Preservation of vertex names
The resulting linear ordering of vertices in topological sorting maintains the property of preserving edge direction. It ensures that for every directed edge (u, v), vertex 'u' comes before 'v' in the ordering, representing a valid sequence of dependencies.

Bubble sort performs well when the list is _______ or nearly sorted because it requires fewer _______ to complete.

  • Presorted, comparisons
  • Randomized, swaps
  • Reversed, elements
  • Unsorted, iterations
Bubble sort performs well when the list is presorted or nearly sorted because it requires fewer comparisons to complete. In a nearly sorted list, many elements are already in their correct positions, reducing the number of swaps needed, making the algorithm more efficient in such scenarios.

A doubly linked list contains nodes that have _______ pointers.

  • Four
  • One
  • Three
  • Two
A doubly linked list contains nodes that have two pointers: one pointing to the next node in the sequence and another pointing to the previous node. This allows for easy traversal in both directions.