Understanding Binary Search, Graphs, and Priority Queues

Q) How is binary search different from linear search?

Linear SearchBinary Search
1. Checks each element one by one from start to end.1. Repeatedly divides the sorted list into halves to find the element.
2. Works on unsorted or sorted lists.2. Works only on sorted lists.
3. Time complexity is O(n).3. Time complexity is O(log n) (much faster).
4. Simple and easy to implement.4. Slightly more complex due to mid calculations.
5. Inefficient for large datasets.5. Highly efficient for large datasets.
6. No
Read More

Fundamental Data Structures and Algorithms Concepts

A stack is a linear data structure that follows the Last In First Out (LIFO) principle. This means that the last element added to the stack is the first one to be removed. A stack can be visualized like a stack of plates; you can only add or remove the top plate.

Key operations of a stack include:

1. Push: Adding an element to the top of the stack.
2. Pop: Removing the element from the top of the stack.
3. Peek (or Top): Viewing the element at the top of the stack without removing it.
4. IsEmpty: Checking

Read More

Operating System Fundamentals and Linux Essentials

Operating System Concepts: Key Differences

This section outlines the differences between core operating system concepts:

  1. Preemptive and Non-Preemptive Scheduling
  2. Program and Process
  3. Hard Real-Time Systems and Soft Real-Time Systems
  4. Time Sharing and Multiprogramming

Preemptive vs. Non-Preemptive Scheduling

PointPreemptive SchedulingNon-Preemptive Scheduling
1CPU can be taken away from a running process before completion.CPU cannot be taken away; the process runs until it finishes or waits.
2Better response
Read More

Essential Data Structures: Bags, Stacks, Queues, and Big O

Fundamentals of Data Structures and OOP

Data Structures (DS): Methods for storing and managing data efficiently so it can be reused.

Examples of Data Structures:

  • Lists
  • Queues
  • Trees
  • Bags
  • Dictionaries
  • Graphs

Object-Oriented Programming (OOP) Principles

  • Encapsulation
  • Abstraction
  • Inheritance
  • Polymorphism

Bags: Unordered Collections

A Bag is a finite collection of objects where the order of elements does not matter. Duplicates are allowed.

Examples: Shopping bags, piggy banks.

Core Bag Operations:

  • add
  • remove
  • contains
  • clear
  • getFrequencyOf
  • isEmpty
  • toArray
Read More

Core Algorithms in Computer Graphics: Clipping, Drawing & Displays

Cohen-Sutherland Line Clipping Algorithm

What is the Cohen-Sutherland Algorithm?

The Cohen–Sutherland algorithm is a line clipping method used to clip a line segment against a rectangular clipping window. It divides the area around the window into regions and assigns a 4-bit region code (Outcode) to each endpoint of the line.

Algorithm Steps

  1. Assign 4-bit codes to each endpoint. Each bit represents a position relative to the window:

    • Bit 1: Top
    • Bit 2: Bottom
    • Bit 3: Right
    • Bit 4: Left

    For example:

    • 0000 →
Read More

C# Programming Fundamentals: Arrays, Loops, and Decisions

Life Expectancy Analysis with Parallel Arrays

This exercise demonstrates the use of parallel arrays to store and process life expectancy data by gender.

Instructions

  1. Create four parallel arrays containing the life expectancy data as shown in Table 1.
  2. Iterate through the parallel arrays to count and display a list of country names where the life expectancy for both genders exceeds 80 years.
  3. Prompt the user to input a country code.
  4. Use a loop to display the country name and life expectancies for males,
Read More