Tree

Binary Tree A binary tree is a tree data structure in which each node has at most two children, referred to as the left child and the right child. B-Tree A B-tree is a self-balancing tree data structure that maintains sorted data and allows searches, sequential access, insertions, and deletions in logarithmic time. It is optimized for systems that read and write large blocks of data. B+ Tree A B+ tree is an extension of a B-tree, optimized for systems that read and write large blocks of data....

October 7, 2024

Data Structure Interview

What is the difference between an array and a linked list? Array: Fixed size (in most languages) Contiguous memory allocation Fast random access Insertion/deletion is expensive (except at the end) Linked List: Dynamic size Non-contiguous memory allocation Slow random access Fast insertion/deletion Explain the difference between a stack and a queue. Stack: Last-In-First-Out (LIFO) structure Push (insert) and pop (remove) operations occur at the same end Used for function calls, undo mechanisms, expression evaluation Queue:...

October 6, 2024

Gin

What is Gin Web Framework? Gin is a lightweight, high-performance web framework for Go, inspired by Martini but with a focus on speed and efficiency. Key Features of Gin Gin is packed with features that make web development in Go both enjoyable and efficient. Here are some of its standout features: 1. High Performance Gin is designed for speed. It outperforms many other Go frameworks by optimizing routing and minimizing middleware overhead, ensuring rapid request processing....

October 5, 2024

Go's `http.ListenAndServe`

Implementation Overview The ListenAndServe function is part of Go’s standard library in the net/http package. Its primary purpose is to start an HTTP server that listens on a specified address and handles incoming requests. func ListenAndServe(addr string, handler Handler) error { server := &Server{Addr: addr, Handler: handler} return server.ListenAndServe() } This function creates a Server instance and calls its ListenAndServe method. Detailed Implementation The core logic is in the Server.ListenAndServe and Server....

October 4, 2024

Network Interview

What is the OSI model? Physical Layer Data Link Layer Network Layer Transport Layer Session Layer Presentation Layer Application Layer Explain the difference between TCP and UDP. TCP (Transmission Control Protocol): Connection-oriented Reliable, ensures all data is received Flow control and congestion control Slower than UDP Used for applications requiring high reliability (e.g., file transfer, email) UDP (User Datagram Protocol): Connectionless Unreliable, doesn’t guarantee data delivery No flow control or congestion control Faster than TCP Used for applications that prioritize speed (e....

October 4, 2024

Network Protocols

Transmission Control Protocol (TCP) TCP Principles and Mechanisms Key features: Connection Establishment: Three-way handshake (SYN, SYN-ACK, ACK) Reliable Delivery: Acknowledgment and retransmission Flow Control: Sliding window mechanism Congestion Control: Slow start, congestion avoidance, fast retransmit, and fast recovery Ordered Data Transfer: Sequence numbers Error Detection: Checksum Example of TCP header: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Source Port | Destination Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Sequence Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Acknowledgment Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Data | |U|A|P|R|S|F| | | Offset| Reserved |R|C|S|S|Y|I| Window | | | |G|K|H|T|N|N| | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Checksum | Urgent Pointer | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options | Padding | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | data | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ TCP Performance Characteristics Throughput:...

October 4, 2024

Operating System Interview

Explain the difference between a process and a thread. Process: Independent execution unit Has its own memory space Heavyweight, more resources Isolated from other processes Thread: Lightweight unit of execution within a process Shares memory space with other threads in the same process Less resource-intensive Can communicate easily with other threads in the same process How do processes and threads communicate Process communication methods: Pipes and named pipes Shared memory Message queues Sockets Signals Thread communication methods:...

October 4, 2024

Subnet and Subnet

What is a Subnet? A subnet is a way to divide a large network into smaller, more manageable pieces. Think of it like dividing a big city into neighborhoods. Each subnet (neighborhood) has its own group of devices (houses), but all are still part of the same overall network (city). What is a Subnet Mask? A subnet mask is a number used to help identify which part of an IP address belongs to the network (city) and which part identifies the device (house)....

October 4, 2024

Epoll

epoll (Linux): An Efficient I/O Multiplexing Mechanism epoll operates on an event-driven model, meaning it only notifies the application when an event occurs on a specific file descriptor, unlike select and poll which poll all descriptors regardless of activity. This drastically reduces overhead, especially when managing numerous connections. Key Features and Functionality The core functionality revolves around three system calls: epoll_create(size): Creates an epoll instance and returns an epoll file descriptor....

October 3, 2024

MySQL's Transaction Isolation Levels

SQL Transaction Isolation Levels Transaction isolation levels define the degree to which the operations in one transaction are visible to other concurrent transactions and the types of reads and writes that are allowed. Comparison Table Isolation Level Dirty Read Non-repeatable Read Phantom Read READ UNCOMMITTED Yes Yes Yes READ COMMITTED No Yes Yes REPEATABLE READ No No Yes SERIALIZABLE No No No Explanation of Isolation Levels 1. READ UNCOMMITTED This is the lowest isolation level....

October 3, 2024