Coding Fundamentals and Logic Flashcards
7 cards from real Mettl practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 Coding Fundamentals and Logic flashcards as text
What is the time complexity of binary search on a sorted array of n elements?
Answer: O(log n)
Binary search halves the search space each iteration, yielding O(log n) time complexity.
Which data structure uses LIFO (Last In, First Out) ordering?
Answer: Stack
A stack follows LIFO ordering, where the last element pushed is the first to be popped.
What does the following pseudocode return for input n=5? function f(n): if n <= 1: return n return f(n-1) + f(n-2)
Answer: 8
This is the Fibonacci sequence; f(5) = f(4)+f(3) = 3+5 = 8.
Which sorting algorithm has an average-case time complexity of O(n log n)?
Answer: Merge Sort
Merge Sort consistently achieves O(n log n) average and worst-case time complexity.
In a singly linked list, what is the time complexity of accessing the kth element?
Answer: O(k)
You must traverse from the head node, taking O(k) steps to reach the kth element.
What value does x hold after this code executes? x = 10 x += 5 x *= 2 x -= 3
Answer: 27
10+5=15, 15×2=30, 30−3=27, so x=27.
Which of the following correctly describes a hash table collision?
Answer: Two keys map to the same index
A collision occurs when two distinct keys produce the same hash index.