Data Structures Fundamentals: 329 MCQs with answers

Showing 200 of 329 multiple-choice questions from this kit.

Warm-up · 111 questions

Q1. When is memory allocated for a static data structure?

Beginner
A When the first element is accessed B At runtime C At compile time D When the program is loaded
Show answer & explanation

At compile time

Static data structures allocate memory at compile time, meaning the size is fixed before the program runs.

Q2. Which of the following is an example of a dynamic data structure?

Beginner
A Static stack B Static queue C Array D Linked list
Show answer & explanation

Linked list

A linked list is dynamic because nodes are created at runtime and can be added or removed.

Q3. What is the main advantage of static data structures?

Beginner
A Can handle variable input sizes B Faster access due to contiguous memory C Flexible size D No memory wastage
Show answer & explanation

Faster access due to contiguous memory

Static structures use contiguous memory, enabling direct indexing and faster access.

Q4. What does 'static' refer to in a static data structure?

Beginner
A The values cannot be changed B The structure cannot be used in functions C The size is fixed D The memory is allocated at runtime
Show answer & explanation

The size is fixed

Static refers to the fixed size, not immutability of values. You can modify elements but not the number of elements.

Q5. Which of the following is a drawback of dynamic data structures?

Beginner
A They waste memory if not fully used B They cannot grow in size C They are slower to access due to pointer traversal D They are simpler to implement
Show answer & explanation

They are slower to access due to pointer traversal

Dynamic structures often use non-contiguous memory, so accessing elements requires following pointers, which is slower.

Q6. In C, which function is used to deallocate dynamic memory?

Beginner
A realloc() B calloc() C free() D malloc()
Show answer & explanation

free()

free() is used to release memory that was previously allocated with malloc() or calloc().

Q7. Which scenario is best suited for a static data structure?

Beginner
A Storing the 12 months of a year B Storing an unknown number of student records C Storing a list of all users in a social media app D Storing a dynamic feed of posts
Show answer & explanation

Storing the 12 months of a year

When the data size is known and fixed, like 12 months, a static array is efficient and simple.

Q8. What is a memory leak?

Beginner
A Memory that is allocated but never freed B Memory that is not contiguous C Memory that is freed too early D Memory that is allocated at compile time
Show answer & explanation

Memory that is allocated but never freed

A memory leak occurs when dynamically allocated memory is not freed, gradually exhausting available memory.

Q9. Which of the following is true about dynamic arrays (e.g., using realloc)?

Beginner
A They cannot change size at runtime B They can be contiguous while still being dynamic in size C They are always non-contiguous D They are slower than linked lists for traversal
Show answer & explanation

They can be contiguous while still being dynamic in size

Dynamic arrays use contiguous memory but can resize at runtime using realloc, so they combine contiguity with flexibility.

Q10. Why do most real-world applications prefer dynamic structures?

Beginner
A They are always faster B They can handle variable and large data sizes C They do not require memory management D They are simpler to implement
Show answer & explanation

They can handle variable and large data sizes

Real-world data sizes are often unpredictable, so dynamic structures provide the scalability and flexibility needed.

Q11. Static data structures can have their values changed, but their size is fixed.

Beginner
A True B False
Show answer & explanation

True

Static refers to the fixed size, not immutability. You can modify elements in a static array.

Q12. Dynamic data structures always use non-contiguous memory.

Beginner
A True B False
Show answer & explanation

False

While linked lists are non-contiguous, dynamic arrays can use contiguous memory while still being dynamic in size.

Q13. What is the fundamental difference between static and dynamic data structures?

Beginner
Show answer & explanation

—

This is the core distinction based on memory allocation time and size flexibility.

Q14. Name two examples of static data structures.

Beginner
Show answer & explanation

—

These have fixed sizes determined at compile time.

Q15. Name two examples of dynamic data structures.

Beginner
Show answer & explanation

—

These can grow or shrink at runtime by allocating and deallocating nodes.

Q16. Why is access faster in static data structures?

Beginner
Show answer & explanation

—

Contiguous memory enables O(1) access to any element by index.

Q17. What is a major drawback of dynamic data structures?

Beginner
Show answer & explanation

—

Manual memory management adds complexity and risk.

Q18. In C, which functions are used to allocate dynamic memory?

Beginner
Show answer & explanation

—

These are standard library functions for runtime memory allocation.

Q19. What is the real-life analogy for a static data structure?

Beginner
Show answer & explanation

—

This illustrates the fixed-size nature and potential wastage.

Q20. How does a linked list store its elements?

Beginner
Show answer & explanation

—

Nodes are scattered in RAM and connected via pointers.

Q21. Which of the following is a data item?

Beginner
A 42 B Student record C A group of coordinates D A file of records
Show answer & explanation

42

A data item is a single unit of value, like 42. Student record, file, and group are collections.

Q22. What is a group item?

Beginner
A A physical memory layout B A single raw value C A collection of related data items D A collection of records
Show answer & explanation

A collection of related data items

A group item is a collection of related data items, like a point (x, y). A file is a collection of records, not a group item.

Q23. In a student record, 'Name' is an example of a:

Beginner
A Data structure B Record C File D Field
Show answer & explanation

Field

A field is a single attribute of a record. 'Name' is one attribute, so it's a field.

Q24. Which of the following best describes a data structure?

Beginner
A The physical memory layout B A single data item C A collection of records D A logical model for organizing data
Show answer & explanation

A logical model for organizing data

A data structure is a logical model for organizing data for efficient access and modification. Storage structure is the physical layout.

Q25. What is the storage structure of an array?

Beginner
A Scattered memory with pointers B Dynamic nodes C Contiguous memory D A logical model
Show answer & explanation

Contiguous memory

An array uses contiguous memory locations, while a linked list uses scattered memory with pointers.

Q26. Which operation is NOT typically performed on a data structure?

Beginner
A Search B Compile C Delete D Insert
Show answer & explanation

Compile

Compile is a programming language operation, not a data structure operation. Insert, delete, search, and traverse are common operations.

Q27. In the C code `struct Student { int roll; char name[20]; float marks; };`, what does `struct Student` represent?

Beginner
A A file B A field C A record D A data item
Show answer & explanation

A record

The struct defines a record with fields. An array of such structs would be a file.

Q28. Which of the following is an example of a file?

Beginner
A A roll number B A student's name C An array of student records D A single student record
Show answer & explanation

An array of student records

A file is a collection of related records. An array of student records is a file.

Q29. Why might a linked list be preferred over an array for frequent insertions?

Beginner
A Linked lists have faster random access B Insertion only requires updating pointers C Linked lists use contiguous memory D Arrays cannot store records
Show answer & explanation

Insertion only requires updating pointers

In a linked list, insertion only requires updating pointers, avoiding the need to shift elements as in an array. This makes insertion faster.

Q30. What is the relationship between a data structure and a storage structure?

Beginner
A The data structure is abstract; the storage structure is concrete B They are the same thing C They are unrelated D The storage structure is abstract; the data structure is concrete
Show answer & explanation

The data structure is abstract; the storage structure is concrete

A data structure is a logical model (abstract), while a storage structure is the physical implementation (concrete).

Q31. Which of the following correctly orders the hierarchy from smallest to largest?

Beginner
A Group item -> Data item -> Record -> File B Data item -> Group item -> Record -> File C File -> Record -> Group item -> Data item D Record -> File -> Data item -> Group item
Show answer & explanation

Data item -> Group item -> Record -> File

The hierarchy is data item (smallest) -> group item -> record -> file (largest).

Q32. A data structure and its storage structure are always identical.

Beginner
A True B False
Show answer & explanation

False

A data structure is a logical model, while a storage structure is the physical implementation. They are distinct concepts.

Q33. A record is a collection of fields, and a file is a collection of records.

Beginner
A True B False
Show answer & explanation

True

This is the standard definition: a record is a complete collection of fields, and a file is a collection of related records.

Q34. Define 'data' and give an example.

Beginner
Show answer & explanation

—

Data is the general term for raw values.

Q35. What is a data item? Provide an example.

Beginner
Show answer & explanation

—

A data item is a specific single value.

Q36. Explain the concept of a group item with an example.

Beginner
Show answer & explanation

—

Group items combine related data items.

Q37. What is a field? Give an example.

Beginner
Show answer & explanation

—

Fields are the individual attributes.

Q38. What is a record? Provide an example.

Beginner
Show answer & explanation

—

A record represents one entity with all its attributes.

Q39. What is a file in the context of data structures?

Beginner
Show answer & explanation

—

Files group related records together.

Q40. Define data structure.

Beginner
Show answer & explanation

—

It's the abstract organization of data.

Q41. Define storage structure.

Beginner
Show answer & explanation

—

It's the physical implementation in memory.

Q42. List four common operations on data structures.

Beginner
Show answer & explanation

—

These are the basic operations.

Q43. Which of the following best defines a data structure?

Beginner
A A programming language feature for loops B A hardware component for data storage C A type of algorithm for sorting numbers D A specialized format for organizing, storing, and managing data
Show answer & explanation

A specialized format for organizing, storing, and managing data

A data structure is a specialized format for organizing, storing, and managing data efficiently. It is not a language feature, algorithm, or hardware.

Q44. Which of the following is NOT a common operation on a data structure?

Beginner
A Search B Delete C Insert D Compile
Show answer & explanation

Compile

Common operations include insert, delete, search, traverse, and sort. Compiling is a process of translating code, not an operation on data structures.

Q45. How does an array store its elements in memory?

Beginner
A In contiguous memory locations B In a hierarchical tree structure C In scattered memory locations with pointers D In a random order determined by the OS
Show answer & explanation

