{"id":429660,"date":"2018-03-06T08:20:05","date_gmt":"2018-03-06T08:20:05","guid":{"rendered":"https:\/\/essaypaper.org\/string-duplicate-characters-assignment-sample\/"},"modified":"2018-10-24T08:53:25","modified_gmt":"2018-10-24T08:53:25","slug":"string-duplicate-characters-assignment-sample","status":"publish","type":"post","link":"https:\/\/www.benedictsol.com\/blogs\/string-duplicate-characters-assignment-sample\/","title":{"rendered":"String Duplicate Characters &#8211; Assignment Sample"},"content":{"rendered":"<div>\n<blockquote>\n<p><i><span style=\"font-weight: 400;\">When reading through this sample on <\/span><\/i><b><i>string duplicate<\/i><\/b><i><span style=\"font-weight: 400;\">characters, students can find ideas on how to solve their own problems. The benefit of our samples is obvious, because they help students to deal with their own homework. In the sample you will read further, you will find our expert\u2019s ideas which can\u2019t be presented as your own. You can find more samples on Assignment.EssayShark.com. While working on your assignment, you can face some difficulties. Numerous students ask us to help them with their homework.<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400;\">If you have a large amount of assignments, you can leave them to our expert. The reason why students get our help is that they can save time and effort. The purpose of our site is to help students with any type of assignment. You just need to place your order, mentioning your requirements and setting the deadline. So, read through the following sample and see how our expert adheres to the academic standards while completing the specific assignment!<\/span><\/i><\/p>\n<\/blockquote>\n<h2><span style=\"font-weight: 400;\">Duplicate Characters in the String<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">In carrying out this task, the additional data structures can not be used.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">One of the obvious ways to solve this problem is to compare each character of the string to any other character. It requires O(n\u00b2) time and O (1) memory.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If we can change the string, it is possible to sort it (which will require O(nlogn) time), and then sequentially verify the identity of adjacent characters. Be careful: some sorting algorithms require large amounts of memory.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We can slightly optimize the task: return false if the length of the string exceeds the number of characters in the alphabet. In the end, a row with 280 unique characters can not exist if there are only just 256 characters. However, if it is Unicode-string, this optimization will not help.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Our solution is to create an array of boolean values, where the flag with index i changes if the string contains the chosen symbol. If you \u201cstumble\u201d on the same character for the second time, you can immediately return false.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The code that implements this algorithm is as follows:<\/span><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&#13;\npublic boolean unique(String s) {&#13;\n    boolean[] chars = new boolean[256];&#13;\n    for (int i = 0; i &lt; s.length(); i++) {&#13;\n        int k = s.charAt(i);&#13;\n        if (chars[k]) {        \/\/symbol was found&#13;\n            return false;&#13;\n        }&#13;\n        chars[k] = true;&#13;\n    }&#13;\n    return true;&#13;\n}&#13;\n&#13;\n<\/pre>\n<p>\u00a0<\/p>\n<p><span style=\"font-weight: 400;\">Evaluation of the execution time of this code is O(n), where n is the length of the string, and the evaluation of the required memory is O(1).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can reduce memory usage using a bit vector. In the next example, we assume that the string has only lowercase characters a-z. This allows us to use just one value of type int.<\/span><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&#13;\npublic boolean unique(String s) {&#13;\n    int c = 0;&#13;\n    for (int i = 0; i &lt; s.length(); i++) {&#13;\n        int k = s.charAt(i) - 'a';&#13;\n        if (c &amp; (1 &lt;&lt; k)) &gt; 0) {&#13;\n            return false;&#13;\n        }&#13;\n        c |= (1 &lt;&lt; k);&#13;\n    }&#13;\n    return true;&#13;\n}&#13;\n<\/pre>\n<p>Choosing the best solution is based on the additional restrictions of a specific task.<br \/>Thanks for your attention!<\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>When reading through this sample on string duplicatecharacters, students can find ideas on how to solve their own problems. The benefit of our samples is obvious, because they help students to deal with their own homework. In the sample you <a href=\"https:\/\/www.benedictsol.com\/blogs\/string-duplicate-characters-assignment-sample\/\" class=\"read-more\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,1],"tags":[],"class_list":["post-429660","post","type-post","status-publish","format-standard","hentry","category-samples","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/429660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/comments?post=429660"}],"version-history":[{"count":0,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/429660\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/media?parent=429660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/categories?post=429660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/tags?post=429660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}