Found 1082 Articles for Go Programming

Golang program to implement a weighted interval scheduling algorithm

Akhil Sharma
Updated on 05-Sep-2023 19:03:01

99 Views

The Weighted Interval Scheduling Problem revolves around a set of intervals, each having an associated weight. In this article, we will implement the Weighted Interval Scheduling algorithm in go, using two methods: Recursive and Dynamic Programming. This classic optimization problem involves selecting non-overlapping intervals with maximum total weight. Explanation Recursive Method The Recursive Method takes a straightforward yet elegant approach. It examines each interval one by one and considers two scenarios − whether to include the current interval or skip it. This method utilises recursion to explore all possible combinations of intervals, calculating the maximum weight. While ... Read More

Golang program to implement a treap

Akhil Sharma
Updated on 05-Sep-2023 18:46:19

55 Views

In this article, we will explore the implementation of a Treap data structure in Golang using two different methods. A Treap is a combination of a binary search tree and a binary heap, making it an efficient data structure for maintaining a set of ordered elements while also ensuring balanced priority. The first method will utilise a recursive approach for building and maintaining the Treap, while the second method will implement an iterative approach. The examples below showcase the creation and traversal of a randomised binary search tree, Explanation A Treap is a cool combination of two other structures, a ... Read More

Golang program to implement a bitset

Akhil Sharma
Updated on 05-Sep-2023 18:08:26

145 Views

A BitSet is a data structure that represents a fixed-size set of binary values, where each value can be either 0 or 1. It is commonly used for efficiently storing and manipulating large sets of boolean values. In this article, we will implement a bitset in go, using two different methods, the first one involves the use of slice of booleans as well as the second one involves using bit manipulation with unsigned integers. Implementation here means that we are going to perform various operations like setting, clearing and testing of individual bits within a bitset data structure. Explanation ... Read More

Golang program to implement a trie with compressed nodes

Akhil Sharma
Updated on 05-Sep-2023 17:57:26

75 Views

Tries are tree-like data structures used for efficient storage and retrieval of strings, making them invaluable for tasks like autocomplete, dictionary implementation, and pattern matching. The compressed node technique optimises space usage by merging common prefixes among nodes, resulting in a more memory-efficient Trie. In this article, we will explore the implementation of a Trie with Compressed Nodes in Golang using two methods to implement the Trie with Compressed Nodes, the first method utilises maps, and the second method uses arrays. Explanation A compressed trie is a trie data structure that saves the space by combining consecutive nodes with ... Read More

Golang program to implement a double ended priority queue

Akhil Sharma
Updated on 05-Sep-2023 17:54:25

95 Views

A Double Ended Priority Queue, in short DEPQ is a data structure that extends the functionality of a standard priority queue. In this article, we will implement a double ended priority queue in Golang using two methods: the first method uses two separate heaps for maximum and minimum priorities, while the second method augments a single heap with additional information for efficient queries. In the code examples we are going to perform the operations like insertion retrieval, deletion and updation. Explanation Double ended priority queue is a data structure that allows insertion and deletion operations and it allows efficient ... Read More

Golang program to implement a hash table with linear probing

Akhil Sharma
Updated on 05-Sep-2023 17:44:25

251 Views

Hash tables are efficient data structures used to store key-value pairs, making them essential for various applications. Linear probing is a collision resolution technique that helps handle situations when two keys map to the same index in the hash table. In this article, we will explore the implementation of a Hash Table with Linear Probing in Golang, using arrays and maps, gaining insights into their workings and practical applications. In the below examples we are going to perform insertion and retrieval operations using a hash mechanism and collision resolution strategy. Explanation In the below example, keys [10 , 25, ... Read More

Golang program to implement a deque using doubly linked list

Akhil Sharma
Updated on 05-Sep-2023 17:39:12

165 Views

A deque is a versatile data structure that allows insertion and deletion of elements from both ends efficiently. The doubly linked list provides an excellent foundation for building a deque as it allows easy traversal in both directions. In this article, we will explore deque using doubly linked lists in go with two methods: using a custom doubly linked list and using the built-in container/list package in Golang. Here in the below examples we will showcase the operations of a double ended queue, we will perform the insertion and deletion operations at both the ends. Explanation As you can see ... Read More

Golang program that takes in a list of weights and values for items and a maximum weight capacity for knapsack

Akhil Sharma
Updated on 04-Aug-2023 16:49:37

108 Views

In this Go language article, we will write programs that take in list of weights and values for items and a maximum weight capacity for knapsack. Knapsack problem is an optimization problem that uses dynamic programming. Here, the purpose is to find out the set of items that can be included in the knapsack without exceeding its weight capacity or maximum weight. Dynamic programming involves solving of problems by breaking them down into smaller subproblems and them combining them to get an optimal solution. Syntax func make ([] type, size, capacity) The make function in go language ... Read More

Golang program that takes in a slice of integers and an anonymous function that filters each element in the slice

Akhil Sharma
Updated on 04-Aug-2023 16:48:04

107 Views

In this Go language article, we will write programs that take in a slice of integers and an anonymous function that filters each element in the slice. An anonymous function is the function which uses no function name and is called by the variable which is assigned to it. It is used generally used with event listeners. Here, Filter function will be created with the anonymous functions to filter the values from slice. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of arguments. The first ... Read More

Golang program that takes in a slice of integers and an anonymous function that maps each element in the slice to a new value

Akhil Sharma
Updated on 04-Aug-2023 16:47:17

56 Views

In this article, we will write Go language programs that take in a slice of integers and an anonymous function that maps each element in the slice to a new value. An anonymous function is declared without a name and is assigned to a variable which is called to execute the process. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments. func range(variable) The range function is used to iterate over any data ... Read More

Advertisements