Question - Data Structure and Algoriths - 2024
Question - Data Structure and Algoriths - 2024
QUESTION 2
a) What is Data Structure? 3mrks
b) Describe briefly Linear Data Structure 3mrks
c) Identify five characteristics of linear data structure. 5mrks
d) List three advantages and three disadvantages of linear data structure 6mrks
e) Define Link list and gives five areas of application of link lists 8mrks
QUESTION 3
a) Define and give any three examples of Nonlinear Data Structure 5mrks
b) What are four major characteristics of non-linear data structures? 4mrks
c) Give three advantages and three disadvantages of nonlinear data structure. 6mrks
d) Identify any five areas of application of nonlinear data structure. 5mrks
e) Compare three and graphs data structure. 5mrks
Marking Guide
QUESTION 1
a) Algorithms are a set of instructions that are used to solve a particular problem or perform a specific task.
They are a fundamental part of computer science and are used in a wide range of fields, including
programming, data analysis, and artificial intelligence.
b) Characteristics of Algorithms:
1. Input: the data or parameters provided to the algorithm.
2. Output: the result or solution produced by the algorithm.
3. Correctness: the algorithm should produce the correct output for a given input.
4. Efficiency: the algorithm should use resources such as time and memory efficiently.
5. Scalability: the algorithm should be able to handle large inputs or scale to meet the needs of a growing
system.
c) Algorithm Design Techniques
1. Divide and Conquer: break down a problem into smaller subproblems and solve each recursively.
2. Dynamic Programming: solve a problem by breaking it down into smaller subproblems and storing the
solutions to subproblems to avoid redundant computation.
3. Greedy Method: make the locally optimal choice at each stage to find a global optimum.
4. Backtracking: recursively explore all possible solutions to find the correct one.
d) Algorithm Analysis
i. Time Complexity: the amount of time an algorithm takes to complete as a function of the size of the
input.
ii. Space Complexity: the amount of memory an algorithm uses as a function of the size of the input.
QUESTION 2
a) Data structures are a fundamental concept in computer science, and they are used to organize, manage, and
store data in a way that allows for efficient access, modification, and manipulation.
b) Linear Data structure: A linear data structure is a type of data structure in which the elements are
arranged in a linear sequence, one after the other. Each element is connected to the next element, and each
element has a unique predecessor and successor (except for the first and last elements).
c) Characteristics of linear data structures:
1. Elements are arranged in a linear sequence
2. Each element has a unique predecessor and successor (except for the first and last elements)
3. Elements can be accessed in a sequential manner
4. Insertion and deletion of elements can be done at any position
5. Searching for an element can be done in O(n) time
d) Advantages of linear data structures:
1. Efficient use of memory
2. Fast search and insertion times
3. Easy to implement and understand
Disadvantages of linear data structures:
1. Limited flexibility
2. Difficult to insert or delete elements in the middle of the structure
3. Not suitable for large amounts of data
e) Linked lists
A linked list is a data structure in which elements are stored as a sequence of nodes, each of which contains a
value and a reference (i.e., a "link") to the next node in the list. This allows for efficient insertion and deletion of
elements at any position in the list.
Linked lists are useful in many applications, such as:
1. Database query results
2. Dynamic memory allocation
3. Browser history
4. Undo/redo functionality
5. Compilers and interpreters
Question 3
a) A non-linear data structure is a type of data structure that does not have a linear relationship between its
elements. In other words, the elements are not stored in a sequential manner, and the relationships between
them are more complex.
Examples of non-linear data structures include:
1. Trees
2. Graphs
3. Hash tables
4. Heaps
5. Maps
6. Sets