In contiguous memory locations

Arrays store elements in contiguous memory locations, meaning elements are placed next to each other. This allows direct access by index.

Q46. Which data structure uses pointers to link elements stored in scattered memory?

Beginner
A Array B Linked list C Stack D Queue
Show answer & explanation

Linked list

A linked list stores elements in scattered memory locations, with each element containing a pointer to the next element. Arrays use contiguous memory.

Q47. What is the main advantage of using a data structure over separate variables?

Beginner
A It makes programs run faster without any trade-offs B It brings efficiency, clarity, and organization to programs C It uses less memory in all cases D It eliminates the need for algorithms
Show answer & explanation

It brings efficiency, clarity, and organization to programs

Data structures organize data so that operations become efficient and code becomes clear and maintainable. They do not always use less memory and still require algorithms.

Q48. Which access method allows direct retrieval of an element using its index?

Beginner
A Direct B Random C Recursive D Sequential
Show answer & explanation

Direct

Direct access uses an index to retrieve an element immediately, as in arrays. Sequential access requires traversing elements one by one.

Q49. What is the relationship between data structures and algorithms?

Beginner
A Algorithms are a type of data structure B Data structures organize data; algorithms manipulate data C They are the same concept D Data structures are only used in algorithms for sorting
Show answer & explanation

Data structures organize data; algorithms manipulate data

Data structures define how data is organized, while algorithms are step-by-step procedures to process that data. They work together.

Q50. Which of the following is a real-world application of a stack?

Beginner
A Undo feature in a text editor B Finding the shortest path in a map C Indexing records in a database D Storing contact names in a phone
Show answer & explanation

Undo feature in a text editor

Stacks are used for undo features because they follow Last-In-First-Out (LIFO) order, allowing the most recent action to be undone first.

Q51. What is the main trade-off between arrays and linked lists?

Beginner
A Arrays allow fast access by index but slow insert/delete; linked lists allow fast insert/delete but slow access by index B Arrays allow fast insert/delete but slow access; linked lists allow fast access but slow insert/delete C Arrays use more memory than linked lists D Linked lists use contiguous memory, making access faster
Show answer & explanation

Arrays allow fast access by index but slow insert/delete; linked lists allow fast insert/delete but slow access by index

Arrays provide O(1) access by index but require shifting elements for insert/delete. Linked lists allow O(1) insert/delete at known positions but require traversal for access.

Q52. Why is choosing the right data structure important?

Beginner
A It makes the code shorter regardless of the task B It determines the programming language to use C It balances memory usage and performance for the required operations D It guarantees the program will have no bugs
Show answer & explanation

It balances memory usage and performance for the required operations

Different data structures have different strengths and weaknesses. Choosing the right one optimizes memory usage and performance for the specific operations needed.

Q53. Which data structure is best suited for implementing a navigation app that finds the shortest route?

Beginner
A Queue B Graph C Array D Stack
Show answer & explanation

Graph

Graphs represent roads and intersections, and algorithms like Dijkstra's work on graphs to find the shortest path.

Q54. What is a key characteristic of a data structure's formal definition?

Beginner
A It only describes the data values, not the operations B It defines how data is grouped, what operations are allowed, and how data is stored in memory C It determines the algorithm's time complexity D It specifies the programming language used
Show answer & explanation

It defines how data is grouped, what operations are allowed, and how data is stored in memory

A data structure is a logical and mathematical model that defines grouping, operations, storage representation, and efficiency impact.

Q55. A linked list stores elements in contiguous memory locations.

Beginner
A True B False
Show answer & explanation

False

A linked list stores elements in scattered memory locations with pointers linking them, not contiguous memory.

Q56. Data structures and algorithms are the same concept.

Beginner
A True B False
Show answer & explanation

False

Data structures organize data, while algorithms are step-by-step procedures to manipulate data. They are distinct but complementary.

Q57. Define a data structure in your own words.

Beginner
Show answer & explanation

—

Full marks require mentioning organization, storage, and efficiency.

Q58. List the four key components of a data structure.

Beginner
Show answer & explanation

—

Each component is essential: data values, how they are stored, what operations can be performed, and how they are accessed.

Q59. Name five common operations that can be performed on a data structure.

Beginner
Show answer & explanation

—

These are the fundamental operations that data structures support.

Q60. What are the three access methods for data structures?

Beginner
Show answer & explanation

—

Direct access uses an index, sequential access uses a loop, and recursive access uses recursion.

Q61. What are the benefits of using data structures in programming?

Beginner
Show answer & explanation

—

List the three main benefits.

Q62. How does an array allow direct access to its elements?

Beginner
Show answer & explanation

—

Mention contiguous memory and index calculation.

Q63. Which of the following is a linear data structure?

Beginner
A Queue B Graph C Tree D Trie
Show answer & explanation

Queue

Queue is a linear structure that follows FIFO. Trees, graphs, and tries are non-linear.

Q64. Which data structure uses LIFO (Last In, First Out) principle?

Beginner
A Stack B Queue C Array D Linked List
Show answer & explanation

Stack

Stack follows LIFO; the last element added is the first to be removed.

Q65. In a linear data structure, each element (except the first and last) has:

Beginner
A At least two successors B No predecessor or successor C Multiple predecessors and successors D Exactly one predecessor and one successor
Show answer & explanation

Exactly one predecessor and one successor

Linear structures have a one-to-one relationship: each element has exactly one predecessor and one successor, except the ends.

Q66. Which of the following is a non-linear data structure?

Beginner
A Stack B Array C Graph D Queue
Show answer & explanation

Graph

Graph is non-linear because elements can have many-to-many relationships.

Q67. What is the primary characteristic of a non-linear data structure?

Beginner
A Elements are arranged hierarchically or as a graph B Elements are arranged sequentially C Elements have only one predecessor D Elements are stored in contiguous memory
Show answer & explanation

Elements are arranged hierarchically or as a graph

Non-linear structures arrange elements hierarchically (tree) or as a network (graph), allowing multiple connections.

Q68. Which real-world scenario best represents a queue data structure?

Beginner
A A family tree B Undo operations in a text editor C People waiting in a line D A road map
Show answer & explanation

People waiting in a line

A queue follows FIFO, like people waiting in a line: the first person in line is served first.

Q69. Which data structure is best suited for modeling a social media network?

Beginner
A Graph B Stack C Queue D Array
Show answer & explanation

Graph

A social network has many-to-many relationships, which a graph represents naturally with nodes and edges.

Q70. What is a key difference in memory allocation between linear and non-linear structures?

Beginner
A Linear structures always use dynamic memory B Linear structures can use contiguous or linked memory; non-linear mostly use dynamic pointer-based memory C Non-linear structures always use contiguous memory D Both use only contiguous memory
Show answer & explanation

Linear structures can use contiguous or linked memory; non-linear mostly use dynamic pointer-based memory

Linear structures like arrays use contiguous memory, while linked lists use pointers. Non-linear structures like trees and graphs typically use dynamic memory.

Q71. Which of the following statements about trees and graphs is TRUE?

Beginner
A A tree can have cycles B A graph is a special type of tree C Graphs cannot have multiple paths between nodes D A tree is a special type of graph with no cycles and a single root
Show answer & explanation

A tree is a special type of graph with no cycles and a single root

A tree is a connected acyclic graph with a root and exactly one path between any two nodes. Graphs can have cycles and multiple paths.

Q72. Which structure is most efficient for autocomplete features?

Beginner
A Trie B Array C Queue D Stack
Show answer & explanation

Trie

Tries are designed for efficient word searching and prefix matching, making them ideal for autocomplete.

Q73. What is the time complexity for searching in a balanced binary search tree?

Beginner
A $O(\log n)$ B $O(1)$ C $O(n)$ D $O(n^2)$
Show answer & explanation

$O(\log n)$

A balanced BST keeps height logarithmic, so search is $O(\log n)$.

Q74. A linked list is a non-linear data structure.

Beginner
A True B False
Show answer & explanation

False

A linked list is linear because each node points to exactly one next node, forming a sequence.

Q75. Non-linear data structures are always slower than linear ones.

Beginner
A True B False
Show answer & explanation

False

Non-linear structures like balanced trees can be faster for search operations than linear structures like linked lists.

Q76. Define linear data structure and give two examples.

Beginner
Show answer & explanation

—

This definition captures the sequential layout and one-to-one relationship.

Q77. Define non-linear data structure and give two examples.

Beginner
Show answer & explanation

—

Non-linear structures have one-to-many or many-to-many relationships.

Q78. What is the difference between LIFO and FIFO?

Beginner
Show answer & explanation

—

These principles define the order of operations in stacks and queues.

Q79. Give a real-world analogy for a stack and explain why it fits.

Beginner
Show answer & explanation

—

Stack's LIFO behavior matches the undo feature.

Q80. Give a real-world analogy for a queue and explain why it fits.

Beginner
Show answer & explanation

—

Queue's FIFO behavior matches a physical queue.

Q81. What is the relationship between elements in a linear data structure?

Beginner
Show answer & explanation

—

This is a defining characteristic of linear structures.

Q82. What type of memory allocation is typical for non-linear data structures?

Beginner
Show answer & explanation

—

Because the structure grows and shrinks as connections change.

Q83. Name three real-world analogies for non-linear data structures.

Beginner
Show answer & explanation

—

These analogies illustrate hierarchical or network-like relationships.

Q84. Which of the following is a primitive data type?

Beginner
A Tree B `int` C Stack D Array
Show answer & explanation

`int`

