coderz.py

Keep Coding Keep Cheering!

Select a Random Element from a Stream

You are given a stream of elements that is too large to fit into memory. Write an algorithm to select a random element from the stream with equal probability

February 3, 2025 | Algorithm, dsa, Twitter | No comments

Product of Array Except Self

Problem Statement (Asked By Uber) Given a list of integers, return a new list such that each element at index i of the new list is the product of all the elements in the original list except the one at i. For instance, if the input is [1, 2, 3, 4, 5], the expected output […]

December 30, 2024 | Algorithm, array, Data Structure, dsa, Uber | No comments

DSA: Heap

A heap is a specialized tree-based data structure that satisfies the heap property. It is commonly used to implement priority queues and efficient sorting algorithms like heap sort.

June 10, 2023 | Algorithm, Data Structure | No comments

Linear Search or Sequential Search in Python

sequential search is a method for finding an element within a list. It sequentially checks each element of the list until a match is found or the whole list has been searched.

December 19, 2020 | Algorithm, python | 1 comment

Implementation of a Hash Table in Python

The idea of a dictionary used as a hash table to get and retrieve items using keys is often referred to as a mapping. Python already has a built-in dictionary object that serves as a Hash Table.

December 19, 2020 | Algorithm, python | No comments

Implementation of Shell Sort in Python

The shell sort improves on the insertion sort by breaking the original list into a number of smaller sub-lists, each of which is sorted using an insertion sort.

December 19, 2020 | Algorithm, python | No comments

Implementation of Selection Sort in Python

The selection sort improves on the bubble sort by making only one exchange for every pass through the list.

December 17, 2020 | Algorithm, python | No comments

Implementation of Quick Sort in Python

A quick sort first selects a value, which is called the pivot value. Although there are many different ways to choose the pivot value, we will simply use the first item in the list.

December 15, 2020 | Algorithm, python | No comments

Implementation of Merge Sort in Python

Merge sort is a recursive algorithm that continually splits a list in half. If the list is empty or has one item, it is sorted by definition (the base case)

December 15, 2020 | Algorithm, python | No comments

Implementation of Insertion Sort in Python

Insertion Sort builds the final sorted array (or list) one item at a time.

December 15, 2020 | Algorithm, python | No comments

Advertisement