Govt. Exams
Entrance Exams
Contiguous allocation places array elements next to each other in memory, improving cache hits and CPU performance through spatial locality.
Level-order traversal requires BFS which uses a queue. Dynamic queue allocation handles arbitrary tree sizes efficiently.
Each malloc() call has fixed metadata overhead (typically 8-16 bytes). Single allocation of 1000 ints has less overhead than 1000 separate allocations.
While both work, inserting at beginning provides O(1) insertion; end requires traversal. Choice depends on use case.
Checking if malloc returns NULL before using the pointer is essential error handling. If allocation fails, the program should handle it gracefully rather than proceeding with NULL.
Doubling capacity and using realloc() provides amortized O(1) insertion with manageable memory overhead, which is the standard approach for dynamic data structures.
Single allocation with index tracking minimizes malloc/free overhead, suitable for competitive programming time constraints.
"Hello World" is 11 bytes (including null terminator). Writing to 10-byte buffer causes buffer overflow, corrupting adjacent memory.
Large allocations may fail due to heap fragmentation or insufficient contiguous memory. Always check malloc() return for NULL.
Without freeing, allocated memory accumulates until system runs out of heap space, causing allocation failure or crash.