I’m looking for a data structure that supports O(1) random access and worst case O(1) append. In my case however, O(1) amortized time for append is not what I’m looking for. The data structure also will not have any operations performed on it other than append and access. No deletions, no insertions, just an append-only ..

#### Category : data-structures

Question : Find the number of "n"(new line character) present in any string. Input : String s = "Shroud isn a godlike player inn video gaming community." Output : 2 Here is my code : #include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int nseq=0; string s; cin>>s; for(int i=0;i<s.length()-1;i++) { if(s.substr(i,i+1)=="n") { nseq++; ..

i choose to use map in maps to implement a graph by this code ~ map<string,map<string,T>> adj_list; int edges = 0; ~ I wonder if I need to write some more code or I can get straight to num_vertices and num_edges. many thanks. Source: Windows Que..

I am working on a project that asks us to implement different sorts and add counter variables to measure the runtime with different array sizes. My problem is that my output is not matching my expected output I already completed the insertion sort and correctly counts the number of comparisons. I am allowed to use ..

I am working on a project that asks us to implement different sorts and add counter variables to measure the runtime with different array sizes. My problem is that I dont know how to do that using the code that my instructor provided for quick sort. I already completed the insertion sort and correctly counts ..

I am working on a project that asks us to implement different sorts and add counter variables to measure the runtime with different array sizes. My problem is that my current output is not matching the expected output for my Merge Sort. Its only off by a bit. Any suggestions on what is wrong? Output: ..

problem:- Geek is a spy in an enemy town. There are N people in the town and every person has a unique natural number that denotes their identification. The ith person’s identification code is i. His organisation has however, planted several allies in the town. They can be identified by their identification code as the ..

I am trying to create a linked list with smart pointers, and all the functions. it is working pretty well, but I cannot write the reverse() function. Before that, I wrote it with raw pointers and everything worked fine. The problem is that the reverse() function is returning a non valid value. How can I ..

https://cses.fi/problemset/task/1197 Cycle Finding, my algorithm prints cycle if it has any negative weight, but jury is not accepting. they suggested to use bellman ford algorithm but my dfs also working fine. Question: You are given a directed graph, and your task is to find out if it contains a negative cycle, and also give an ..

I am working on a project that asks us to implement different sorts and add counter variables to measure the runtime with different array sizes. My problem is that my current output is not matching the expected output for my insertion sort. Any suggestions on what is wrong? Output: Array Size: 10 100 1000 10000 ..

## Recent Comments