Primitive data types are basic types provided by the language, such as `int`, `char`, `float`, `bool`, and `pointer`. Arrays, stacks, and trees are non-primitive because they organize multiple values.

Q85. Which of the following is a non-primitive data structure?

Beginner
A `bool` B `char` C `float` D Queue
Show answer & explanation

Queue

A queue is a linear non-primitive data structure. `float`, `bool`, and `char` are primitive types that store single atomic values.

Q86. What does a primitive data structure store?

Beginner
A A single atomic value B A hierarchical structure C A collection of multiple values D A dynamic list of items
Show answer & explanation

A single atomic value

Primitive data structures represent atomic, single-value data types. They cannot hold multiple values; that is the role of non-primitive structures.

Q87. Which of the following is an example of a non-linear non-primitive data structure?

Beginner
A Queue B Array C Tree D Stack
Show answer & explanation

Tree

Non-linear structures arrange elements hierarchically or interconnectedly. Trees, graphs, heaps, and tries are non-linear. Arrays, stacks, and queues are linear.

Q88. Which of the following is a linear non-primitive data structure?

Beginner
A Trie B Heap C Linked List D Graph
Show answer & explanation

Linked List

Linear data structures arrange elements in a sequence. Linked lists, arrays, stacks, and queues are linear. Graphs, heaps, and tries are non-linear.

Q89. Which of the following statements about arrays is true?

Beginner
A Arrays are non-primitive because they organize multiple elements. B Arrays are non-primitive only when they store non-primitive values. C Arrays are primitive because they store primitive values. D Arrays are primitive because they have a fixed size.
Show answer & explanation

Arrays are non-primitive because they organize multiple elements.

Arrays are non-primitive because they organize multiple elements into a single structure, regardless of the type of elements they store. The fact that they store primitive values does not make them primitive.

Q90. What is the main advantage of non-primitive data structures over primitive ones?

Beginner
A They can organize and manipulate collections of data. B They are provided directly by the language. C They use less memory. D They are faster for single-value operations.
Show answer & explanation

They can organize and manipulate collections of data.

Non-primitive structures are designed for manipulation, searching, sorting, and organizing collections of data. Primitives are simple and fast for single values but cannot handle collections.

Q91. Which of the following is a real-life analogy for non-primitive data structures?

Beginner
A A library B A single brick C A single chair D A single book
Show answer & explanation

A library

A library is an organized collection of books, similar to how non-primitive structures organize multiple values. A single brick, book, or chair represents a primitive unit.

Q92. How does memory usage typically differ between primitive and non-primitive data structures?

Beginner
A Both use fixed memory. B Primitives use dynamic memory; non-primitives use fixed memory. C Primitives use fixed memory; non-primitives can use dynamic memory. D Both use dynamic memory.
Show answer & explanation

Primitives use fixed memory; non-primitives can use dynamic memory.

Primitive data types have a fixed memory footprint (e.g., an `int` always uses a fixed number of bytes). Non-primitive structures can use dynamic memory, allowing them to grow or shrink as needed.

Q93. Which of the following is an example of a primitive data type used to store a memory address?

Beginner
A `int` B `char` C `bool` D `pointer`
Show answer & explanation

`pointer`

A pointer is a primitive data type that stores memory addresses. It is often used to build dynamic data structures like linked lists.

Q94. Why are non-primitive data structures considered more flexible than primitive ones?

Beginner
A They always use less memory. B They are faster for single-value operations. C They can grow, shrink, and reorganize. D They are provided by the programming language.
Show answer & explanation

They can grow, shrink, and reorganize.

Non-primitive structures like linked lists can dynamically adjust their size, whereas primitives have a fixed size. This flexibility allows them to handle varying amounts of data efficiently.

Q95. Which of the following best describes the relationship between primitive and non-primitive data structures?

Beginner
A They are the same thing. B Primitive structures are built using non-primitive types. C Non-primitive structures are built using primitive types as building blocks. D They are independent and unrelated.
Show answer & explanation

Non-primitive structures are built using primitive types as building blocks.

Non-primitive data structures are composed of primitive types. For example, an array of integers uses `int` as its base type. Primitives are the atoms; non-primitives are the molecules.

Q96. Which of the following is NOT a characteristic of primitive data structures?

Beginner
A They store single atomic values. B They can grow and shrink dynamically. C They have low flexibility. D They are provided by the programming language.
Show answer & explanation

They can grow and shrink dynamically.

Primitive data structures have fixed memory and cannot grow or shrink. Dynamic behavior is a feature of many non-primitive structures, such as linked lists.

Q97. Which of the following is an example of a non-primitive data structure that can hold a collection of student records?

Beginner
A `char` B Linked list C `bool` D `int`
Show answer & explanation

Linked list

A linked list is a non-primitive structure that can hold multiple records, each composed of primitives like name, age, and grade. Primitives like `int` or `char` can only hold a single value.

Q98. What is the primary purpose of non-primitive data structures?

Beginner
A To provide basic data types to the programmer B To replace primitive data types C To store a single value efficiently D To organize and manipulate collections of data
Show answer & explanation

To organize and manipulate collections of data

Non-primitive data structures are designed for organizing, storing, and manipulating collections of data. They support operations like searching, sorting, and dynamic resizing, which are essential for complex applications.

Q99. Arrays are considered primitive data structures because they store primitive values.

Beginner
A True B False
Show answer & explanation

False

Arrays are non-primitive because they organize multiple elements into a single structure. Storing primitive values does not make them primitive.

Q100. Non-primitive data structures can be either linear or non-linear.

Beginner
A True B False
Show answer & explanation

True

Non-primitive structures are classified into linear (e.g., arrays, stacks, queues, linked lists) and non-linear (e.g., trees, graphs, heaps, tries).

Q101. Define primitive data structure and give two examples.

Beginner
Show answer & explanation

—

This tests recall of the definition and examples.

Q102. Define non-primitive data structure and give two examples.

Beginner
Show answer & explanation

—

This tests recall of the definition and examples.

Q103. What are the two categories of non-primitive data structures?

Beginner
Show answer & explanation

—

This tests understanding of the classification.

Q104. What is the real-life analogy of primitive vs non-primitive data structures?

Beginner
Show answer & explanation

—

This tests the ability to relate abstract concepts to real-world examples.

Q105. What is the primary use case for primitive data structures?

Beginner
Show answer & explanation

—

This tests understanding of when to use primitives.

Q106. List three primitive data types and their typical use.

Beginner
Show answer & explanation

—

This tests recall of primitive types.

Q107. List three non-primitive data structures and their typical use.

Beginner
Show answer & explanation

—

This tests recall of non-primitive structures.

Q108. Give an example of a linear non-primitive data structure and a non-linear one.

Beginner
Show answer & explanation

—

This tests the ability to classify non-primitive structures.

Q109. Which data structure uses pointers to link elements stored in scattered memory?

Beginner
A Array B Linked list C Stack D Queue
Show answer & explanation

Linked list

A linked list stores elements in scattered memory locations, with each element containing a pointer to the next element. Arrays use contiguous memory.

Q110. What is the main advantage of using a data structure over separate variables?

Beginner
A It makes programs run faster without any trade-offs B It brings efficiency, clarity, and organization to programs C It uses less memory in all cases D It eliminates the need for algorithms
Show answer & explanation

It brings efficiency, clarity, and organization to programs

Data structures organize data so that operations become efficient and code becomes clear and maintainable. They do not always use less memory and still require algorithms.

Q111. Which of the following best defines a data structure?

Beginner
A A programming language feature for loops B A hardware component for data storage C A type of algorithm for sorting numbers D A specialized format for organizing, storing, and managing data
Show answer & explanation

A specialized format for organizing, storing, and managing data

A data structure is a specialized format for organizing, storing, and managing data efficiently. It is not a language feature, algorithm, or hardware.

Building up · 57 questions

Q112. What does 'static' refer to in a static data structure?

Intermediate
Show answer & explanation

—

This clarifies a common misconception.

Q113. When should you prefer a static data structure?

Intermediate
Show answer & explanation

—

Static structures are simpler and faster but inflexible.

Q114. What is a common risk when using dynamic structures?

Intermediate
Show answer & explanation

—

Unreleased memory can exhaust system resources over time.

Q115. What is the trade-off between static and dynamic structures?

Intermediate
Show answer & explanation

—

This is the key trade-off in choosing between them.

Q116. Why do most real-world applications prefer dynamic structures?

Intermediate
Show answer & explanation

—

Real-world data sizes are often unpredictable.

Q117. A developer needs to store a fixed set of sensor readings collected every second for exactly 60 seconds. Which data structure would be most appropriate and why?

Intermediate
A A linked list, because it uses non-contiguous memory and is more flexible. B A static array, because the size is known in advance and access is faster. C A linked list, because it allows dynamic resizing if more readings are added. D A dynamic array, because it uses contiguous memory and can grow if needed.
Show answer & explanation

A static array, because the size is known in advance and access is faster.

Since the number of readings is fixed at 60, a static array is ideal: it provides fast O(1) access and avoids the overhead of dynamic memory management. A linked list or dynamic array would add unnecessary complexity and slower access without any benefit because the size is known and will not change.

Q118. Which of the following best explains why accessing an element in a static array is faster than in a linked list?

Intermediate
A Static arrays use pointers to directly locate any element. B Static arrays store elements contiguously, enabling direct arithmetic to compute an element's address. C Static arrays store elements in non-contiguous memory, allowing parallel access. D Static arrays allocate memory at compile time, so the CPU can cache the entire array.
Show answer & explanation

Static arrays store elements contiguously, enabling direct arithmetic to compute an element's address.

