Skip to content

Instantly share code, notes, and snippets.

@halitbatur
Created May 15, 2024 09:54
Show Gist options
  • Save halitbatur/44a4222a3a72f8134b55c9d28aeacf49 to your computer and use it in GitHub Desktop.
Save halitbatur/44a4222a3a72f8134b55c9d28aeacf49 to your computer and use it in GitHub Desktop.
DSA Discussion

Discussion questions about DSA and Algorithims in Javascript

  1. Discuss the concept of recursion in programming. How does it work, and in what scenarios might recursion be more advantageous than iterative solutions?
  2. 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?
  3. What distinguishes linear data structures from non-linear data structures? Provide examples and use cases where one might be preferred over the other.
  4. Discuss difference between linear and binary search
  5. In your own words explain the following data structures:
  • Linked List
  • Stack
  • Queues
@katmafalela
Copy link

katmafalela commented May 15, 2024

  1. is defined as a process which calls itself directly or indirectly and the corresponding function is called a recursive function. It's advantageous in instances where space and time complexity are a factor.
  2. Time complexity is the amount of time taken to run an algorithm. is the amount of memory space an algorithm/program uses during its entire execution. To ensure that the program runs efficiently and to save resources.
  3. A linear data structure is executed in a sequential manner such as arrays and lists while a non-linear is executed in a hierarchal manner such as trees and graphs.
  4. A linear search is searching for an element in a sequential process and binary uses recursion to find elements
  5. Linked list- is a data structure made up of nodes and pointers
  6. Stack - Is a data structure that allows for elements to be stacked on top of each other
  7. Queues - Is a data structure that follows FIFI and LIFO to insert items.

Breakout room: Pumlani & Mpilo

@NtokozoMitchell
Copy link

Group Names: 1.Nkosi Ntokozo
2.Sakhile Motha
3.Gerald Mutswi

1.Recursion in JavaScript is a powerful technique where a function calls itself repeatedly to solve a problem.
Advantage: Recursion can be advantageous for simplifying complex problems, like those with tree-like structures or that can be divided into smaller parts. However, it can also lead to stack overflow errors if the recursion goes too deep, and it might be less efficient than iterative solutions in some cases.

2.Time complexity refers to how the runtime of an algorithm grows as the size of the input increases. Space complexity refers to how much memory an algorithm uses as the input size increases. It's important to consider both because an algorithm might be fast but use a lot of memory, or it might be memory-efficient but slow. By understanding both, we can choose algorithms that balance speed and memory usage, optimizing overall performance.
3. linear data structures: elements are arranged in a sequential order, like a train with connected cars, each element has a well defined predecessor.... non linear: elements are not in a sequential order, but rather in a hierarchical or web like structure. elements can have multiple connections.

4.Linear search, also known as sequential search, scans through each element in a list or array one by one until it finds the target value.
It starts from the beginning and compares each element with the target.
#Binary search operates on sorted arrays. It repeatedly divides the search interval in half and compares the middle element with the target.
If the middle element is equal to the target, the search is successful. Otherwise, it narrows down the search to the left or right half.

5.#Linked List: Imagine a chain of paperclips where each paperclip knows where the next one is. That's a linked list! It's like a chain letter, but less annoying. You can add or remove paperclips easily without disturbing the others in the chain.

#Stack: Picture a stack of pancakes. You can only add or remove a pancake from the top. So, the last pancake you put on is the first one you'll take off. It's like a pancake tower where you can only eat from the top down.

#Queue: Think of a queue like waiting in line for your favorite roller coaster. The first person to join the line is the first one to ride the coaster. No cutting! It's like being at a buffet where you patiently wait your turn to scoop up the mashed potatoes.

@TNMnguni
Copy link

TNMnguni commented May 15, 2024

  1. Recursion is a function that invokes itself this is how it works when you have a recursive function you call that function inside the body of that function in Fibonacci sequence recursion is most ideal

  2. time complexity is the amount of time an algorithm takes to solve a problem. and space complexity is the memory needed by the algorithm takes to solve a problem as the n value increases.

  3. Linear data structures follow sequential order for instance Stack and the non-linear follow a non-sequential order for instances. Graphs and Trees

  4. linear data are data elements that are arranged sequentially or linearly like in an array and binary structure are is a tree-like data structure where each node has at most two children, known as the left child and the right child

  5. Linked List - is a dynamic linear data structure that comprises of sequential elements called nodes. Node has two parts, first part i the actual data stored in that node and second part is the pointer that points to the next node. Linked Lists grow and shrink during runtime unlike arrays that have a fixed size.
    Stack - is a dynamic linear data structure that has allows operations to be done in one end only which is called a top of a stack it uses an order of Last In and First Out
    Queue- is a dynamic linear data structure that has both ends open but inserting a new element can only be done at the end of the queue also called "rear" using Enqueue() operation and deletion or removal of an element can only be done at the front of the queue also called "front" using a Dequeue() operation

