CIT341: Data Structures - Answered Questions
1a. What is an expression?
An expression is a combination of variables, constants, operators, and functions that are evaluated
to produce another value. It represents a computation that returns a result.
1b. What are the main primitive operations and the functions?
Primitive operations include operations such as assignment, comparison, arithmetic operations, and
logical operations. Their functions include manipulating data values, performing computations, and
making decisions based on conditions.
1c. What could be referred to as blocks?
Blocks refer to sections of code that are grouped together. They are typically enclosed in braces `{}`
in many programming languages and represent compound statements or structured sections like
loops, conditionals, or function definitions.
2a. What do you understand by variables? Give at least two examples.
Variables are symbolic names used to store data values in memory during program execution.
Examples include: `int age = 25;`, `float salary = 45000.50;`
2b. List the Single Data Type classification
The single data type classifications include: Integer, Float, Character, and Boolean.
2c. What is an Abstract Data Type
An Abstract Data Type (ADT) is a type for objects whose behavior is defined by a set of values and
operations, independent of their implementation. Examples include List, Stack, Queue, and Tree.
3a. What is an Array?
An array is a data structure consisting of a collection of elements, each identified by at least one
array index or key. It is used to store multiple values of the same type.
3b. Operators functions by precedence:
Postfix: Performs operations after the operand (e.g., i++).
Multiplicative: Performs multiplication, division, or modulus (e.g., *, /, %).
Additive: Performs addition or subtraction (e.g., +, -).
Shift: Shifts bits left or right (e.g., <<, >>).
Equality: Compares two values (e.g., ==, !=).
3c. Describe garbage collection
Garbage collection is the process of automatically reclaiming memory by identifying and disposing of
objects no longer in use by a program.
4a. State the main advantage of the buddy system?
The main advantage of the buddy system is its ability to efficiently allocate and deallocate memory
in powers of two, which reduces fragmentation.
4b. Exhaustively define Data Structure
A data structure is a specialized format for organizing, processing, and storing data. It allows
efficient access and modification.
4c. With explanation classify data structure
Data structures can be classified as:
- Linear (e.g., arrays, linked lists), where data is stored sequentially.
- Non-linear (e.g., trees, graphs), where data is stored hierarchically or in a network.
- Static (e.g., arrays), with fixed size.
- Dynamic (e.g., linked lists), which can grow or shrink at runtime.
5a. List at least five commonly used type parameter names.
T, E, K, N, V
5b. Additional primitive operations and their functions
Examples include:
- create(): initializes a data structure.
- destroy(): deallocates a data structure.
- update(): modifies data in the structure.
- retrieve(): accesses data from the structure.
5c. Mention 4 common types of operators, stating their functions.
1. Arithmetic operators (+, -, *, /): perform mathematical operations.
2. Relational operators (==, !=, <, >): compare values.
3. Logical operators (&&, ||, !): evaluate logical expressions.
4. Assignment operators (=, +=, -=): assign or modify values of variables.
6a. What is an algorithm with regards to data structure?
An algorithm is a step-by-step procedure or formula for solving a problem. In data structures, it
manipulates the structure to perform tasks like searching, sorting, inserting, and deleting data.
6b. What is a Hash Table?
A hash table is a data structure that stores key-value pairs. It uses a hash function to compute an
index into an array of buckets from which the desired value can be found.
6c. Two important ways to characterize the effectiveness of an algorithm
1. Time Complexity: how fast it runs depending on input size.
2. Space Complexity: how much memory it consumes.
7a. Explain Memory Allocation Process?
Memory allocation is the process of assigning memory to variables or programs during runtime or
compile time. It can be static or dynamic.
7b. When could an algorithm for a given problem be optimal?
An algorithm is considered optimal when it solves a problem in the most efficient way possible in
terms of time and space under given constraints.