In a static array, elements are stored in contiguous memory locations. The address of any element can be computed directly using the base address and index (e.g., base + index * size), giving O(1) access. A linked list requires traversing pointers from the head to reach a specific node, which is O(n).

Q119. A programmer uses `malloc()` to create a linked list node but forgets to call `free()` after the node is no longer needed. What is the most likely consequence?

Intermediate
A The node's data will be automatically overwritten by the next allocation. B The compiler will automatically free the memory at the end of the function. C The memory remains allocated but is no longer accessible, leading to a memory leak. D The program will crash immediately due to a segmentation fault.
Show answer & explanation

The memory remains allocated but is no longer accessible, leading to a memory leak.

When `malloc()` allocates memory, it must be explicitly released with `free()`. If not, the memory stays allocated but the pointer is lost, making it impossible to free later. This is a memory leak, which gradually consumes available memory and can eventually cause the program or system to run out of memory.

Q120. Which of the following scenarios would most likely require a dynamic data structure?

Intermediate
A Storing the days of the week in a program that always uses exactly 7 days. B Storing user-generated posts on a social media platform where the number of posts changes constantly. C Storing the coordinates of a fixed 10x10 game board. D Storing the monthly sales figures for a company that has been in business for 10 years.
Show answer & explanation

Storing user-generated posts on a social media platform where the number of posts changes constantly.

Social media posts are unpredictable in number and change frequently, so a dynamic structure like a linked list or dynamic array is needed to grow and shrink as posts are added or removed. The other options have known, fixed sizes, making static structures more appropriate.

Q121. A dynamic array (e.g., using `realloc` in C) can be resized at runtime. Which of the following statements correctly describes its memory layout?

Intermediate
A It uses contiguous memory, but resizing may require copying all elements to a new memory block. B It always uses non-contiguous memory to allow easy resizing. C It uses a mix of contiguous and non-contiguous memory depending on the data type. D It uses contiguous memory only when the array is small; larger arrays become non-contiguous.
Show answer & explanation

It uses contiguous memory, but resizing may require copying all elements to a new memory block.

A dynamic array maintains a contiguous block of memory. When resizing is needed, `realloc` attempts to extend the existing block; if that's not possible, it allocates a new contiguous block and copies the elements over. Thus, the memory remains contiguous, but resizing can be costly due to the copy operation.

Q122. In the C struct `struct Student { int roll; char name[20]; float marks; };`, identify the fields.

Intermediate
Show answer & explanation

—

Fields are the individual attributes of the record.

Q123. In the C struct `struct Student { int roll; char name[20]; float marks; };`, what does the struct represent?

Intermediate
Show answer & explanation

—

The struct defines a record with fields.

Q124. How would you represent a file of student records in C?

Intermediate
Show answer & explanation

—

An array of structs is a collection of related records, i.e., a file.

Q125. Explain the difference between a data structure and a storage structure.

Intermediate
Show answer & explanation

—

The same logical structure can have different physical implementations.

Q126. Give an example of a logical data structure that can have multiple storage structures.

Intermediate
Show answer & explanation

—

The logical behavior (LIFO) remains the same, but the storage differs.

Q127. In the C struct `struct Student { int roll; char name[20]; float marks; };`, which of the following correctly identifies the roles of `roll`, `name`, and `marks`?

Intermediate
A They are data items because each stores a single value. B They are fields because each is a single attribute of a record. C They are records because they together describe a student. D They are group items because they are related data items.
Show answer & explanation

They are fields because each is a single attribute of a record.

In the context of a record, `roll`, `name`, and `marks` are individual attributes, which are called fields. A record is the entire struct (one student), and a group item is a collection of related data items, but here they are specifically fields of a record.

Q128. Which of the following best explains why a linked list is often preferred over an array for frequent insertions and deletions?

Intermediate
A A linked list requires only updating pointers for insertion/deletion, not shifting elements. B A linked list uses contiguous memory, making insertion faster. C A linked list allows direct access to any element by index. D A linked list always uses less memory than an array.
Show answer & explanation

A linked list requires only updating pointers for insertion/deletion, not shifting elements.

In a linked list, each node stores data and a pointer to the next node. Inserting or deleting a node involves adjusting a few pointers, whereas an array requires shifting elements to maintain contiguous storage. This makes linked lists more efficient for frequent insertions/deletions.

Q129. Given the logical data structure 'stack', which of the following statements about its storage structure is correct?

Intermediate
A A stack can only be implemented using an array. B The storage structure of a stack is always contiguous memory. C A stack can be implemented using either an array or a linked list, with different trade-offs. D The storage structure of a stack is determined by the logical model.
Show answer & explanation

A stack can be implemented using either an array or a linked list, with different trade-offs.

A stack is a logical data structure with LIFO behavior. It can be implemented using an array (contiguous memory, fixed size) or a linked list (scattered nodes, dynamic size). The logical model is separate from the physical storage, so multiple storage structures are possible.

Q130. In a library catalog, each book is represented with fields like title, author, and ISBN. The entire catalog is a collection of all such book entries. Which term best describes the entire catalog?

Intermediate
A A data item B A group item C A file D A record
Show answer & explanation

A file

A file is defined as a collection of related records. In this example, each book entry is a record, and the entire catalog (all book entries) is a file. A group item is a collection of related data items, not necessarily records, and a data item is a single value.

Q131. Why is the choice of storage structure important for the performance of operations on a data structure?

Intermediate
A Because the storage structure is always fixed for a given data structure. B Because different storage structures have different time and space trade-offs for operations like access and insertion. C Because the storage structure determines the data type of the elements. D Because the logical model changes based on the storage structure.
Show answer & explanation

Because different storage structures have different time and space trade-offs for operations like access and insertion.

The storage structure (e.g., array vs. linked list) affects how operations are implemented. Arrays provide O(1) random access but O(n) insertion/deletion, while linked lists provide O(1) insertion/deletion (given a pointer) but O(n) access. These trade-offs directly impact performance, so the choice matters.

Q132. Explain the difference between contiguous and scattered memory storage.

Intermediate
Show answer & explanation

—

Mention the trade-off between access speed and modification flexibility.

Q133. Why are data structures important for program efficiency?

Intermediate
Show answer & explanation

—

Highlight the contrast between organized and unorganized data.

Q134. What is the difference between a data structure and an algorithm?

Intermediate
Show answer & explanation

—

Clarify that they are distinct but complementary.

Q135. Describe the trade-off between arrays and linked lists.

Intermediate
Show answer & explanation

—

Mention both access speed and modification flexibility.

Q136. Give two real-world applications of data structures and identify the data structure used.

Intermediate
Show answer & explanation

—

Any valid example from the source material is acceptable.

Q137. What are the formal characteristics of a data structure?

Intermediate
Show answer & explanation

—

Include grouping, operations, storage, and efficiency.

Q138. Explain how a stack is used in an undo feature.

Intermediate
Show answer & explanation

—

Mention LIFO and push/pop operations.

Q139. What is the role of storage representation in a data structure?

Intermediate
Show answer & explanation

—

Mention contiguous vs. scattered and performance impact.

Q140. A programmer needs to store a collection of student records and frequently insert new records at the beginning of the collection. Which data structure would be most efficient for this operation, and why?

Intermediate
A Hash table, because it provides constant-time lookup. B Stack, because it follows LIFO order. C Array, because it allows direct access by index. D Linked list, because insertion at the head only requires updating a few pointers.
Show answer & explanation

Linked list, because insertion at the head only requires updating a few pointers.

Inserting at the beginning of an array requires shifting all existing elements, which is O(n). A linked list can insert at the head in O(1) by updating the head pointer and the new node's next pointer. Stacks and hash tables are not designed for arbitrary insertion at the beginning.

Q141. Consider the following scenario: You need to implement a feature that finds the shortest path between two locations in a city. Which data structure is most appropriate to model the city's road network?

Intermediate
A Graph B Linked list C Stack D Array
Show answer & explanation

Graph

A graph is the natural data structure to represent a road network, with intersections as vertices and roads as edges. Algorithms like Dijkstra's operate on graphs to find shortest paths. Arrays, linked lists, and stacks do not capture the complex relationships between locations.

Q142. Which of the following best explains the relationship between a data structure and an algorithm?

Intermediate
A An algorithm defines how data is stored, while a data structure defines how to manipulate it. B A data structure is a step-by-step procedure, while an algorithm is the organization of data. C A data structure organizes data, and an algorithm is a procedure that operates on that data. D They are interchangeable terms for the same concept.
Show answer & explanation

A data structure organizes data, and an algorithm is a procedure that operates on that data.

A data structure is the logical organization of data (e.g., array, tree), while an algorithm is a step-by-step procedure to perform a task (e.g., binary search). They work together: algorithms often require specific data structures to be efficient.

Q143. A developer is choosing between an array and a linked list to store a list of tasks. The tasks are frequently searched by their position (e.g., the 5th task), but rarely inserted or deleted. Which data structure is more suitable, and why?

Intermediate
A Array, because it uses less memory for pointers. B Linked list, because it supports efficient traversal. C Linked list, because it uses pointers for flexibility. D Array, because it allows direct access by index in O(1) time.
Show answer & explanation

Array, because it allows direct access by index in O(1) time.

Arrays provide O(1) direct access by index, which is ideal for frequent positional access. Linked lists require O(n) traversal to reach a specific position. While arrays may have overhead for insertions/deletions, the scenario emphasizes searching by position, making arrays the better choice.

Q144. In the context of data structures, what does 'storage representation' refer to?

Intermediate
A The algorithm used to sort the data. B How data is physically laid out in memory, such as contiguous or scattered. C The set of operations that can be performed on the data. D The logical relationship between data elements.
Show answer & explanation