Members : Sharon Matyila
: Ntokozo Mnguni
: Simphiwe Ndlovu

@Hophneylen
Copy link

Lentsoana Hophney
Pamela Gwala
Nokulunga Msabala

  1. Recursion technique where a function calls itself to solve a problem until a base case is reached. mostly used when you have a complex code that performs the same operation over and over again and allows us to call the function instead of creating multiple functions that perform the same operations.
  2. Time complexity is a function that describes how long an algorithm takes in terms of the quantity of input it receives. Space complexity is a function that describes how much memory (space) an algorithm requires to the quantity of input to the method.
    importance as to why consider both:
    -Considering both time complexity and space complexity when analyzing the efficiency of an algorithm provides a comprehensive understanding of its performance characteristics
  3. Linear data structure - organize data elements sequentially, where each element is connected to its previous and next adjacent element.
    Examples:
    Array: Stores elements of the same type with indices (e.g., storing prices of cars).
    Stack: Follows the LIFO (Last In, First Out) rule (e.g., managing function calls or undo operations).

Non-linear data structures arrange data elements hierarchically, where elements are not connected sequentially.
Examples:
Trees: Hierarchical structure with a root node and child nodes (e.g., file systems, organization charts).
Graphs: Consist of nodes (vertices) connected by edges (e.g., social networks, transportation networks).

4.Linear Search sequentially checks each element in the list until it finds a match or exhausts the list
Binary Search continuously divides the sorted list, comparing the middle element with the target value
5.
A linked list is a data structure consisting of a sequence of elements, called nodes, where each node contains a reference (or link) to the next node in the sequence.
A stack is a fundamental data structure in computer science that follows the Last In, First Out (LIFO) principle.
A queue is another fundamental data structure in computer science, following the First In, First Out (FIFO) principle.
stack

@ImisebenziEmihle
Copy link

Room 3- Keketso, Emihle, Nhlanhla

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

@PhamelaMhlaba
Copy link

Answers.

  1. It is a function that that calls itself repeatedly.

  2. Time Complexity- Refers to the amount of time it takes for the algorithm to complete its execution
    Space Complexity- The amount of memory that it uses during its execution
    We are trying to find a balance between the two and to pick the best algorithm for different situations.

  3. Linear data structures-It aligns data in a linear sequence, examples include arrays, lists or queues
    Non- linear data structure connects two or more information items, examples include a graph and a tree.

  4. Linear checks each element until it finds the element that it is looking for and the binary search it divides the list into half and searches for the element.

  5. Linked List- it is a series of nodes that are linked together through pointers.
    Stack- It is a data structure that uses the last in first out method where elements are added and
    removed from the top of the stack, allowing for efficient insertion and deletion operations.
    Queue- It is a data structure that uses that first in first out. You add elements to the end of the queue and you remove them the front.

Breakout room (Phamela, Letago, Vuyo, Koni)

@thewesss
Copy link

Group members: Tumelo, Lindokuhle, Wesley
1)Its a process whereby a function calls itself until a certain condition is met. scenarios that would be more advantageous would be is where readability is important, e.g. Tree structures
2)Time complexity is the amount time an algorithm takes to run its execution. Space complexity the amount of space it takes to execute a function.
3)linear data structures e.g.arrays,linked lists, stack follow a sequential order while non-linear data structures is more complex and have hierachical relationships
4)linear search:
5)

@samuelthis
Copy link

  1. Recursion is when the function is calling itself, it is also used to solve problems that contain smaller sub-problems. Moreover, Recursion is a programming technique where a function calls itself repeatedly until it reaches a base case that stops the recursion. In other words, a function solves a problem by breaking it down into smaller sub-problems of the same type, and then solving those sub-problems using the same function.
  2. Time complexity, is used to measure the amount of time required to execute the code. Space complexity, means the amount of space required to execute successfully the functionalities of the code. Both of the above complexities are measured with respect to the input parameters.
    3.Linear Data structure where data elements are arranged sequentially or linearly where each and every element is attached to its previous and next adjacent for example [list, array, stack and queue]. while Non-linear data structure, where data elements are not arranged sequentially or lineary example [map, graph and tree].
  3. In linear search input data need not to be in sorted. In binary search input data need to be in sorted order.
    • Linked List, is a collection of nodes, each containing a value and a reference to the next node. Each node is connected to its neighbors through pointers or references. Linked lists allow for efficient insertion and deletion of elements at any position.
  • Stack, A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle.
  • Queues, foundational concept in computer science used for storing and managing data in a specific order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment