- Discuss the concept of recursion in programming. How does it work, and in what scenarios might recursion be more advantageous than iterative solutions?
- Explain the difference between time complexity and space complexity in algorithms. Why is it important to consider both when evaluating the efficiency of an algorithm?
- What distinguishes linear data structures from non-linear data structures? Provide examples and use cases where one might be preferred over the other.
- Discuss difference between linear and binary search
- In your own words explain the following data structures:
- Linked List
- Stack
- Queues
Room 3- Keketso, Emihle, Nhlanhla
Recursion in programming is a method where a function calls itself repeatedly until it reaches a base case that stops the recursion. Recursion is particularly advantageous when dealing with problems that can be naturally broken down into smaller parts. examples of data strucutres that recursion works is in tree or graph traversal.
Time complexity refers to the amount of time and algorithm it takes to complete the problem, and space complexity refers to the amount of memory it requires to solve a given problem.Making sure that an algorithm is both fast and doesn't use up too much memory is important, especially in places where there isn't a lot of space or when dealing with big sets of data. Algorithms often have tradeoffs between time and space complexity optimising one aspect while compromising the other.
Linear - data strucutres where data is arranged linearly / sequentially where each an every element is attached to its previous and next adjacent.
Non- linear : data strucutres where data elements are not arranged linearly/sequentially.
Linear It defines a sequential search algorithm, and searches until it finds what its looking for. For binary search, a sorted array is divided into two, itworks by repeatedly dividing the search interval in half until the target element is found or the interval is empty.
A linked list- A data structure in which sequence of notes are connected through pointers.
Stack - A data strucutre that follows the last-in-first-out principle.
Queues - A data structure that follows the first-in-first-out principle.