C Programming
Time Complexity
Data Structures
100

After executing ./a.out, what message will be displayed in the terminal?

"Data read: hello, wor"


100

Searching for an element in a stack will be an operation of this time complexity.

What is O(n)?

100

A linear data structure where the first element inserted is the first element removed is known as this.

What is a queue?

200

What will be printed?

What is 8? 

var1[0] is a pointer type.

200

Searching is an operation that is typically this time complexity when using a hash table.

What is O(1)?

200

In a static data structure, the size of the structure is fixed. Why is a linked list NOT considered a static data structure?

Because a linked list can grow and shrink during the run time of a program (when code is being executed).

NOTE: Arrays are static data structures as the size or length is determined when the array is created and/or allocated.

300

The segmentation fault in the following code is due to this issue.

The memory pointed to by the "eliot" variable is used uninitialized. In other words, the memory we are pointing at isn't ours so we can't set it to 21.

300

What is the time complexity of the below code?

What is O(n^2)?

300

    a) All memory allocated in the program is on the stack.

    b) All memory allocated in the program is on the heap.

    c) Memory for 'mainStackVar' is on the stack, and memory for 'stackVar' and 'heapVar' is on the heap.

    d) Memory for 'mainStackVar' and 'stackVar' is on the stack, and memory for 'heapVar' is on the heap.

Memory for 'mainStackVar' is on the stack, and memory for 'stackVar' and 'heapVar' is on the heap.

This is because stackVar is in the scope of the call to exampleFunction(), and the only other variable declared in main is mainStackVar. 

500

What will be printed

a) Result: 1.25

b) Result: 1

c) Segmentation Fault

d) 0

0

6/12 = 0.5 but we are dealing with ints, so the decimal gets truncated.

500

What is the time complexity for an enqueue? 

This operation inserts an element at the back of the queue.

O(1), In enqueue function a single element is inserted at the last position. This takes a single memory allocation operation which is done in constant time.

500

Occurs when two or more keys hash to the same index or bucket. Hash functions are used to map keys to indices in the hash table. Ideally, each key should have a unique hash value. However, due to the finite size of the hash table and the potentially infinite keyspace, these are inevitable.

What are collisions?

800

Dynamically Allocate space for a 2d array of integers. This array should have m rows and n columns. (Assume you know m and n)

800

Heap Sort is often used in scenarios where a stable sorting order is not a requirement, and worst-case time complexity is crucial. What is it's worst, average, and best case run time complexity?

HeapSort guarantees a consistent O(n log n) time complexity, making it suitable for situations where worst-case performance is crucial

800

What is this data structure? And what will be printed?

This is an example of a dispatch table. 

7 + 3 = 10.

7 - 3 = 4.

7 * 3 = 21.

7 / 3 = 2.

M
e
n
u