Notes, summaries, assignments, exams, and problems for Computer science

C++ Algorithms: 0-1 Knapsack and LCS Implementation

Computer science2.52 KB

Knapsack Problem: Recursive Approach

The following code demonstrates a naive recursive implementation of the 0-1 Knapsack problem in C++.

/* A Naive recursive implementation of 0-1 Knapsack problem */
#include <bits/stdc++.h>
using namespace std;

// A utility function that returns the maximum of two integers
int max(int a, int b) { return (a > b) ? a : b; }

// Returns the maximum value that can be put in a knapsack of capacity W
int knapSack(int W, int wt[], int val[], int n)
{
    // Base Case
    if (n == 0 || W == 0)
        return 0;

    // If weight of the nth item is more than Knapsack capacity W,
    // then this item cannot be included in the optimal solution
    if (wt[n - 1] > W)
        return knapSack(W, wt, val, n
...
Continue reading "C++ Algorithms: 0-1 Knapsack and LCS Implementation" »

Early vs Late Binding and Major Programming Paradigms

Computer science2.69 KB

Early Binding

Early binding — the binding that can be resolved at compile time by the compiler is known as static or early binding. The method definition and the method call are linked during compile time. This happens when all information needed to call a method is available at compile time. Early binding is more efficient than late binding.

Late Binding

Late binding — it is a runtime process. The method definition and the method call are linked during runtime. Execution speed is lower in late binding. Overriding methods are bound using late binding.

Programming Paradigms

Below are common programming paradigms and their characteristics.

Object-Oriented Programming (OOP)

Object-oriented programming is a programming paradigm based on the concept...

Continue reading "Early vs Late Binding and Major Programming Paradigms" »

Fixed C Programming Examples: Calendar, Stack, Queue, Linked List, Tree

Computer science27.31 KB

Fixed C Programming Examples

1. Weekly Calendar Program

This program creates, reads, displays and frees a weekly calendar using a structure.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define NUM_DAYS_IN_WEEK 7

typedef struct {
    char *acDayName;
    int iDate;
    char *acActivity;
} DAYTYPE;

void fnFreeCal(DAYTYPE *);
void fnDispCal(DAYTYPE *);
void fnReadCal(DAYTYPE *);
DAYTYPE *fnCreateCal();

int main()
{
    DAYTYPE *weeklyCalendar = fnCreateCal();
    fnReadCal(weeklyCalendar);
    fnDispCal(weeklyCalendar);
    fnFreeCal(weeklyCalendar);
    return 0;
}

DAYTYPE *fnCreateCal()
{
    DAYTYPE *calendar = (DAYTYPE *)malloc(NUM_DAYS_IN_WEEK * sizeof(DAYTYPE));
    for (int i =
...
Continue reading "Fixed C Programming Examples: Calendar, Stack, Queue, Linked List, Tree" »

Frame Relay क्या है? फायदे और नुकसान (हिंदी में पूरी जानकारी)

Computer science5.48 KB

Network Protocols (नेटवर्क प्रोटोकॉल)

Frame Relay क्या है? (What is Frame Relay in Hindi)

Frame Relay एक तेज गति का packet switching प्रोटोकॉल है जिसका प्रयोग Wide Area Networks (WANs) में किया जाता है। इसके अलावा, यह दो या दो से अधिक Local Area Networks (LANs) के बीच data को transfer करता है।

Frame Relay एक packet switched टेक्नोलॉजी है। इसे Local Area Networks के बीच कम खर्च में data transfer करने के लिए design किया गया था। साथ ही,...

Continue reading "Frame Relay क्या है? फायदे और नुकसान (हिंदी में पूरी जानकारी)" »

Digital Image Processing Tutorial for Beginners and Professionals

Computer science3.19 KB

Digital Image Processing Tutorial

Digital Image Processing Tutorial provides basic and advanced concepts of image processing. Our Digital Image Processing Tutorial is designed for beginners and professionals both.

Digital image processing is used to manipulate digital images by the use of algorithms. For processing digital images, the most common software that is used widely is Adobe Photoshop.

Our digital image processing tutorial includes all topics of digital image processing such as introduction, computer graphics, signals, photography, camera mechanism, pixel, transaction, types of images, etc.

What Is Digital Image Processing (DIP)?

Digital Image Processing (DIP) is a software which is used to manipulate digital images by the use of a computer...

Continue reading "Digital Image Processing Tutorial for Beginners and Professionals" »

Mastering C# List: A Comprehensive Reference

Computer science54.79 KB

Understanding the C# List<T>

  • The List<T> is a collection of strongly typed objects that can be accessed by index and includes methods for sorting, searching, and modifying the list.
  • It is the generic version of the ArrayList, found within the System.Collections.Generic namespace.
  • The List<T> performs faster and is less error-prone than the ArrayList.
  • Because it is a generic collection, you must specify a type parameter for the data it stores.

Creating a List and Adding Elements

List<int> primeNumbers = new List<int>();
primeNumbers.Add(1); // Adding elements using Add() method
primeNumbers.Add(3);
primeNumbers.Add(5);
primeNumbers.Add(7);

Using Collection Initializer Syntax

var bigCities = new List<string>()
{
...
Continue reading "Mastering C# List: A Comprehensive Reference" »

Socket.io Emitting Patterns and Best Practices

Computer science2.3 KB

Socket.io Emitting Patterns

io.on('connect', onConnect);

function onConnect(socket) {
  // Sending to the client
  socket.emit('hello', 'can you hear me?', 1, 2, 'abc');

  // Sending to all clients except sender
  socket.broadcast.emit('broadcast', 'hello friends!');

  // Sending to all clients in 'game' room except sender
  socket.to('game').emit('nice game', "let's play a game");

  // Sending to all clients in 'game1' and/or 'game2' room, except sender
  socket.to('game1').to('game2').emit('nice game', "let's play a game (too)");

  // Sending to all clients in 'game' room, including sender
  io.in('game').emit('big-announcement', 'the game will start soon');

  // Sending to all clients in namespace 'myNamespace', including sender
  io.
...
Continue reading "Socket.io Emitting Patterns and Best Practices" »

Understanding Microprocessor Architecture and Core Components

Computer science6.55 KB

  1. Introduction to Microprocessor

Definition:

  • “The microprocessor is a multipurpose, clock driven, register based, digital-integrated circuit which accepts binary data as input, processes it according to instructions stored in its memory, and provides results as output.”
    • “Microprocessor is a computer Central Processing Unit (CPU) on a single chip that contains millions of transistors connected by wires.” Introduction:
    • A microprocessor is designed to perform arithmetic and logic operations that make use of small number-holding areas called registers.
    • Typical microprocessor operations include adding, subtracting, comparing two numbers, and fetching numbers from one area to another.
  • Components of Microprocessor
    • Microprocessor is capable of performing
...
Continue reading "Understanding Microprocessor Architecture and Core Components" »

Web Protocols, P2P Networking, and Data Transmission

Computer science2.27 KB

Client and Server Web Interaction

Steps for a Client (Browser)

  • Determine the protocol (HTTP).
  • Ask DNS for the IP address of the server.
  • Make a TCP connection to the server.
  • Send a request for the page; the server sends it back.
  • Fetch other URLs as needed to display the page.
  • Close idle TCP connections.

Steps for a Server

  • Accept a TCP connection from the client.
  • Get the page request and map it to a resource (e.g., file name).
  • Get the resource (e.g., file from disk).
  • Send the contents of the resource to the client.
  • Release idle TCP connections.

Challenges in P2P Networking

  1. How do peers find each other?
  2. How do peers support rapid content downloads?
  3. How do peers encourage each other to upload?

BitTorrent Protocol Download Steps

  1. Start with the torrent description.
...
Continue reading "Web Protocols, P2P Networking, and Data Transmission" »

Essential Networking Concepts: TCP, UDP, and Congestion

Computer science2.5 KB

Differences Between TCP and UDP

  • TCP: Connection-oriented, bytes delivered in order, arbitrary length content, flow control matches sender to receiver, and congestion control matches sender to network.
  • UDP: Connectionless, messages may be lost, limited message size, can send regardless of receiver state, and can send regardless of receiver network.

TCP Connection Management

Explain using figures where and how the 3-way handshaking is used. Explain using figures how TCP releases connections (refer to the other side of this paper).

  • Normal case
  • Simultaneous connect

Computing Adaptive Timeout

Keep smoothed estimates of the RTT and variance in RTT. Update estimates with a moving average. Set timeout to a multiple of estimates to estimate the upper RTT in...

Continue reading "Essential Networking Concepts: TCP, UDP, and Congestion" »