본문 바로가기

Sorting: Bubble Sort Consider the following version of Bubble Sort:for (int i = 0; i a[j+1]){ int tmp = a[j+1]; a[j+1] = a[j]; a[j] = tmp; count++; } } } System.out.println("Array is sorted in " + count + " swaps."); System.out.println("First Element: " + a[0]); System.out.println("Last Element: " + a[a.length-1]); } } 더보기
Heaps: Find the Running Median The median of a dataset of integers is the midpoint value of the dataset for which an equal number of integers are less than and greater than the value. To find the median, you must first sort your dataset of integers in non-decreasing order, then:If your dataset contains an odd number of elements, the median is the middle element of the sorted sample. In the sorted dataset , is the median.If yo.. 더보기
Queues: A Tale of Two Stacks A queue is an abstract data type that maintains the order in which elements were added to it, allowing the oldest elements to be removed from the front and new elements to be added to the rear. This is called a First-In-First-Out(FIFO) data structure because the first element added to the queue (i.e., the one that has been waiting the longest) is always the first one to be removed.A basic queue .. 더보기
Stacks: Balanced Brackets A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [], {}, and ().A matching pair of brackets is not balanced if the set of brackets .. 더보기
Linked Lists: Detect a Cycle A linked list is said to contain a cycle if any node is visited more than once while traversing the list.Complete the function provided in the editor below. It has one parameter: a pointer to a Node object named that points to the head of a linked list. Your function must return a boolean denoting whether or not there is a cycle in the list. If there is a cycle, return true; otherwise, return fa.. 더보기
Hash Tables: Ransom Note A kidnapper wrote a ransom note but is worried it will be traced back to him. He found a magazine and wants to know if he can cut out whole words from it and use them to create an untraceable replica of his ransom note. The words in his note are case-sensitive and he must use whole words available in the magazine, meaning he cannotuse substrings or concatenation to create the words he needs.Give.. 더보기
Strings: Making Anagrams Alice is taking a cryptography class and finding anagrams to be very useful. We consider two strings to be anagrams of each other if the first string's letters can be rearranged to form the second string. In other words, both strings must contain the same exact letters in the same exact frequency For example, bacdc and dcbac are anagrams, but bacdc and dcbad are not.Alice decides on an encryptio.. 더보기
Arrays: Left Rotation A left rotation operation on an array of size shifts each of the array's elements unit to the left. For example, if left rotations are performed on array , then the array would become .Given an array of integers and a number, , perform left rotations on the array. Then print the updated array as a single line of space-separated integers.Input FormatThe first line contains two space-separated int.. 더보기