How data is physically laid out in memory, such as contiguous or scattered.

Storage representation describes how data is placed in memory—contiguously (like arrays) or scattered with pointers (like linked lists). This affects access speed and flexibility. The logical relationship and operations are separate aspects of a data structure.

Q145. What is a trie and where is it commonly used?

Intermediate
Show answer & explanation

—

Tries allow fast prefix-based searches.

Q146. How does traversal differ between linear and non-linear structures?

Intermediate
Show answer & explanation

—

This affects how you implement algorithms to visit all elements.

Q147. Why might a balanced binary search tree be faster than a linked list for searching?

Intermediate
Show answer & explanation

—

The tree's structure allows halving the search space each step.

Q148. What is the key difference between a tree and a graph?

Intermediate
Show answer & explanation

—

All trees are graphs, but not all graphs are trees.

Q149. When would you choose a linear structure over a non-linear one?

Intermediate
Show answer & explanation

—

Linear structures are easier to implement and traverse for sequential processing.

Q150. When would you choose a non-linear structure?

Intermediate
Show answer & explanation

—

Non-linear structures model one-to-many or many-to-many relationships.

Q151. What is a common misconception about non-linear data structures?

Intermediate
Show answer & explanation

—

Efficiency depends on the operation and the specific structure.

Q152. A developer needs to store a collection of words for an autocomplete feature. The words share common prefixes, and the developer wants to minimize memory usage by sharing those prefixes. Which data structure is the most appropriate choice, and why?

Intermediate
A A linked list, because it allows dynamic insertion of new words. B A trie, because it is a non-linear structure that stores characters in a tree-like layout, sharing common prefixes. C A queue, because it processes words in the order they are typed. D A stack, because it can reverse the order of words for faster lookup.
Show answer & explanation

A trie, because it is a non-linear structure that stores characters in a tree-like layout, sharing common prefixes.

A trie is a non-linear, tree-like data structure specifically designed for storing strings with common prefixes. It shares those prefixes, reducing memory usage and enabling fast prefix-based searches, which is ideal for autocomplete. The other options are linear structures that do not share prefixes and would store ea…

Q153. Consider a binary search tree (BST) and a sorted array. Which statement correctly compares their performance for search and insertion operations?

Intermediate
A A BST always has $O(1)$ search time, while a sorted array has $O(n)$ search time. B A sorted array has $O(1)$ insertion time, while a BST has $O(n)$ insertion time. C A sorted array has $O(\log n)$ search time but $O(n)$ insertion time, while a balanced BST has $O(\log n)$ for both search and insertion. D Both have $O(n)$ search and insertion times in all cases.
Show answer & explanation

A sorted array has $O(\log n)$ search time but $O(n)$ insertion time, while a balanced BST has $O(\log n)$ for both search and insertion.

A sorted array supports binary search in $O(\log n)$ time, but inserting an element requires shifting elements, which is $O(n)$. A balanced BST maintains $O(\log n)$ time for both search and insertion because it keeps the tree height logarithmic. This trade-off is a key difference between linear and non-linear structur…

Q154. A file system directory structure is best modeled as a tree, not a graph. Which property of a tree makes it more suitable than a general graph for this use case?

Intermediate
A A tree is a linear structure, making traversal simpler. B A tree has no root, allowing multiple entry points. C A tree allows cycles, which is necessary for representing shortcuts. D A tree has a single root and exactly one path between any two nodes, ensuring a clear hierarchy without cycles.
Show answer & explanation

A tree has a single root and exactly one path between any two nodes, ensuring a clear hierarchy without cycles.

A tree is a non-linear, hierarchical structure with a single root and exactly one path between any two nodes. This ensures no cycles and a clear parent-child relationship, which matches how directories contain subdirectories. A general graph can have cycles and multiple paths, which would not represent a strict hierarc…

Q155. In a linked list, each node points to the next node. Why is a linked list still considered a linear data structure even if it uses pointers and dynamic memory allocation?

Intermediate
A Because it uses contiguous memory allocation. B Because it supports constant-time random access. C Because each element has exactly one predecessor and one successor, forming a single sequence. D Because it can only store primitive data types.
Show answer & explanation

Because each element has exactly one predecessor and one successor, forming a single sequence.

The linearity of a data structure is defined by the logical arrangement of elements, not the physical memory layout. In a linked list, each node (except the first and last) has exactly one predecessor and one successor, so elements form a single sequence. This is true even though memory is dynamically allocated and nod…

Q156. A social network like Facebook uses a graph to model friendships. Which characteristic of a graph makes it more suitable than a tree for this scenario?

Intermediate
A A graph has a root node, which is necessary for central control. B A graph has exactly one path between any two nodes, simplifying connection checks. C A graph is a linear structure, making it easier to traverse all users. D A graph allows many-to-many relationships and cycles, representing mutual friendships and multiple connections.
Show answer & explanation

A graph allows many-to-many relationships and cycles, representing mutual friendships and multiple connections.

A graph is a non-linear structure that allows many-to-many relationships and cycles. In a social network, a person can have many friends, and friendships can form cycles (e.g., A is friends with B, B with C, C with A). A tree, by contrast, has a hierarchical structure with exactly one path between nodes and no cycles,…

Q157. Why is an array considered non-primitive even though it stores primitive values?

Intermediate
Show answer & explanation

—

This targets the common misconception about arrays.

Q158. How does memory usage differ between primitive and non-primitive data structures?

Intermediate
Show answer & explanation

—

This tests understanding of memory allocation.

Q159. Which type of data structure offers higher flexibility: primitive or non-primitive? Explain.

Intermediate
Show answer & explanation

—

This tests the flexibility characteristic.

Q160. What is the primary use case for non-primitive data structures?

Intermediate
Show answer & explanation

—

This tests understanding of when to use non-primitives.

Q161. What does 'atomic' mean in the context of primitive data types?

Intermediate
Show answer & explanation

—

This tests understanding of the term 'atomic'.

Q162. Why are non-primitive data structures considered 'user-defined'?

Intermediate
Show answer & explanation

—

This tests understanding of the origin of non-primitives.

Q163. What is the role of a pointer in data structures?

Intermediate
Show answer & explanation

—

This tests understanding of pointers as primitives.

Q164. A programmer needs to store a collection of student records, each containing a name (string), an age (int), and a grade (char). Which approach best demonstrates the relationship between primitive and non-primitive data structures?

Intermediate
A Use a primitive array to store all student records, since arrays are primitive. B Declare separate primitive variables for each student's name, age, and grade, and manage them individually. C Use an array of structs, where each struct combines primitive types (string, int, char) into a single non-primitive unit. D Use a single primitive variable to store all student data as a long string.
Show answer & explanation

Use an array of structs, where each struct combines primitive types (string, int, char) into a single non-primitive unit.

Non-primitive data structures are built on top of primitives. An array of structs organizes multiple primitive values (name, age, grade) into a structured, indexable collection, demonstrating how non-primitives combine primitives. The other options either misuse primitives or incorrectly classify arrays as primitive.

Q165. Consider the following code snippet: ```c int arr[5] = {10, 20, 30, 40, 50}; ``` Why is `arr` considered a non-primitive data structure even though it stores primitive `int` values?

Intermediate
A Because it can grow and shrink dynamically at runtime. B Because it is a user-defined type, unlike primitive types. C Because it holds multiple values and provides an organized, indexable collection. D Because it uses a fixed amount of memory, like all non-primitive structures.
Show answer & explanation

Because it holds multiple values and provides an organized, indexable collection.

The key distinction is that non-primitive structures organize multiple elements into a single unit. An array groups five `int` values into one indexable structure, making it non-primitive. It is not user-defined (arrays are built-in), and it has a fixed size, so the other options are incorrect.

Q166. In terms of memory usage, how do primitive and non-primitive data structures typically differ?

Intermediate
A Primitive types use variable memory, while non-primitive types use fixed memory. B Non-primitive types use less memory because they share data among elements. C Primitive types use a fixed amount of memory, while non-primitive types can use dynamic memory and often require additional overhead for organization. D Both primitive and non-primitive types always use the same amount of memory.
Show answer & explanation

Primitive types use a fixed amount of memory, while non-primitive types can use dynamic memory and often require additional overhead for organization.

Primitive types have a fixed memory footprint (e.g., an `int` is always 4 bytes on many systems). Non-primitive structures like linked lists or arrays may use dynamic memory and often include extra overhead (e.g., pointers, metadata) to manage the collection. The other options misrepresent the typical memory behavior.

Q167. A developer needs to represent a hierarchical file system where each folder can contain subfolders and files. Which type of non-primitive data structure is most appropriate, and why?

Intermediate
A An array, because it stores elements in a linear sequence. B A tree, because it arranges elements hierarchically with parent-child relationships. C A stack, because it uses a last-in, first-out order. D A queue, because it processes elements in a first-in, first-out order.
Show answer & explanation

A tree, because it arranges elements hierarchically with parent-child relationships.

A file system naturally forms a hierarchy—folders contain subfolders, which contain files. Trees are non-linear non-primitive structures designed for hierarchical relationships. Queues and stacks are linear structures for ordered processing, and arrays are linear collections, none of which capture the hierarchical natu…

Q168. Which of the following statements best explains why non-primitive data structures are considered 'user-defined'?

Intermediate
A They are automatically generated by the compiler without user input. B They can only be used after the user defines a new primitive type. C They are defined by the programming language and cannot be modified by users. D They are created by combining primitive types and other structures to suit specific needs.
Show answer & explanation

They are created by combining primitive types and other structures to suit specific needs.

Non-primitive structures are built by the programmer using primitives and other structures (e.g., a struct combining int and char). They are not predefined by the language; the user designs them to solve specific problems. The other options incorrectly describe their origin or flexibility.

Topper level · 32 questions

Q169. What is a memory leak?

Advanced
Show answer & explanation

—

It is a serious issue in long-running programs.

Q170. Can a dynamic structure use contiguous memory? Give an example.

Advanced
Show answer & explanation

—

This shows that dynamic refers to size flexibility, not necessarily memory layout.

Q171. A developer is designing a system to store sensor readings from a high-frequency data acquisition device. The device produces exactly 1,000 readings per second, and the system must process each batch of 1,000 readings within a strict 10-millisecond deadline. The readings are processed sequentially, and the size never changes. Which data structure should the developer choose, and why?

Advanced
A A dynamic array (using `realloc`) because it can be resized if the sensor frequency changes. B A dynamic structure like a hash table because it provides faster lookup than an array. C A linked list because it allows O(1) insertion at the tail. D A static array because it provides O(1) access and avoids runtime allocation overhead, ensuring the strict deadline is met.
Show answer & explanation

A static array because it provides O(1) access and avoids runtime allocation overhead, ensuring the strict deadline is met.

The data size is known and fixed (1,000 readings per batch), and the system has a strict performance deadline. A static array allocates memory at compile time, providing contiguous storage and O(1) access with no runtime allocation overhead. Dynamic structures like linked lists or `realloc` introduce runtime overhead a…

Q172. Consider the following C code snippet: ```c int *arr = (int*) malloc(10 * sizeof(int)); arr = (int*) realloc(arr, 20 * sizeof(int)); free(arr); ``` Which of the following statements correctly describes the memory behavior of this dynamic array?

Advanced
A The `realloc` function may extend the existing memory block in place or move it to a new location; in either case, the logical order of elements is preserved. B After `realloc`, the array becomes non-contiguous, so accessing elements requires pointer traversal. C The `realloc` function always moves the array to a new memory location, leaving the original block untouched. D The `free(arr)` call only deallocates the memory allocated by the original `malloc`, not the resized block.
Show answer & explanation

The `realloc` function may extend the existing memory block in place or move it to a new location; in either case, the logical order of elements is preserved.

`realloc` attempts to resize the existing memory block. If there is enough contiguous space, it extends in place; otherwise, it allocates a new block, copies the old data, and frees the old block. In both cases, the resulting memory is contiguous and the logical order of elements is preserved. The `free` call after `re…

Q173. A programmer needs to implement a function that processes a list of integers. The list is built by reading integers from a file until the end of the file is reached. The number of integers is unknown in advance. The programmer decides to use a linked list. Which of the following is the most significant trade-off of this choice compared to using a dynamic array?

Advanced
A The linked list allocates memory at compile time, making it faster to create nodes. B The linked list cannot be resized at runtime, so it is unsuitable for unknown input sizes. C The linked list provides O(1) access to any element, which is faster than a dynamic array. D The linked list uses more memory per element due to the pointer field, and accessing the i-th element requires O(n) time.
Show answer & explanation

The linked list uses more memory per element due to the pointer field, and accessing the i-th element requires O(n) time.

A linked list allocates memory dynamically for each node, but each node also stores a pointer to the next node, increasing memory overhead. Accessing the i-th element requires traversing from the head, which is O(n). A dynamic array (using `realloc`) also resizes at runtime but provides O(1) access and uses less memory…

Q174. A developer is writing a program that needs to store a fixed set of configuration parameters (e.g., 10 integer values) that are read at startup and never change in size. The program is running on a memory-constrained embedded system. Which of the following statements best justifies using a static array over a dynamic structure?

Advanced
A A static array uses non-contiguous memory, which reduces fragmentation on the embedded system. B A static array allows the program to allocate memory only when needed, saving memory when the configuration is small. C A static array can be resized at runtime if the configuration changes, providing flexibility. D A static array avoids the overhead of runtime memory allocation, reducing the risk of memory leaks and ensuring predictable memory usage.
Show answer & explanation

A static array avoids the overhead of runtime memory allocation, reducing the risk of memory leaks and ensuring predictable memory usage.

Static arrays allocate memory at compile time, so there is no runtime allocation overhead, no risk of memory leaks from `malloc`/`free`, and memory usage is fixed and predictable. This is ideal for memory-constrained systems where the size is known. Dynamic structures would introduce overhead and potential fragmentatio…

Q175. A software engineer is designing a text editor that must support undo/redo operations. The number of undo steps is limited to 50, and each step stores a snapshot of the document. The engineer initially uses a linked list to store the snapshots but notices that accessing the most recent snapshot (the last element) is slow. Which of the following changes would best improve the performance of accessing the most recent snapshot while still respecting the fixed limit of 50 steps?

Advanced
A Use a dynamic array that grows without bound to store all snapshots, ensuring O(1) access to the last element. B Use a static array of size 50 but shift all elements on each new snapshot to keep the most recent at the front. C Keep the linked list but add a pointer to the last node, allowing O(1) access to the most recent snapshot. D Replace the linked list with a static array of size 50, using a circular buffer to overwrite the oldest snapshot when full.
Show answer & explanation

Replace the linked list with a static array of size 50, using a circular buffer to overwrite the oldest snapshot when full.

A static array of size 50 with a circular buffer provides O(1) access to any element, including the most recent, and respects the fixed limit of 50 steps. Adding a tail pointer to a linked list would give O(1) access to the last node, but the question asks for the best improvement; a circular buffer is simpler and avoi…

Q176. Why is the choice of storage structure important for performance?

Advanced
Show answer & explanation

—

Performance depends on the storage structure.

Q177. Consider the following C code snippet: ```c struct Point { int x; int y; }; struct Point p1 = {3, 4}; struct Point p2 = {5, 6}; struct Point points[2] = {p1, p2}; ``` In the context of data structure terminology, which of the following statements is **most accurate**?

Advanced
A `points` is a record, `p1` and `p2` are fields, and `x` and `y` are data items. B `points` is a storage structure, `p1` and `p2` are files, and `x` and `y` are records. C `points` is a file, `p1` and `p2` are records, and `x` and `y` are fields. D `points` is a data structure, `p1` and `p2` are group items, and `x` and `y` are data items.
Show answer & explanation

`points` is a file, `p1` and `p2` are records, and `x` and `y` are fields.

In the given code, `struct Point` defines a record with fields `x` and `y`. `p1` and `p2` are instances of that record, so they are records. The array `points` is a collection of related records (two points), which fits the definition of a file. The other options misclassify the terms: a data structure is a broader log…

Q178. A developer is designing a system to store a collection of employee records. Each record has fields: `emp_id`, `name`, and `salary`. The system must support frequent insertions and deletions of records in the middle of the collection, and also occasional searches by `emp_id`. Which storage structure is **most appropriate** for this scenario, and why?

Advanced
A An array, because it provides O(1) random access for searches by `emp_id` and supports insertions/deletions in O(1) time. B A hash table, because it provides O(1) insertions, deletions, and searches, and also maintains the order of records. C A linked list, because insertions and deletions in the middle are O(1) once the position is known, and searches can be done by traversing. D A binary search tree, because it provides O(log n) insertions, deletions, and searches, and also allows efficient in-order traversal.
Show answer & explanation

A linked list, because insertions and deletions in the middle are O(1) once the position is known, and searches can be done by traversing.

The requirement emphasizes frequent insertions and deletions in the middle of the collection. A linked list excels at this because, once the node is located, insertion and deletion only involve updating pointers, which is O(1). Searches by `emp_id` would require traversal, but that is acceptable given the emphasis on i…

Q179. A data structure is defined as a stack, and it is implemented using an array. Which of the following statements correctly describes the relationship between the data structure and the storage structure?

Advanced
A The data structure is the array, and the storage structure is the stack, because the array is the physical implementation. B The data structure and storage structure are identical because the stack is always implemented as an array. C The data structure is the abstract logical model (stack) with LIFO behavior, and the storage structure is the array that physically stores the elements. D The data structure is the stack, and the storage structure is the LIFO behavior, because the behavior defines the storage.
Show answer & explanation

The data structure is the abstract logical model (stack) with LIFO behavior, and the storage structure is the array that physically stores the elements.

The data structure is the logical organization—here, a stack with LIFO semantics. The storage structure is the concrete implementation—here, an array that holds the elements in memory. They are distinct concepts: the same logical stack could be implemented with a linked list, so they are not identical. The other option…

Q180. In a database system, a table `Students` has columns `id`, `name`, and `gpa`. Each row represents a student. Which of the following statements is **correct** in terms of data structure terminology?

Advanced
A Each row is a file, each column is a record, and the entire table is a data structure. B Each row is a group item, each column is a data item, and the entire table is a record. C Each row is a data item, each column is a field, and the entire table is a group item. D Each row is a record, each column is a field, and the entire table is a file.
Show answer & explanation

Each row is a record, each column is a field, and the entire table is a file.

In a relational database, a row is a record because it is a collection of related fields that describe one entity (a student). Columns are fields because they represent a single attribute. The entire table is a file because it is a collection of related records. The other options misapply the hierarchy: a row is not a…

Q181. A programmer needs to store a collection of 2D points. Each point has two coordinates, `x` and `y`. The programmer defines a structure `Point` and then creates an array of `Point` objects. Which of the following statements is **most accurate**?

Advanced
A The structure `Point` is a record, each instance is a record, and the array is a file. B The structure `Point` is a group item, each instance is a data item, and the array is a storage structure. C The structure `Point` is a field, each instance is a group item, and the array is a record. D The structure `Point` is a data structure, each instance is a record, and the array is a file.
Show answer & explanation

The structure `Point` is a record, each instance is a record, and the array is a file.

The structure `Point` defines a record with fields `x` and `y`. Each instance of `Point` is a record because it holds values for those fields. The array of `Point` objects is a collection of related records, which is a file. The other options misclassify: `Point` is not a group item (it has named fields, making it a re…

Q182. Why is choosing the right data structure important?

Advanced
Show answer & explanation

—

Emphasize the trade-offs and context-dependence.

Q183. A software engineer is designing a system to store a dynamic collection of student records. The system must support frequent insertions at the beginning of the collection, but also needs to allow binary search on the records. Which approach best satisfies both requirements, and why?

Advanced
A Use a hash table to store records, and sort the keys when binary search is needed. B Use an array and shift all elements right on each insertion at the beginning, then use binary search on the array. C Use a linked list for O(1) insertions at the head, and implement binary search by traversing the list to the midpoint each time. D Use a balanced binary search tree (e.g., AVL tree) to maintain sorted order with O(log n) insertions and O(log n) search.
Show answer & explanation

Use a balanced binary search tree (e.g., AVL tree) to maintain sorted order with O(log n) insertions and O(log n) search.

A balanced BST (like AVL) supports O(log n) insertions (including at the 'beginning' in sorted order) and O(log n) search, which is efficient. A linked list gives O(1) insertions at the head but binary search on a linked list is O(n) because random access is not possible. An array allows binary search but shifting elem…

Q184. Consider a navigation system that models a city's road network. The system must find the shortest path between two locations, and also frequently update road weights (e.g., due to traffic). Which data structure and algorithm combination is most appropriate, and why?

Advanced
A Use an adjacency list and Dijkstra's algorithm with a binary heap priority queue. B Use a hash table to store edges and perform a depth-first search for the shortest path. C Use a linked list of edges and apply Bellman-Ford algorithm without any priority queue. D Use an adjacency matrix and Dijkstra's algorithm with a simple array-based priority queue.
Show answer & explanation

Use an adjacency list and Dijkstra's algorithm with a binary heap priority queue.

An adjacency list is memory-efficient for sparse road networks and allows quick updates to edge weights. Dijkstra's algorithm with a binary heap achieves O((V+E) log V) time, which is efficient for shortest path. An adjacency matrix uses O(V^2) memory and is inefficient for sparse graphs. DFS does not guarantee shortes…

Q185. A developer needs to implement an undo feature in a text editor. The editor must support undoing the most recent action, but also allow the user to redo an action after undoing. Which data structure(s) would be most appropriate, and what is the trade-off?

Advanced
A Use a single stack for undo; redo is not possible with a single stack. B Use a queue for undo and a stack for redo, allowing FIFO undo order. C Use two stacks: one for undo and one for redo. When an undo occurs, the action is pushed onto the redo stack; when a new action is performed, the redo stack is cleared. D Use an array to store all actions and a pointer to the current position, but this requires shifting elements on undo.
Show answer & explanation

Use two stacks: one for undo and one for redo. When an undo occurs, the action is pushed onto the redo stack; when a new action is performed, the redo stack is cleared.

Two stacks are the classic approach: the undo stack holds actions in LIFO order, and the redo stack stores undone actions. When a new action is performed, the redo stack is cleared to maintain consistency. A single stack cannot support redo. A queue would give FIFO order, which is incorrect for undo. An array with a po…

Q186. A programmer is comparing an array and a linked list for storing a list of tasks. The tasks are frequently accessed by their position (e.g., the 5th task), but insertions and deletions are rare. Which data structure is more suitable, and what is the time complexity for accessing the 5th task in each?

Advanced
A Array, because accessing the 5th task is O(log n) using binary search, while linked list access is O(n). B Array, because accessing the 5th task is O(1) via index, while linked list access is O(n) due to traversal. C Linked list, because insertions and deletions are rare, so the overhead of pointers is negligible, and access is O(1) with a tail pointer. D Linked list, because accessing the 5th task is O(1) if you maintain a pointer to the 5th node, while array access is O(n) due to shifting.
Show answer & explanation

Array, because accessing the 5th task is O(1) via index, while linked list access is O(n) due to traversal.

Arrays provide O(1) random access by index because elements are stored in contiguous memory. Linked lists require traversal from the head to reach the 5th node, which is O(n) in the worst case. Maintaining a pointer to the 5th node is not practical for arbitrary positions. Binary search on an array is O(log n) but only…

Q187. In the formal definition of a data structure, which of the following correctly describes the relationship between storage representation and the operations allowed?

Advanced
A Storage representation is independent of operations; any storage layout can support any operation with the same efficiency. B Operations are defined solely by the logical grouping of data, and storage representation only affects memory usage, not operation speed. C Storage representation determines the efficiency of operations; for example, contiguous storage enables O(1) index access, while scattered storage requires traversal for access. D Storage representation is only relevant for linked structures; arrays do not have a storage representation.
Show answer & explanation

Storage representation determines the efficiency of operations; for example, contiguous storage enables O(1) index access, while scattered storage requires traversal for access.

The storage representation (contiguous vs. scattered) directly impacts the time complexity of operations. Arrays (contiguous) allow O(1) random access, while linked lists (scattered) require O(n) traversal for access. Operations are not independent of storage; the physical layout determines how efficiently operations c…

Q188. A developer is designing a system to manage a sequence of undo operations in a text editor. The system must support undoing the most recent action first, but also allow the user to 'redo' an undone action if no new action is performed in between. Which combination of data structures would best model this behavior, and why?

Advanced
A A binary search tree: actions are stored in sorted order, and undo/redo traverses the tree to find the most recent action. B A single queue: actions are enqueued and dequeued in FIFO order, with a pointer to track the current position for undo/redo. C Two stacks: one for undo history and one for redo history. When an action is undone, it is popped from the undo stack and pushed onto the redo stack. A new action clears the redo stack. D A single linked list: each node represents an action, and undo/redo moves a pointer forward or backward through the list.
Show answer & explanation

Two stacks: one for undo history and one for redo history. When an action is undone, it is popped from the undo stack and pushed onto the redo stack. A new action clears the redo stack.

Undo/redo requires LIFO behavior for both operations: the most recent action is undone first, and the most recently undone action is redone first. Two stacks perfectly capture this: the undo stack holds actions in reverse chronological order, and the redo stack holds undone actions in reverse order of undoing. A new ac…

Q189. Consider a file system directory structure. It is modeled as a tree, not a general graph. Which property of a tree makes it more suitable than a general graph for representing the hierarchical organization of folders and files?

Advanced
A A tree is always balanced, which ensures that file system operations like searching for a file are always O(log n). B A tree allows multiple parents for a node, which is necessary for representing hard links in a file system. C A tree has exactly one path between any two nodes, which enforces a strict parent-child relationship and prevents cycles, ensuring that there is no ambiguity in the hierarchy. D A tree is a linear structure, which simplifies traversal and makes it easier to list all files in a directory.
Show answer & explanation

A tree has exactly one path between any two nodes, which enforces a strict parent-child relationship and prevents cycles, ensuring that there is no ambiguity in the hierarchy.

The defining property of a tree is that there is exactly one unique path between any two nodes, and it has a single root. This enforces a strict hierarchy where each node (except the root) has exactly one parent, making the structure acyclic. This is ideal for a file system because folders and files are organized in a…

Q190. A developer needs to store a collection of words for an autocomplete feature. The words share common prefixes, and the developer wants to minimize memory usage by sharing those prefixes. Which data structure is the most appropriate choice, and why?

Advanced
A A hash set, because it provides O(1) lookup for exact words and can be used to check if a prefix exists by iterating over all keys. B A linked list, because it allows dynamic insertion of words and can be traversed to find all words with a given prefix. C A trie (prefix tree), because it stores common prefixes only once, reducing memory usage when many words share prefixes, and it allows efficient prefix-based searches. D A balanced binary search tree, because it keeps words sorted and allows prefix searches by traversing the tree in order.
Show answer & explanation

A trie (prefix tree), because it stores common prefixes only once, reducing memory usage when many words share prefixes, and it allows efficient prefix-based searches.

A trie is specifically designed to store strings by sharing common prefixes. Each node represents a character, and paths from the root to leaves represent words. This minimizes memory usage when words share prefixes (e.g., 'cat', 'car', 'can' share 'ca'). It also supports efficient prefix searches: to find all words wi…

Q191. Consider a binary search tree (BST) and a sorted array. Which statement correctly compares their performance for search and insertion operations?

Advanced
A A sorted array supports O(1) search and O(1) insertion, while a BST supports O(log n) for both. B A sorted array supports O(log n) search via binary search but O(n) insertion due to shifting elements, while a balanced BST supports O(log n) for both search and insertion. C A sorted array supports O(n) search and O(1) insertion, while a BST supports O(log n) search and O(n) insertion. D A sorted array supports O(log n) search and O(log n) insertion, while a BST supports O(n) for both.
Show answer & explanation

A sorted array supports O(log n) search via binary search but O(n) insertion due to shifting elements, while a balanced BST supports O(log n) for both search and insertion.

In a sorted array, binary search can find an element in O(log n) time, but inserting an element requires shifting all subsequent elements to maintain sorted order, which is O(n) in the worst case. A balanced BST (e.g., AVL or Red-Black tree) maintains balance, ensuring that both search and insertion are O(log n) becaus…

Q192. A social network like Facebook uses a graph to model friendships. Which characteristic of a graph makes it more suitable than a tree for this scenario?

Advanced
A Graphs are linear, which makes it easier to traverse all users in a simple sequence. B Graphs allow cycles and multiple paths, which can represent mutual friendships and the possibility of multiple connection paths between users, whereas trees enforce a strict hierarchy with no cycles. C Graphs have a single root node, which simplifies the representation of the entire network from a central user. D Graphs are always connected, ensuring that every user is reachable from every other user, which is necessary for a social network.
Show answer & explanation

Graphs allow cycles and multiple paths, which can represent mutual friendships and the possibility of multiple connection paths between users, whereas trees enforce a strict hierarchy with no cycles.

A social network is inherently non-hierarchical: friendships are mutual (undirected edges) and can form cycles (e.g., A is friends with B, B with C, C with A). There can be multiple paths between two users. Graphs are designed to model such many-to-many relationships with cycles and multiple paths. Trees, by definition…

Q193. A programmer is designing a system to store and manipulate a collection of sensor readings. Each reading is a floating-point number, and the system must support frequent insertions and deletions at both ends of the collection. Which combination of primitive and non-primitive data structures best satisfies the requirement, and why?

Advanced
A Use a queue of `float` values because queues are non-primitive and allow operations at both ends. B Use an array of `float` values because arrays provide direct indexing and are non-primitive. C Use a stack of `float` values because stacks are linear and support insertions and deletions at both ends. D Use a linked list of `float` values because linked lists allow efficient insertions and deletions at both ends, and `float` is a primitive type.
Show answer & explanation

Use a linked list of `float` values because linked lists allow efficient insertions and deletions at both ends, and `float` is a primitive type.

A linked list is a non-primitive linear data structure that allows O(1) insertions and deletions at both ends (head and tail) if pointers are maintained. An array has fixed size and shifting elements for insertions/deletions is O(n). A stack only allows operations at one end (LIFO), and a queue typically allows inserti…

Q194. Consider the following C code snippet: ```c struct Student { char name[50]; int age; char grade; }; struct Student classRoom[30]; ``` Which of the following statements correctly analyzes the primitive and non-primitive aspects of this code?

Advanced
A `classRoom` is a non-primitive array of structures, and each structure is non-primitive because it contains a `char` array, but `age` and `grade` are primitive. B `name` is a primitive data type because it is a single variable. C The `struct Student` is a primitive data type because it is defined by the user. D `classRoom` is a primitive array because it stores primitive types like `int` and `char`.
Show answer & explanation

`classRoom` is a non-primitive array of structures, and each structure is non-primitive because it contains a `char` array, but `age` and `grade` are primitive.

`classRoom` is an array (non-primitive) of `struct Student` objects. Each `struct Student` is a user-defined non-primitive data type because it aggregates multiple fields. Within the struct, `age` (int) and `grade` (char) are primitive types, while `name` is a `char` array (non-primitive). Arrays are never primitive; t…

Q195. A developer needs to represent a family tree where each person has a name (string), age (int), and a list of children. Which combination of primitive and non-primitive data structures is most appropriate, and why?

Advanced
A Use a tree (non-primitive) where each node stores a `string` for name and an `int` for age; children are pointers to other nodes. This leverages primitives for atomic data and non-primitives for hierarchy. B Use a stack (non-primitive) to store people; the hierarchy is represented by push and pop operations. C Use an array of `int` values to store ages and a separate array of `string` for names; this is sufficient to represent the hierarchy. D Use a linked list (non-primitive) to store all people linearly; the hierarchy can be inferred from the order.
Show answer & explanation

Use a tree (non-primitive) where each node stores a `string` for name and an `int` for age; children are pointers to other nodes. This leverages primitives for atomic data and non-primitives for hierarchy.

A family tree is a hierarchical structure, best represented by a tree (non-primitive, non-linear). Each node contains primitive data (string for name, int for age) and references to child nodes (pointers, which are primitive). Arrays and linked lists are linear and cannot naturally represent parent-child relationships.…

Q196. In a memory-constrained embedded system, a developer must choose between using a fixed-size array of `int` and a dynamically allocated linked list of `int` to store a list of sensor readings. Which statement best evaluates the trade-offs in terms of primitive vs non-primitive data structures?

Advanced
A The array is non-primitive and uses contiguous memory, leading to better cache locality and lower overhead, but it cannot grow dynamically; the linked list is non-primitive and uses scattered memory with per-node overhead, but it can grow dynamically. B Both are primitive because they store `int` values; the choice depends only on the number of elements. C The array is primitive because it stores `int` values, and the linked list is non-primitive; the array is always more memory-efficient. D The linked list is primitive because it uses pointers, and the array is non-primitive; the linked list is always faster for traversal.
Show answer & explanation

The array is non-primitive and uses contiguous memory, leading to better cache locality and lower overhead, but it cannot grow dynamically; the linked list is non-primitive and uses scattered memory with per-node overhead, but it can grow dynamically.

Both arrays and linked lists are non-primitive data structures. Arrays use contiguous memory, which improves cache locality and reduces overhead, but have fixed size. Linked lists use non-contiguous memory with extra pointer storage per node, allowing dynamic growth but with higher memory overhead and poorer cache perf…

Q197. A programmer is implementing a text editor's undo feature. The editor needs to store a sequence of operations, each operation being a tuple (type: `char`, position: `int`, text: `string`). The undo feature must allow undoing the most recent operation first, and the number of operations can grow indefinitely. Which data structure choice best utilizes primitive and non-primitive types, and why?

Advanced
A Use an array (non-primitive) of structures (non-primitive) with fixed size; this is sufficient because the number of operations is known in advance. B Use a linked list (non-primitive) of primitive `char` and `int` values; this avoids the need for structures. C Use a stack (non-primitive) where each element is a structure (non-primitive) containing primitive fields (`char`, `int`) and a string (non-primitive). This supports LIFO undo and dynamic growth. D Use a queue (non-primitive) of primitive tuples; this ensures FIFO order, which is correct for undo.
Show answer & explanation

Use a stack (non-primitive) where each element is a structure (non-primitive) containing primitive fields (`char`, `int`) and a string (non-primitive). This supports LIFO undo and dynamic growth.

Undo functionality requires LIFO (Last-In-First-Out) order, which is exactly what a stack provides. A stack is a non-primitive linear data structure that can grow dynamically. Each operation is a composite data type (struct/class) that aggregates primitive types (`char`, `int`) and a string (which is non-primitive). An…

Q198. A software engineer is designing a system to store a dynamic collection of student records. The system must support frequent insertions at the beginning of the collection, but also needs to allow binary search on the records. Which approach best satisfies both requirements, and why?

Advanced
A Use a hash table to store records, and sort the keys when binary search is needed. B Use an array and shift all elements right on each insertion at the beginning, then use binary search on the array. C Use a linked list for O(1) insertions at the head, and implement binary search by traversing the list to the midpoint each time. D Use a balanced binary search tree (e.g., AVL tree) to maintain sorted order with O(log n) insertions and O(log n) search.
Show answer & explanation

Use a balanced binary search tree (e.g., AVL tree) to maintain sorted order with O(log n) insertions and O(log n) search.

A balanced BST (like AVL) supports O(log n) insertions (including at the 'beginning' in sorted order) and O(log n) search, which is efficient. A linked list gives O(1) insertions at the head but binary search on a linked list is O(n) because random access is not possible. An array allows binary search but shifting elem…

Q199. Consider a navigation system that models a city's road network. The system must find the shortest path between two locations, and also frequently update road weights (e.g., due to traffic). Which data structure and algorithm combination is most appropriate, and why?

Advanced
A Use an adjacency list and Dijkstra's algorithm with a binary heap priority queue. B Use a hash table to store edges and perform a depth-first search for the shortest path. C Use a linked list of edges and apply Bellman-Ford algorithm without any priority queue. D Use an adjacency matrix and Dijkstra's algorithm with a simple array-based priority queue.
Show answer & explanation

Use an adjacency list and Dijkstra's algorithm with a binary heap priority queue.

An adjacency list is memory-efficient for sparse road networks and allows quick updates to edge weights. Dijkstra's algorithm with a binary heap achieves O((V+E) log V) time, which is efficient for shortest path. An adjacency matrix uses O(V^2) memory and is inefficient for sparse graphs. DFS does not guarantee shortes…

Q200. A programmer is comparing an array and a linked list for storing a list of tasks. The tasks are frequently accessed by their position (e.g., the 5th task), but insertions and deletions are rare. Which data structure is more suitable, and what is the time complexity for accessing the 5th task in each?

Advanced
A Array, because accessing the 5th task is O(log n) using binary search, while linked list access is O(n). B Array, because accessing the 5th task is O(1) via index, while linked list access is O(n) due to traversal. C Linked list, because insertions and deletions are rare, so the overhead of pointers is negligible, and access is O(1) with a tail pointer. D Linked list, because accessing the 5th task is O(1) if you maintain a pointer to the 5th node, while array access is O(n) due to shifting.
Show answer & explanation

Array, because accessing the 5th task is O(1) via index, while linked list access is O(n) due to traversal.

Arrays provide O(1) random access by index because elements are stored in contiguous memory. Linked lists require traversal from the head to reach the 5th node, which is O(n) in the worst case. Maintaining a pointer to the 5th node is not practical for arbitrary positions. Binary search on an array is O(log n) but only…

Make your own

Your notes can be a kit like these

Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.

  • Chapter notes
  • Flashcards
  • Practice MCQs
  • Scored tests
  • Exam prep

Get Veda free See what students get

Free to start · No ads · Works in 42 languages